vimrc 4.2 KB

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