vimrc 4.6 KB

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