Skip to content

Instantly share code, notes, and snippets.

@dougrchamberlain
Created May 29, 2018 13:01
Show Gist options
  • Save dougrchamberlain/ad05b5b45d96fa8b56c87ffb5792f240 to your computer and use it in GitHub Desktop.
Save dougrchamberlain/ad05b5b45d96fa8b56c87ffb5792f240 to your computer and use it in GitHub Desktop.
"Beginners .vimrc
" v0.1 2012-10-22 Philip Thrasher
"
" Important things for beginners:
" * Start out small... Don't jam your vimrc full of things you're not ready to
" immediately use.
" * Read other people's vimrc's.
" * Use a plugin manager for christ's sake! (I highly recommend vundle)
" * Spend time configuring your editor... It's important. Its the tool you
" spend 8 hours a day crafting your reputation.
" * remap stupid things to new keys that make you more efficient.
" * Don't listen to the haters that complain about using non-default
" key-bindings. Their argument is weak. I spend most of my time in the editor
" on my computer, not others, so I don't care if customizing vim means I'll
" have a harder time using remote vim.
"
" Below I've left some suggestions of good default settings to have in a bare
" minimal vimrc. You only what you want to use, and nothing more. I've heavily
" commented each, and these are what I consider bare necessities, my workflow
" absolutely depends on these things.
"
" If you have any questions, email me at [email protected]
" Setup Vundle:
" For this to work, you must install the vundle plugin manually.
" https://github.com/gmarik/vundle
" To install vundle, copy all the files from the repo into your respective
" folders within ~/.vim
set nocompatible " Fuck VI... That's for grandpas.
filetype off
set rtp+=$HOME/.vim/bundle/Vundle.vim/
call vundle#rc('$HOME/.vim/bundle/')
Bundle 'gmarik/vundle'
" Vundle let's you specify a plugin in a number of formats, but my favorite
" allows you to grab plugins straight off of github, just specify the bundle
" in the following format:
" Bundle 'githubUsername/repoName'
" vim-dispatch
Bundle 'tpope/vim-dispatch'
Bundle 'tpope/vim-fugitive'
Bundle 'Shougo/vimproc.vim'
" Let vundle manage itself:
" easy motion
Bundle 'easymotion/vim-easymotion'
" Just a shitload of color schemes.
" https://github.com/flazz/vim-colorschemes#current-colorschemes
Bundle 'flazz/vim-colorschemes'
" Fuzzy finder -- absolutely must have.
Bundle 'ctrlpvim/ctrlp.vim'
" Support for easily toggling comments.
Bundle 'tpope/vim-commentary'
" In addtion to the above plugins, you'll likely need some for individual
" non-standard syntaxes that aren't pre-bundled with vim. Here are some I use,
" these are required for me, but depending on what code you write, obviously
" this may differ for you.
" Proper JSON filetype detection, and support.
Bundle 'leshill/vim-json'
" vim already has syntax support for javascript, but the indent support is
" horrid. This fixes that.
Bundle 'pangloss/vim-javascript'
" vim indents HTML very poorly on it's own. This fixes a lot of that.
Bundle 'indenthtml.vim'
" I write markdown a lot. This is a good syntax.
Bundle 'tpope/vim-markdown'
" LessCSS -- I use this every day.
Bundle 'groenewege/vim-less'
" Coffee-script syntax.
Bundle 'kchmck/vim-coffee-script'
" C# Syntax
Bundle 'OmniSharp/omnisharp-vim'
" ALE
Bundle 'w0rp/ale'
" Unimpaired
Bundle 'tpope/vim-unimpaired'
Bundle 'airblade/vim-gitgutter'
" Airline
Bundle 'vim-airline/vim-airline'
Bundle 'vim-airline/vim-airline-themes'
" NerdTree
Bundle 'scrooloose/nerdtree'
" Autosave
"Bundle '907th/vim-auto-save'
" vim-tags
"Bundle 'szw/vim-tags'
"tagbar
Bundle 'majutsushi/tagbar'
Bundle 'hushicai/tagbar-javascript.vim'
nmap <F8> :TagbarToggle<CR>
" ultisnips
Bundle 'SirVer/ultisnips'
Bundle 'ervandew/supertab'
Bundle 'jremmen/vim-ripgrep'
" We have to turn this stuff back on if we want all of our features.
filetype plugin indent on " Filetype auto-detection
syntax on " Syntax highlighting
set number " Show line numbers
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab " use spaces instead of tabs.
set smarttab " let's tab key insert 'tab stops', and bksp deletes tabs.
set shiftround " tab / shifting moves to closest tabstop.
set autoindent " Match indents on new lines.
set smartindent " Intellegently dedent / indent new lines based on rules.
set bs=indent,eol,start " Backspace over everything in insert mode
" We have VCS -- we don't need this stuff.
set nobackup " We have vcs, we don't need backups.
set nowritebackup " We have vcs, we don't need backups.
set noswapfile " They're just annoying. Who likes them?
" don't nag me when hiding buffers
set hidden " allow me to have buffers with unsaved changes.
set autoread " when a file has changed on disk, just load it. Don't ask.
" Make search more sane
set ignorecase " case insensitive search
set smartcase " If there are uppercase letters, become case-sensitive.
set incsearch " live incremental searching
set showmatch " live match highlighting
set hlsearch " highlight matches
set gdefault " use the `g` flag by default.
" allow the cursor to go anywhere in visual block mode.
set virtualedit+=block
set foldmethod=syntax
set foldnestmax=10
set nofoldenable
set foldlevel=2
let g:tagbar_type_typescript = {
\ 'ctagstype': 'typescript',
\ 'kinds': [
\ 'c:classes',
\ 'n:modules',
\ 'f:functions',
\ 'v:variables',
\ 'v:varlambdas',
\ 'm:members',
\ 'i:interfaces',
\ 'e:enums',
\ ]
\ }
" leader is a key that allows you to have your own "namespace" of keybindings.
" You'll see it a lot below as <leader>
let mapleader = ","
" So we don't have to type for tabs
noremap <leader>+ :tabnew<cr>
noremap <leader>< :tabprevious<cr>
noremap <leader>> :tabnext<cr>
" So we don't have to reach for escape to leave insert mode.
inoremap jf <esc>
" create new vsplit, and switch to it.
noremap <leader>v <C-w>v
" bindings for easy split nav
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Use sane regex's when searching
nnoremap / /\v
vnoremap / /\v
" Clear match highlighting
noremap <leader><space> :noh<cr>:call clearmatches()<cr>
" Quick buffer switching - like cmd-tab'ing
"nnoremap <leader><leader> <c-^>
" Visual line nav, not real line nav
" If you wrap lines, vim by default won't let you move down one line to the
" wrapped portion. This fixes that.
noremap j gj
noremap k gk
" Plugin settings:
" Below are some 'sane' (IMHO) defaults for a couple of the above plugins I
" referenced.
" Map the key for toggling comments with vim-commentary
nnoremap <leader>c <Plug>CommentaryLine
" Remap ctrlp to ctrl-t -- map it however you like, or stick with the
" defaults. Additionally, in my OS, I remap caps lock to control. I never use
" caps lock. This is highly recommended.
"let g:ctrlp_map = '<c-t>'
" Let ctrlp have up to 30 results.
let g:ctrlp_cmd = 'CtrlPMRU'
let g:ctrlp_max_height = 10
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](node_modules|DS_Store|git|packages)'
\ }
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
nnoremap <leader>. :CtrlPTag<cr>
" Finally the color scheme. Choose whichever you want from the list in the
" link above (back up where we included the
if !has("gui_running")
set term=xterm
set t_Co=256
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
colorscheme gruvbox
endif
set statusline+=%#warningmsg#
"set statusline+=%{fugitive#statusline()}
set statusline+=%*
let g:ale_fixers = {
\ 'javascript': ['jshint'],
\
\ }
let g:ale_linters = {
\ 'javascript': ['jshint'],
\}
let g:ale_completion_enabled = 1
let g:airline#extensions#ale#enabled = 1
let g:airline_section_error = airline#section#create_right(['ALE'])
" Write this in your vimrc file
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_open_list = 1
" augroup CloseLoclistWindowGroup
" autocmd!
" autocmd QuitPre * if empty(&buftype) | lclose | endif
" augroup END
" Set this if you want to.
" This can be useful if you are combining ALE with
" some other plugin which sets quickfix errors, etc.
"let g:ale_keep_list_window_open = 1
inoremap <Char-0x07F> <BS>
nnoremap <Char-0x07F> <BS>
"let g:OmniSharp_server_path = '~\.omnisharp\OmniSharp.exe'
let g:OmniSharp_selector_ui = 'ctrlp'
map <C-n> :NERDTreeToggle<CR>
" Set the type lookup function to use the preview window instead of echoing it
"let g:OmniSharp_typeLookupInPreview = 1
let g:OmniSharp_server_type = 'roslyn'
"let g:OmniSharp_prefer_global_sln = 1
" Timeout in seconds to wait for a response from the server
let g:OmniSharp_timeout = 10
let g:Omnisharp_stop_server = 1
" Don't autoselect first omnicomplete option, show options even if there is only
" one (so the preview documentation is accessible). Remove 'preview' if you
" don't want to see any documentation whatsoever.
set completeopt=longest,menuone
" Fetch full documentation during omnicomplete requests.
" There is a performance penalty with this (especially on Mono).
" By default, only Type/Method signatures are fetched. Full documentation can
" still be fetched when you need it with the :OmniSharpDocumentation command.
"let g:omnicomplete_fetch_full_documentation = 1
" Set desired preview window height for viewing documentation.
" You might also want to look at the echodoc plugin.
set previewheight=5
" Get code issues and syntax errors
autocmd BufNewFile,BufRead *.cs setlocal errorformat=\ %#%f(%l\\\,%c):\ %m
" autocmd BufNewFile,BufRead *.cs setlocal makeprg=dotnet\ build\ /property:GenerateFullPaths=true
augroup omnisharp_commands
autocmd!
" Synchronous build (blocks Vim)
"autocmd FileType cs nnoremap <buffer> <F5> :wa!<CR>:OmniSharpBuild<CR>
" Builds can also run asynchronously with vim-dispatch installed
autocmd FileType cs nnoremap <buffer> <Leader>b :wa!<CR>:OmniSharpBuildAsync<CR>
" Automatic syntax check on events (TextChanged requires Vim 7.4)
" Automatically add new cs files to the nearest project on save
autocmd BufWritePost *.cs call OmniSharp#AddToProject()
" Show type information automatically when the cursor stops moving
autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()
" The following commands are contextual, based on the cursor position.
autocmd FileType cs nnoremap <buffer> gd :OmniSharpGotoDefinition<CR>
autocmd FileType cs nnoremap <buffer> <Leader>fi :OmniSharpFindImplementations<CR>
autocmd FileType cs nnoremap <buffer> <Leader>fs :OmniSharpFindSymbol<CR>
autocmd FileType cs nnoremap <buffer> <Leader>fu :OmniSharpFindUsages<CR>
" Finds members in the current buffer
autocmd FileType cs nnoremap <buffer> <Leader>fm :OmniSharpFindMembers<CR>
" Cursor can be anywhere on the line containing an issue
autocmd FileType cs nnoremap <buffer> <Leader>x :OmniSharpFixIssue<CR>
autocmd FileType cs nnoremap <buffer> <Leader>fx :OmniSharpFixUsings<CR>
autocmd FileType cs nnoremap <buffer> <Leader>tt :OmniSharpTypeLookup<CR>
autocmd FileType cs nnoremap <buffer> <Leader>dc :OmniSharpDocumentation<CR>
" Navigate up and down by method/property/field
autocmd FileType cs nnoremap <buffer> <C-k> :OmniSharpNavigateUp<CR>
autocmd FileType cs nnoremap <buffer> <C-j> :OmniSharpNavigateDown<CR>
augroup END
" Contextual code actions (uses fzf, CtrlP or unite.vim when available)
"nnoremap <Leader><Space> :OmniSharpGetCodeActions<CR>
" Run code actions with text selected in visual mode to extract method
xnoremap <Leader><Space> :call OmniSharp#GetCodeActions('visual')<CR>
" Rename with dialog
nnoremap <Leader>nm :OmniSharpRename<CR>
nnoremap <F2> :OmniSharpRename<CR>
" Rename without dialog - with cursor on the symbol to rename: `:Rename newname`
command! -nargs=1 Rename :call OmniSharp#RenameTo("<args>")
" Force OmniSharp to reload the solution. Useful when switching branches etc.
nnoremap <Leader>rl :OmniSharpReloadSolution<CR>
nnoremap <Leader>cf :OmniSharpCodeFormat<CR>
" Load the current .cs file to the nearest project
nnoremap <Leader>tp :OmniSharpAddToProject<CR>
" Start the omnisharp server for the current solution
nnoremap <Leader>ss :OmniSharpStartServer<CR>
nnoremap <Leader>sp :OmniSharpStopServer<CR>
" Add syntax highlighting for types and interfaces
nnoremap <Leader>th :OmniSharpHighlightTypes<CR>
" Enable snippet completion
let g:OmniSharp_want_snippet=1
"set tags=~/.vim/.git/vim.tags,~/.vim/.git/tags,./tags,./TAGS,tags,TAGS,~/.vimtags,/tmp/.graudeejs/.vim/easytags/vim
"let g:vim_tags_use_vim_dispatch = 1
nnoremap <Leader>rr :Rg<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment