vimrc 4.2 KB

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