vimrc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. " Use pathogen to load other plugins
  2. execute pathogen#infect()
  3. Helptags
  4. filetype plugin indent on
  5. set encoding=utf-8
  6. " Search settings
  7. set incsearch
  8. set ignorecase
  9. set smartcase
  10. set hlsearch
  11. " Indentation and tab functionality
  12. set tabstop=2
  13. set shiftwidth=2
  14. set softtabstop=2
  15. set expandtab
  16. set autoindent
  17. set smarttab
  18. set smartindent
  19. " Code Folding
  20. set nofoldenable
  21. set foldmethod=indent
  22. set foldnestmax=10
  23. set viewoptions=cursor,folds,slash,unix
  24. " Command expiration
  25. set timeout
  26. set ttimeoutlen=15
  27. " Set font for (m|g)vim
  28. set guifont=Meslo\ LG\ S\ for\ Powerline:h11
  29. set guioptions=ce
  30. set number " Line numbers
  31. set nowrap " Line Wrapping
  32. set hidden " Just hide buffer when :bd'ing
  33. set autoread " Automatically update externally updated files
  34. set cc=80 " Which line is the 80th column?
  35. set splitright " New window split settings
  36. set viminfo^=% " Remember buffer info on close
  37. """""""""""""""""""""""""""""""""""""""""
  38. " Keybinds
  39. """""""""""""""""""""""""""""""""""""""""
  40. let mapleader="\<space>"
  41. " Wrapped lines treated like normal ones
  42. nnoremap j gj
  43. nnoremap k gk
  44. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  45. command! -nargs=0 -bar Save if &modified
  46. \| confirm write
  47. \|endif
  48. nnoremap <silent> <C-s> :Update<CR>
  49. inoremap <C-s> <C-o>:Update<CR>
  50. vnoremap <C-s> <C-o>:Update<CR>
  51. " CTRL+w to close the current buffer
  52. nnoremap <silent> <C-w> :bd<CR>
  53. " Buffer magic
  54. nnoremap <leader>l :ls<CR>:b<space>
  55. " Switch indentation settings
  56. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  57. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  58. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  59. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  60. " To wrap or not to wrap
  61. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  62. " Window Switching and Resizing
  63. nnoremap <silent> <C-k> :wincmd k<CR>
  64. nnoremap <silent> <C-J> :wincmd j<CR>
  65. nnoremap <silent> <C-h> :wincmd h<CR>
  66. nnoremap <silent> <C-l> :wincmd l<CR>
  67. nnoremap <silent> + :wincmd +<CR>
  68. nnoremap <silent> _ :wincmd -<CR>
  69. nnoremap <silent> ) :wincmd ><CR>
  70. nnoremap <silent> ( :wincmd <<CR>
  71. nnoremap <silent> <leader>r :wincmd r<CR>
  72. nnoremap <silent> <leader>R :wincmd R<CR>
  73. " ALt+d to duplicate a line, vmode version is best for SHIFT+V, not the others
  74. nnoremap <A-d> yyp
  75. vnoremap <A-d> y<C-o>p
  76. inoremap <A-d> <C-o>:yank<CR><C-o>:put<CR>
  77. " Open new files in new buffer or new windows
  78. nnoremap <C-p> :sp<space>
  79. nnoremap <A-p> :vs<space>
  80. " Move lines of text via Cmd+[jk]
  81. nnoremap <A-j> :m+1<CR>==
  82. nnoremap <A-k> :m-2<CR>==
  83. vnoremap <A-j> :m '>+1<CR>gv=gv
  84. vnoremap <A-k> :m '<-2<CR>gv=gv
  85. " Clear searches so there aren't underlined words.
  86. nnoremap <silent> <C-i> :nohlsearch<CR>
  87. " Set specific directories for swap, undo, and backups.
  88. set backupdir=~/.vim/tmp/backup//
  89. set directory=~/.vim/tmp/swap//
  90. set undodir=~/.vim/tmp/undo//
  91. set viewdir=~/.vim/tmp/view//
  92. set undofile
  93. map <S-k> <nop>
  94. map <S-q> <nop>
  95. """""""""""""""""""""""""""""""""""""""""
  96. " vim-rspec
  97. """""""""""""""""""""""""""""""""""""""""
  98. map <silent> <leader>t :call RunCurrentSpecFile()<CR>
  99. map <silent> <leader>a :call RunAllSpecs()<CR>
  100. map <silent> <leader>s :call RunNearestSpec()<CR>
  101. map <silent> <leader>k :call RunLastSpec()<CR>
  102. let g:rspec_command = "bundle exec spec {spec}"
  103. """""""""""""""""""""""""""""""""""""""""
  104. " Ctrl-P Settings
  105. """""""""""""""""""""""""""""""""""""""""
  106. " Keybinding and functionality
  107. let g:ctrlp_map = "<leader>o"
  108. let g:ctrlp_cmd = 'CtrlPLastMode'
  109. let g:ctrlp_extensions = ['line']
  110. " Move Ctrl-P to top of the screen
  111. let g:ctrlp_match_window_bottom = 0
  112. let g:ctrlp_match_window_reversed = 0
  113. " Ignore some filetypes
  114. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  115. let g:ctrlp_switch_buffer = 'E'
  116. "let g:ctrlp_by_filename = 1
  117. let g:ctrlp_clear_cache_on_exit = 0
  118. " Uncomment to show hidden directories.
  119. "let g:ctrlp_show_hidden = 1
  120. """""""""""""""""""""""""""""""""""""""""
  121. " Airline (Powerline replacement)
  122. """""""""""""""""""""""""""""""""""""""""
  123. let g:airline_theme = 'powerlineish'
  124. let g:airline_powerline_fonts = 1
  125. """""""""""""""""""""""""""""""""""""""""
  126. " NerdTree
  127. """""""""""""""""""""""""""""""""""""""""
  128. " Directory tree toggle
  129. nnoremap <leader>e :NERDTreeToggle<CR>
  130. """""""""""""""""""""""""""""""""""""""""
  131. " NerdCommenter
  132. """""""""""""""""""""""""""""""""""""""""
  133. map <leader>cc <plug>NERDCommenterToggle
  134. " For some reason, CommentToggle doesn't work unless this is
  135. " remapped, so remapping it to something I won't ever use.
  136. map <leader><A-/><space> <plug>NERDCommenterComment
  137. """"""""""""""""""""""""""""""""""""""""
  138. " UltiSnips
  139. """"""""""""""""""""""""""""""""""""""""
  140. let g:UltiSnipsExpandTrigger = "<A-c>"
  141. let g:UltiSnipsJumpForwardTrigger = "<A-w>"
  142. let g:UltiSnipsJumpBackwardTrigger = "<A-s>"
  143. """""""""""""""""""""""""""""""""""""""""
  144. " Easytags
  145. """""""""""""""""""""""""""""""""""""""""
  146. let g:easytags_updatetime_min = 2000
  147. """""""""""""""""""""""""""""""""""""""""
  148. " Tex Settings
  149. """""""""""""""""""""""""""""""""""""""""
  150. let g:tex_flavor = "latex"
  151. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  152. autocmd FileType tex setlocal spell spelllang=en_us
  153. """""""""""""""""""""""""""""""""""""""""
  154. " Colors and Themes
  155. """""""""""""""""""""""""""""""""""""""""
  156. syntax enable
  157. "Set 256 color mode (not always needed).
  158. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  159. set t_Co=256
  160. endif
  161. " Use a nice color scheme
  162. colors Monokai
  163. """"""""""""""""""""""""""""""""""""""""
  164. " Useful Stuff
  165. """"""""""""""""""""""""""""""""""""""""
  166. " Delete trailing whitespaces on saving.
  167. func! DeleteTrailingWS()
  168. exe "normal mz"
  169. %s/\s\+$//ge
  170. exe "normal `z"
  171. endfunc
  172. autocmd BufWrite * :call DeleteTrailingWS()
  173. " Allow the use of ALT as a function key.
  174. let c='a'
  175. while c <= 'z'
  176. exec "set <A-".c.">=\e".c
  177. exec "imap \e".c." <A-".c.">"
  178. let c = nr2char(1+char2nr(c))
  179. endw
  180. " Close current window or quit vim if no active windows
  181. autocmd BufDelete * if len(filter(range(1, bufnr('$')), '!empty(bufname(v:val)) && buflisted(v:val)')) == 1 | q | endif
  182. " For auto-aligning Cucumber tables
  183. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  184. function! s:align()
  185. let p = '^\s*|\s.*\s|\s*$'
  186. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  187. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  188. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  189. Tabularize/|/l1
  190. normal! 0
  191. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  192. endif
  193. endfunction