.vimrc 6.1 KB

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