.vimrc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. " Vundle
  2. set nocompatible " be iMproved, required
  3. filetype off " required
  4. " set the runtime path to include Vundle and initialize
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7. " alternatively, pass a path where Vundle should install plugins
  8. "call vundle#begin('~/some/path/here')
  9. " let Vundle manage Vundle, required
  10. Plugin 'VundleVim/Vundle.vim'
  11. " The following are examples of different formats supported.
  12. " Keep Plugin commands between vundle#begin/end.
  13. Plugin 'mbbill/undotree'
  14. Plugin 'scrooloose/syntastic'
  15. Plugin 'vim-scripts/mru.vim'
  16. Plugin 'tpope/vim-fugitive'
  17. Plugin 'benmills/vimux'
  18. Plugin 'vim-airline/vim-airline'
  19. Plugin 'Valloric/YouCompleteMe'
  20. Plugin 'rust-lang/rust.vim'
  21. Plugin 'ctrlpvim/ctrlp.vim'
  22. " All of your Plugins must be added before the following line
  23. call vundle#end() " required
  24. filetype plugin indent on " required
  25. " To ignore plugin indent changes, instead use:
  26. "filetype plugin on
  27. "
  28. " Brief help
  29. " :PluginList - lists configured plugins
  30. " :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
  31. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  32. " :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
  33. "
  34. " see :h vundle for more details or wiki for FAQ
  35. " Put your non-Plugin stuff after this line
  36. " space is Leader
  37. map <space> <leader>
  38. """ Visual
  39. syntax enable " enable syntax processing
  40. set nocursorline " don't highlight current line
  41. set nohlsearch " disable search highlight
  42. set showmatch " highlight matching brackets
  43. set lazyredraw " redraw only when necessary (faster macros)
  44. """ Tabs
  45. set tabstop=4 " number of visual spaces per TAB
  46. set softtabstop=4 " number of spaces in tab when editing
  47. set shiftwidth=4 " number of space when using > or <
  48. set expandtab " tabs are spaces
  49. """ Numbering
  50. set number " show line numbers
  51. set rnu " show relative line numbers
  52. " toggle relative line nums when focus is gained/lost
  53. :au FocusLost * :set norelativenumber
  54. :au FocusGained * :set relativenumber
  55. " map C-n to toggle line nums
  56. function! NumberToggle()
  57. if(&relativenumber == 1)
  58. set norelativenumber
  59. else
  60. set relativenumber
  61. endif
  62. endfunc
  63. nnoremap <Leader>n :call NumberToggle()<CR>
  64. """ Command menu and Searching
  65. set wildmenu " visual autocomplete for command menu
  66. set wildmode=longest,full " don't autocomplete on first tab press
  67. set showcmd " show command in bottom bar
  68. set incsearch " search as characters are entered
  69. " search through subdirectories when looking for files
  70. set path+=**
  71. """ Folds
  72. set foldmethod=indent " fold based on indent
  73. set foldlevelstart=20 " foldlevel when window is loaded
  74. set foldmethod=indent " fold based on indent level
  75. """ Insert mode
  76. " backspace is used to remove previous characters, indents, and newlines
  77. set backspace=indent,eol,start
  78. " Map Ctrl-Backspace to delete the previous word in insert mode.
  79. imap <C-BS> <C-W>
  80. """ Filetypes
  81. autocmd FileType make setlocal noexpandtab " set Makefiles with tabs not spaces
  82. filetype indent on " load filetype-specific indent files
  83. " ensure normal tabs and 8 space tabs in assembly files
  84. autocmd FileType asm set noexpandtab shiftwidth=8 softtabstop=0
  85. """ System/OS
  86. set mouse= " disable the mouse
  87. " set shell to zsh on linux (if it exists)
  88. if !(has("win32") || has("win16") || has("win32unix"))
  89. if filereadable("/bin/zsh") && $SHELL=="/bin/zsh"
  90. silent! set shell=/bin/zsh
  91. endif
  92. endif
  93. set updatecount=10 " swap files are rotated every 10 keystrokes
  94. " make an undo file to allow undoing after closing a file
  95. set undofile
  96. set undodir=~/.vim/undodir
  97. " compare current buffer to saved file
  98. function! s:DiffWithSaved()
  99. let filetype=&ft
  100. diffthis
  101. vnew | r # | normal! 1Gdd
  102. diffthis
  103. exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  104. endfunction
  105. com! DiffSaved call s:DiffWithSaved()
  106. " map the comp buff function above
  107. noremap <Leader>d :DiffSaved<CR>
  108. " write w/ privileges when Vim isn't started as root
  109. cmap w!! %!sudo tee > /dev/null %
  110. " ignore modelines
  111. set modelines=0
  112. " toggle background
  113. function! ClearBG()
  114. highlight Normal ctermbg=none
  115. endfunction
  116. function! BlackBG()
  117. highlight Normal ctermbg=black
  118. endfunction
  119. """ Key shortcuts
  120. " remove trailing whitespace and return to start position
  121. " remove highlight if in nvim
  122. if has('nvim')
  123. noremap <Leader>w :%s/\s\+$//<CR>:nohl<CR>``
  124. else
  125. noremap <Leader>w :%s/\s\+$//<CR>``
  126. endif
  127. " <Leader>l formats a line
  128. noremap <Leader>l Vgq
  129. " <Leader>s toggles spelling
  130. function! SpellToggle()
  131. if(&spell == 1)
  132. setlocal nospell
  133. else
  134. setlocal spell spelllang=en_us
  135. endif
  136. endfunc
  137. nnoremap <Leader>s :call SpellToggle()<CR>
  138. """ Plugins
  139. " show recently opened files
  140. noremap <Leader>m :MRU<CR>
  141. " show undo tree
  142. noremap <Leader>u :UndotreeToggle<CR>
  143. " syntastic/YCM
  144. if exists(':SyntasticStatuslineFlag()')
  145. set statusline+=%#warningmsg#
  146. set statusline+=%{SyntasticStatuslineFlag()}
  147. set statusline+=%*
  148. let g:syntastic_always_populate_loc_list = 1
  149. let g:syntastic_auto_loc_list = 1
  150. let g:syntastic_check_on_open = 1
  151. let g:syntastic_check_on_wq = 0
  152. endif
  153. " YouCompleteMe
  154. let g:ycm_global_ycm_extra_conf = '/home/josh/.vim/bundle/ycm_extra_conf.py'
  155. " autoclose suggestion windows
  156. let g:ycm_autoclose_preview_window_after_insertion=1
  157. " colors
  158. highlight YcmWarningSection ctermfg=Yellow
  159. highlight YcmWarningSign ctermfg=Yellow
  160. highlight YcmErrorSection ctermfg=Red
  161. highlight YcmErrorsign ctermfg=Red
  162. "" diff colors
  163. highlight DiffAdd cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
  164. highlight DiffDelete cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
  165. highlight DiffChange cterm=bold ctermfg=10 ctermbg=17 gui=none guifg=bg guibg=Red
  166. highlight DiffText cterm=bold ctermfg=10 ctermbg=88 gui=none guifg=bg guibg=Red
  167. " place the vim-airline bar above the command line
  168. set laststatus=2
  169. " ignore trailing whitespace in markdown
  170. autocmd FileType markdown AirlineToggleWhitespace
  171. """ Neovim
  172. if has('nvim')
  173. " Esc returns to normal mode in terminal mode
  174. tnoremap <C-w> <C-\><C-n><C-w>
  175. endif