vimrc 3.8 KB

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