vimrc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. colorscheme torte " set black color scheme
  40. syntax enable " enable syntax processing
  41. set nocursorline " don't highlight current line
  42. set nohlsearch " disable search highlight
  43. set showmatch " highlight matching brackets
  44. set lazyredraw " redraw only when necessary (faster macros)
  45. """ Tabs
  46. set tabstop=4 " number of visual spaces per TAB
  47. set softtabstop=4 " number of spaces in tab when editing
  48. set shiftwidth=4 " number of space when using > or <
  49. set expandtab " tabs are spaces
  50. """ Numbering
  51. set number " show line numbers
  52. set rnu " show relative line numbers
  53. " toggle relative line nums when focus is gained/lost
  54. :au FocusLost * :set norelativenumber
  55. :au FocusGained * :set relativenumber
  56. " map C-n to toggle line nums
  57. function! NumberToggle()
  58. if(&relativenumber == 1)
  59. set norelativenumber
  60. else
  61. set relativenumber
  62. endif
  63. endfunc
  64. nnoremap <Leader>n :call NumberToggle()<CR>
  65. """ Command menu and Searching
  66. set wildmenu " visual autocomplete for command menu
  67. set wildmode=longest,full " don't autocomplete on first tab press
  68. set showcmd " show command in bottom bar
  69. set incsearch " search as characters are entered
  70. " search through subdirectories when looking for files
  71. set path+=**
  72. """ Folds
  73. set foldmethod=indent " fold based on indent
  74. set foldlevelstart=1 " foldlevel when window is loaded
  75. set foldmethod=indent " fold based on indent level
  76. """ Insert mode
  77. " backspace is used to remove previous characters, indents, and newlines
  78. set backspace=indent,eol,start
  79. " Map Ctrl-Backspace to delete the previous word in insert mode.
  80. imap <C-BS> <C-W>
  81. """ Filetypes
  82. autocmd FileType make setlocal noexpandtab " set Makefiles with tabs not spaces
  83. filetype indent on " load filetype-specific indent files
  84. " ensure normal tabs and 8 space tabs in assembly files
  85. autocmd FileType asm set noexpandtab shiftwidth=8 softtabstop=0
  86. """ System/OS
  87. set mouse= " disable the mouse
  88. " set shell to zsh on linux (if it exists)
  89. if !(has("win32") || has("win16") || has("win32unix"))
  90. if filereadable("/bin/zsh") && $SHELL=="/bin/zsh"
  91. silent! set shell=/bin/zsh
  92. endif
  93. endif
  94. set updatecount=10 " swap files are rotated every 10 keystrokes
  95. " make an undo file to allow undoing after closing a file
  96. set undofile
  97. set undodir=~/.vim/undodir
  98. " compare current buffer to saved file
  99. function! s:DiffWithSaved()
  100. let filetype=&ft
  101. diffthis
  102. vnew | r # | normal! 1Gdd
  103. diffthis
  104. exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  105. endfunction
  106. com! DiffSaved call s:DiffWithSaved()
  107. " map the comp buff function above
  108. noremap <Leader>d :DiffSaved<CR>
  109. " write w/ privileges when Vim isn't started as root
  110. cmap w!! %!sudo tee > /dev/null %
  111. " ignore modelines
  112. set modelines=0
  113. " toggle background
  114. function! ClearBG()
  115. highlight Normal ctermbg=none
  116. endfunction
  117. function! BlackBG()
  118. highlight Normal ctermbg=black
  119. endfunction
  120. """ Key shortcuts
  121. " remove trailing whitespace and return to start position
  122. " remove highlight if in nvim
  123. if has('nvim')
  124. noremap <Leader>w :%s/\s\+$//<CR>:nohl<CR>``
  125. else
  126. noremap <Leader>w :%s/\s\+$//<CR>``
  127. endif
  128. " <Leader>l formats a line
  129. noremap <Leader>l Vgq
  130. " <Leader>s toggles spelling
  131. function! SpellToggle()
  132. if(&spell == 1)
  133. setlocal nospell
  134. else
  135. setlocal spell spelllang=en_us
  136. endif
  137. endfunc
  138. nnoremap <Leader>s :call SpellToggle()<CR>
  139. """ Plugins
  140. " show recently opened files
  141. noremap <Leader>m :MRU<CR>
  142. " show undo tree
  143. noremap <Leader>u :UndotreeToggle<CR>
  144. " syntastic/YCM
  145. if exists(':SyntasticStatuslineFlag()')
  146. set statusline+=%#warningmsg#
  147. set statusline+=%{SyntasticStatuslineFlag()}
  148. set statusline+=%*
  149. let g:syntastic_always_populate_loc_list = 1
  150. let g:syntastic_auto_loc_list = 1
  151. let g:syntastic_check_on_open = 1
  152. let g:syntastic_check_on_wq = 0
  153. endif
  154. " YouCompleteMe
  155. let g:ycm_global_ycm_extra_conf = '/home/josh/.vim/bundle/ycm_extra_conf.py'
  156. " autoclose suggestion windows
  157. let g:ycm_autoclose_preview_window_after_insertion=1
  158. " colors
  159. highlight YcmWarningSection ctermfg=Yellow
  160. highlight YcmWarningSign ctermfg=Yellow
  161. highlight YcmErrorSection ctermfg=Red
  162. highlight YcmErrorsign ctermfg=Red
  163. " place the vim-airline bar above the command line
  164. set laststatus=2
  165. " ignore trailing whitespace in markdown
  166. autocmd FileType markdown AirlineToggleWhitespace
  167. """ Neovim
  168. if has('nvim')
  169. " Esc returns to normal mode in terminal mode
  170. tnoremap <C-w> <C-\><C-n><C-w>
  171. endif