vimrc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. " space is Leader
  38. map <space> <leader>
  39. " fold based on indent level
  40. set foldmethod=indent
  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. " Esc clears search highlight
  54. nnoremap <silent> <esc> :noh<cr><esc>
  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. "caps switching functions - unused
  62. "" function to check for running instances of vim on Linux
  63. "function! UnixCapsControl()
  64. " silent! let running = system('echo $(pgrep -c vim)')
  65. " if(running <= 1)
  66. " silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Caps_Lock'
  67. " endif
  68. "endfunction
  69. "
  70. "" map caps lock to escape under Linux
  71. "if !(has("win32") || has("win16") || has("win32unix")) && (!$SSH_CLIENT && !$SSH_TTY) && executable("xmodmap")
  72. " au VimEnter * silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
  73. " au VimLeave * :call UnixCapsControl()
  74. "endif
  75. "
  76. "" function to check for running instances of vim on Windows
  77. "function! WindowsCapsControl()
  78. " silent! let running = system('tasklist /FI "IMAGENAME eq vim.exe" 2>NUL | find /I /C "vim.exe"')
  79. " if(running <= 1)
  80. " silent! !start taskkill /IM CapsEsc.exe
  81. " endif
  82. "endfunction
  83. "
  84. "" map caps lock to escape under Windows
  85. "if (has("win32") || has("win16"))
  86. " au VimEnter * silent! !start C:\Users\Josh\vimfiles\CapsEsc.exe
  87. " au VimLeave * :call WindowsCapsControl()
  88. "endif
  89. ""
  90. "" function to check for running instances of vim on Cygwin
  91. "function! CygwinCapsControl()
  92. " silent! let running = system('echo $(pgrep -c vim)')
  93. " if(running <= 1)
  94. " silent! !pkill CapsEsc
  95. " endif
  96. "endfunction
  97. "
  98. "" map caps lock to escape under Cygwin
  99. "if (has("win32unix"))
  100. " au VimEnter * silent! !/home/josh/.vim/CapsEsc.exe &
  101. " au VimLeave * :call CygwinCapsControl()
  102. "endif
  103. " swap files are rotated every 10 keystrokes
  104. set updatecount=10
  105. " backspace is used to remove previous characters, indents, and newlines
  106. set backspace=indent,eol,start
  107. " <Leader>l formats a line
  108. noremap <Leader>l Vgq
  109. " make an undo file to allow undoing after closing a file
  110. set undofile
  111. set undodir=~/.vim/undodir
  112. " set Makefiles with tabs not spaces
  113. autocmd FileType make setlocal noexpandtab
  114. " compare current buffer to saved file
  115. function! s:DiffWithSaved()
  116. let filetype=&ft
  117. diffthis
  118. vnew | r # | normal! 1Gdd
  119. diffthis
  120. exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  121. endfunction
  122. com! DiffSaved call s:DiffWithSaved()
  123. " map the comp buff function above
  124. noremap <Leader>d :DiffSaved<CR>
  125. " map the write and make function
  126. noremap <Leader>c :WriteMake<CR>
  127. " write w/ privileges when Vim isn't started as root
  128. cmap w!! %!sudo tee > /dev/null %
  129. " remove trailing whitespace and return to start position
  130. noremap <Leader>w :%s/\s\+$//<CR>``
  131. " plugins
  132. " show recently opened files
  133. noremap <Leader>m :MRU<CR>
  134. " Start Geeknote
  135. noremap <Leader>g :Geeknote<CR>
  136. " show undo tree
  137. noremap <Leader>u :UndotreeToggle<CR>
  138. " syntastic/YCM
  139. if exists(':SyntasticStatuslineFlag()')
  140. set statusline+=%#warningmsg#
  141. set statusline+=%{SyntasticStatuslineFlag()}
  142. set statusline+=%*
  143. let g:syntastic_always_populate_loc_list = 1
  144. let g:syntastic_auto_loc_list = 1
  145. let g:syntastic_check_on_open = 1
  146. let g:syntastic_check_on_wq = 0
  147. endif
  148. " YouCompleteMe
  149. let g:ycm_global_ycm_extra_conf = '/home/josh/.vim/bundle/ycm_extra_conf.py'
  150. " autoclose suggestion windows
  151. let g:ycm_autoclose_preview_window_after_insertion=1
  152. " colors
  153. highlight YcmWarningSection ctermfg=Yellow
  154. highlight YcmWarningSign ctermfg=Yellow
  155. highlight YcmErrorSection ctermfg=Red
  156. highlight YcmErrorsign ctermfg=Red
  157. " vim-airline
  158. " place the airline bar above the command line
  159. set laststatus=2