vimrc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. " Use pathogen to load other plugins
  2. execute pathogen#infect()
  3. Helptags
  4. filetype plugin indent on
  5. """""""""""""""""""""""""""""""""""""""""
  6. " Some Basics
  7. " Note : vim-sensible does some of these
  8. " settings already
  9. """""""""""""""""""""""""""""""""""""""""
  10. set encoding=utf-8
  11. " Search settings
  12. set incsearch
  13. set ignorecase
  14. set smartcase
  15. set hlsearch
  16. " Indentation and tab functionality
  17. set tabstop=2
  18. set shiftwidth=2
  19. set softtabstop=2
  20. set expandtab
  21. set autoindent
  22. set smarttab
  23. set smartindent
  24. " Code Folding
  25. set nofoldenable
  26. set foldmethod=indent
  27. set foldnestmax=10
  28. set viewoptions=cursor,folds,slash,unix
  29. " let g:skipview_files = ['*\.vim']
  30. " Line numbers
  31. set number
  32. " Line Wrapping
  33. set nowrap
  34. " Automatically update externally updated files
  35. set autoread
  36. " Command expiration
  37. set timeout
  38. set ttimeoutlen=15
  39. " New window split settings
  40. set splitright
  41. " Remember buffer info on close
  42. set viminfo^=%
  43. " Set font for (m|g)vim
  44. set guifont=Meslo\ LG\ S\ for\ Powerline:h11
  45. set guioptions=c
  46. " Which line is the 80th column?
  47. set cc=80
  48. """""""""""""""""""""""""""""""""""""""""
  49. " Keybinds
  50. """""""""""""""""""""""""""""""""""""""""
  51. let mapleader="\<space>"
  52. " Wrapped lines treated like normal ones
  53. nnoremap j gj
  54. nnoremap k gk
  55. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  56. " browse is only available in gvim
  57. command! -nargs=0 -bar Save if &modified
  58. \| confirm write
  59. \|endif
  60. nnoremap <silent> <C-s> :Save<CR>
  61. inoremap <C-s> <C-o>:Save<CR>
  62. vnoremap <C-s> <C-o>:Save<CR>
  63. " CTRL+w to close the current buffer
  64. nnoremap <silent> <C-w> :call CloseWindow()<CR>
  65. nnoremap <silent> <S-w> :hide<CR>
  66. " Buffer magic
  67. nnoremap <leader>l :ls<CR>:b<space>
  68. nnoremap <leader>b :ls<CR>:bd<space>
  69. " Switch indentation settings
  70. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  71. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  72. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  73. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  74. " To wrap or not to wrap
  75. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  76. " Window Switching and Resizing
  77. nnoremap <silent> <C-k> :wincmd k<CR>
  78. nnoremap <silent> <C-J> :wincmd j<CR>
  79. nnoremap <silent> <C-h> :wincmd h<CR>
  80. nnoremap <silent> <C-l> :wincmd l<CR>
  81. nnoremap <silent> + :wincmd +<CR>
  82. nnoremap <silent> _ :wincmd -<CR>
  83. nnoremap <silent> ) :wincmd ><CR>
  84. nnoremap <silent> ( :wincmd <<CR>
  85. nnoremap <silent> <leader>r :wincmd r<CR>
  86. nnoremap <silent> <leader>R :wincmd R<CR>
  87. " ALt+d to duplicate a line, vmode version is best for SHIFT+V, not the others
  88. nnoremap <D-d> yyp
  89. vnoremap <D-d> y<C-o>p
  90. inoremap <D-d> <C-o>:yank<CR><C-o>:put<CR>
  91. " Open new files in new buffer or new windows
  92. nnoremap <C-o> :e<space>
  93. nnoremap <C-p> :sp<space>
  94. nnoremap <D-p> :vs<space>
  95. " Move lines of text via Alt+[jk] (Like sublime!)
  96. nnoremap <D-j> :m+1<CR>==
  97. nnoremap <D-k> :m-2<CR>==
  98. vnoremap <D-j> :m '>+1<CR>gv=gv
  99. vnoremap <D-k> :m '<-2<CR>gv=gv
  100. " Clear searches so there aren't underlined words.
  101. nnoremap <silent> <C-i> :nohlsearch<CR>
  102. " Set specific directories for swap, undo, and backups.
  103. set backupdir=~/.vim/tmp/backup//
  104. set directory=~/.vim/tmp/swap//
  105. set undodir=~/.vim/tmp/undo//
  106. set undofile
  107. macmenu File.Print key=<nop>
  108. """""""""""""""""""""""""""""""""""""""""
  109. " Ctrl-P Settings
  110. """""""""""""""""""""""""""""""""""""""""
  111. " Keybinding and functionality
  112. let g:ctrlp_map = "<leader>o"
  113. let g:ctrlp_cmd = 'CtrlPLastMode'
  114. let g:ctrlp_extensions = ['line']
  115. " Move Ctrl-P to top of the screen
  116. let g:ctrlp_match_window_bottom = 0
  117. let g:ctrlp_match_window_reversed = 0
  118. " Ignore some filetypes
  119. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  120. let g:ctrlp_switch_buffer = 'E'
  121. "let g:ctrlp_by_filename = 1
  122. let g:ctrlp_clear_cache_on_exit = 0
  123. " Uncomment to show hidden directories.
  124. "let g:ctrlp_show_hidden = 1
  125. """""""""""""""""""""""""""""""""""""""""
  126. " Airline (Powerline replacement)
  127. """""""""""""""""""""""""""""""""""""""""
  128. let g:airline_theme = 'powerlineish'
  129. let g:airline_powerline_fonts = 1
  130. """""""""""""""""""""""""""""""""""""""""
  131. " NerdTree
  132. """""""""""""""""""""""""""""""""""""""""
  133. " Directory tree toggle
  134. nnoremap <leader>e :NERDTreeToggle<CR>
  135. """""""""""""""""""""""""""""""""""""""""
  136. " NerdCommenter
  137. """""""""""""""""""""""""""""""""""""""""
  138. map <leader>cc <plug>NERDCommenterToggle
  139. " For some reason, CommentToggle doesn't work unless this is
  140. " remapped, so remapping it to something I won't ever use.
  141. map <leader><D-/><space> <plug>NERDCommenterComment
  142. """"""""""""""""""""""""""""""""""""""""
  143. " UltiSnips
  144. """"""""""""""""""""""""""""""""""""""""
  145. let g:UltiSnipsExpandTrigger = "<D-C>"
  146. let g:UltiSnipsJumpForwardTrigger = "<D-W>"
  147. let g:UltiSnipsJumpBackwardTrigger = "<D-S>"
  148. """""""""""""""""""""""""""""""""""""""""
  149. " Easytags
  150. """""""""""""""""""""""""""""""""""""""""
  151. set regexpengine=1
  152. let g:easytags_updatetime_min = 4000
  153. """""""""""""""""""""""""""""""""""""""""
  154. " Tex Settings
  155. """""""""""""""""""""""""""""""""""""""""
  156. let g:tex_flavor = "latex"
  157. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  158. autocmd FileType tex setlocal spell spelllang=en_us
  159. """""""""""""""""""""""""""""""""""""""""
  160. " Rails.vim
  161. """""""""""""""""""""""""""""""""""""""""
  162. let g:rails_gem_projections = {
  163. \ "fabrication": {
  164. \ "spec/fabricators/*_fabricator.rb": {
  165. \ "command": "fabricator",
  166. \ "affinity": "model",
  167. \ "alternate": "app/models/%s.rb",
  168. \ "related": "db/schema.rb#%p",
  169. \ "test": "spec/models/%s_spec.rb",
  170. \ "template": "Fabricator :%s do\nend",
  171. \ "keywords": "Fabricate Fabricator sequence"
  172. \ }
  173. \ },
  174. \ "factory_girl_rails": {
  175. \ "spec/factories/*_factory.rb": {
  176. \ "command": "factory",
  177. \ "affinity": "collection",
  178. \ "alternate": "app/models/%i.rb",
  179. \ "related": "db/schema.rb#%s",
  180. \ "test": "spec/models/%i_spec.rb",
  181. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  182. \ "keywords": "factory sequence"
  183. \ }
  184. \ },
  185. \ "factory_girl": {
  186. \ "spec/factories/*.rb": {
  187. \ "command": "factory",
  188. \ "affinity": "collection",
  189. \ "alternate": "app/models/%i.rb",
  190. \ "related": "db/schema.rb#%s",
  191. \ "test": "spec/models/%i_spec.rb",
  192. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  193. \ "keywords": "factory sequence"
  194. \ }
  195. \ },
  196. \ "cucumber-rails": {
  197. \ "features/*.feature": {
  198. \ "command": "feature",
  199. \ "template": "Feature: %h\n\n Scenario: " ,
  200. \ },
  201. \ "features/step_definitions/*_steps.rb": {
  202. \ "command": "steps",
  203. \ "affinity": "collection"
  204. \ }
  205. \ },
  206. \ "draper": {
  207. \ "app/decorators/*_decorator.rb": {
  208. \ "command": "decorator",
  209. \ "affinity": "model",
  210. \ "alternate": "app/models/%s.rb",
  211. \ "related": "db/schema.rb#%p",
  212. \ "test": "spec/decorators/%s_decorator_spec.rb",
  213. \ "template": "class %SDecorator < Draper::Decorator\n\nend" ,
  214. \ }
  215. \ }
  216. \ }
  217. """""""""""""""""""""""""""""""""""""""""
  218. " YCM Settings
  219. """""""""""""""""""""""""""""""""""""""""
  220. let g:ycm_register_as_syntastic_checker = 0
  221. """""""""""""""""""""""""""""""""""""""""
  222. " Colors and Themes
  223. """""""""""""""""""""""""""""""""""""""""
  224. syntax enable
  225. "Set 256 color mode (not always needed).
  226. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  227. set t_Co=256
  228. endif
  229. " Use a nice color scheme
  230. colors Monokai
  231. """"""""""""""""""""""""""""""""""""""""
  232. " Useful Stuff
  233. """"""""""""""""""""""""""""""""""""""""
  234. " Delete trailing whitespaces on saving.
  235. function! DeleteTrailingWS()
  236. exe "normal mz"
  237. %s/\s\+$//ge
  238. exe "normal `z"
  239. endfunc
  240. autocmd BufWrite * :call DeleteTrailingWS()
  241. " Allow the use of ALT as a function key.
  242. let c='a'
  243. while c <= 'z'
  244. exec "set <A-".c.">=\e".c
  245. exec "imap \e".c." <A-".c.">"
  246. let c = nr2char(1+char2nr(c))
  247. endw
  248. " Close current window or vim if no unsaved windows are open.
  249. function! CloseWindow()
  250. if &modified
  251. echo "Save first or manual exit."
  252. else
  253. if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
  254. q
  255. else
  256. :bd
  257. endif
  258. endif
  259. endfunction
  260. " For auto-aligning cucumber tables
  261. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  262. function! s:align()
  263. let p = '^\s*|\s.*\s|\s*$'
  264. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  265. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  266. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  267. Tabularize/|/l1
  268. normal! 0
  269. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  270. endif
  271. endfunction