vimrc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. \| if empty(bufname('%'))
  59. \| browse confirm write
  60. \| else
  61. \| confirm write
  62. \| endif
  63. \|endif
  64. nnoremap <silent> <C-s> :Save<CR>
  65. inoremap <C-s> <C-o>:Save<CR>
  66. vnoremap <C-s> <C-o>:Save<CR>
  67. " CTRL+w to close the current buffer
  68. nnoremap <silent> <C-w> :call CloseWindow()<CR>
  69. " Buffer magic
  70. nnoremap <leader>l :ls<CR>:b<space>
  71. nnoremap <leader>b :ls<CR>:bd<space>
  72. " Switch indentation settings
  73. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  74. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  75. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  76. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  77. " To wrap or not to wrap
  78. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  79. " Window Switching and Resizing
  80. nnoremap <silent> <C-k> :wincmd k<CR>
  81. nnoremap <silent> <C-J> :wincmd j<CR>
  82. nnoremap <silent> <C-h> :wincmd h<CR>
  83. nnoremap <silent> <C-l> :wincmd l<CR>
  84. nnoremap <silent> + :wincmd +<CR>
  85. nnoremap <silent> _ :wincmd -<CR>
  86. nnoremap <silent> ) :wincmd ><CR>
  87. nnoremap <silent> ( :wincmd <<CR>
  88. nnoremap <silent> <leader>r :wincmd r<CR>
  89. nnoremap <silent> <leader>R :wincmd R<CR>
  90. " ALt+d to duplicate a line, vmode version is best for SHIFT+V, not the others
  91. nnoremap <D-d> yyp
  92. vnoremap <D-d> y<C-o>p
  93. inoremap <D-d> <C-o>:yank<CR><C-o>:put<CR>
  94. " Open new files in new buffer or new windows
  95. nnoremap <C-o> :e<space>
  96. nnoremap <C-p> :sp<space>
  97. nnoremap <D-p> :vs<space>
  98. " Move lines of text via Alt+[jk] (Like sublime!)
  99. nnoremap <D-j> :m+1<CR>==
  100. nnoremap <D-k> :m-2<CR>==
  101. vnoremap <D-j> :m '>+1<CR>gv=gv
  102. vnoremap <D-k> :m '<-2<CR>gv=gv
  103. " Clear searches so there aren't underlined words.
  104. nnoremap <silent> <C-i> :nohlsearch<CR>
  105. " Set specific directories for swap, undo, and backups.
  106. set backupdir=~/.vim/tmp/backup//
  107. set directory=~/.vim/tmp/swap//
  108. set undodir=~/.vim/tmp/undo//
  109. set undofile
  110. macmenu File.Print key=<nop>
  111. """""""""""""""""""""""""""""""""""""""""
  112. " Ctrl-P Settings
  113. """""""""""""""""""""""""""""""""""""""""
  114. " Keybinding and functionality
  115. let g:ctrlp_map = "<leader>o"
  116. let g:ctrlp_cmd = 'CtrlPLastMode'
  117. let g:ctrlp_extensions = ['line']
  118. " Move Ctrl-P to top of the screen
  119. let g:ctrlp_match_window_bottom = 0
  120. let g:ctrlp_match_window_reversed = 0
  121. " Ignore some filetypes
  122. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  123. let g:ctrlp_switch_buffer = 'E'
  124. "let g:ctrlp_by_filename = 1
  125. let g:ctrlp_clear_cache_on_exit = 0
  126. " Uncomment to show hidden directories.
  127. "let g:ctrlp_show_hidden = 1
  128. """""""""""""""""""""""""""""""""""""""""
  129. " Airline (Powerline replacement)
  130. """""""""""""""""""""""""""""""""""""""""
  131. let g:airline_theme = 'powerlineish'
  132. let g:airline_powerline_fonts = 1
  133. """""""""""""""""""""""""""""""""""""""""
  134. " NerdTree
  135. """""""""""""""""""""""""""""""""""""""""
  136. " Directory tree toggle
  137. nnoremap <leader>e :NERDTreeToggle<CR>
  138. """""""""""""""""""""""""""""""""""""""""
  139. " NerdCommenter
  140. """""""""""""""""""""""""""""""""""""""""
  141. map <leader>cc <plug>NERDCommenterToggle
  142. " For some reason, CommentToggle doesn't work unless this is
  143. " remapped, so remapping it to something I won't ever use.
  144. map <leader><D-/><space> <plug>NERDCommenterComment
  145. """"""""""""""""""""""""""""""""""""""""
  146. " UltiSnips
  147. """"""""""""""""""""""""""""""""""""""""
  148. let g:UltiSnipsExpandTrigger = "<D-C>"
  149. let g:UltiSnipsJumpForwardTrigger = "<D-W>"
  150. let g:UltiSnipsJumpBackwardTrigger = "<D-S>"
  151. """""""""""""""""""""""""""""""""""""""""
  152. " Easytags
  153. """""""""""""""""""""""""""""""""""""""""
  154. set regexpengine=1
  155. let g:easytags_updatetime_min = 4000
  156. """""""""""""""""""""""""""""""""""""""""
  157. " Tex Settings
  158. """""""""""""""""""""""""""""""""""""""""
  159. let g:tex_flavor = "latex"
  160. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  161. autocmd FileType tex setlocal spell spelllang=en_us
  162. """""""""""""""""""""""""""""""""""""""""
  163. " Rails.vim
  164. """""""""""""""""""""""""""""""""""""""""
  165. let g:rails_gem_projections = {
  166. \ "fabrication": {
  167. \ "spec/fabricators/*_fabricator.rb": {
  168. \ "command": "fabricator",
  169. \ "affinity": "model",
  170. \ "alternate": "app/models/%s.rb",
  171. \ "related": "db/schema.rb#%p",
  172. \ "test": "spec/models/%s_spec.rb",
  173. \ "template": "Fabricator :%s do\nend",
  174. \ "keywords": "Fabricate Fabricator sequence"
  175. \ }
  176. \ },
  177. \ "factory_girl_rails": {
  178. \ "spec/factories/*_factory.rb": {
  179. \ "command": "factory",
  180. \ "affinity": "collection",
  181. \ "alternate": "app/models/%i.rb",
  182. \ "related": "db/schema.rb#%s",
  183. \ "test": "spec/models/%i_spec.rb",
  184. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  185. \ "keywords": "factory sequence"
  186. \ }
  187. \ },
  188. \ "factory_girl": {
  189. \ "spec/factories/*.rb": {
  190. \ "command": "factory",
  191. \ "affinity": "collection",
  192. \ "alternate": "app/models/%i.rb",
  193. \ "related": "db/schema.rb#%s",
  194. \ "test": "spec/models/%i_spec.rb",
  195. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  196. \ "keywords": "factory sequence"
  197. \ }
  198. \ },
  199. \ "cucumber-rails": {
  200. \ "features/*.feature": {
  201. \ "command": "feature",
  202. \ "template": "Feature: %h\n\n Scenario: " ,
  203. \ },
  204. \ "features/step_definitions/*_steps.rb": {
  205. \ "command": "steps",
  206. \ "affinity": "collection"
  207. \ }
  208. \ },
  209. \ "draper": {
  210. \ "app/decorators/*_decorator.rb": {
  211. \ "command": "decorator",
  212. \ "affinity": "model",
  213. \ "alternate": "app/models/%s.rb",
  214. \ "related": "db/schema.rb#%p",
  215. \ "test": "spec/decorators/%s_decorator_spec.rb",
  216. \ "template": "class %SDecorator < Draper::Decorator\n\nend" ,
  217. \ }
  218. \ }
  219. \ }
  220. """""""""""""""""""""""""""""""""""""""""
  221. " YCM Settings
  222. """""""""""""""""""""""""""""""""""""""""
  223. let g:ycm_register_as_syntastic_checker = 0
  224. """""""""""""""""""""""""""""""""""""""""
  225. " Colors and Themes
  226. """""""""""""""""""""""""""""""""""""""""
  227. syntax enable
  228. "Set 256 color mode (not always needed).
  229. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  230. set t_Co=256
  231. endif
  232. " Use a nice color scheme
  233. colors Monokai
  234. """"""""""""""""""""""""""""""""""""""""
  235. " Useful Stuff
  236. """"""""""""""""""""""""""""""""""""""""
  237. " Delete trailing whitespaces on saving.
  238. func! DeleteTrailingWS()
  239. exe "normal mz"
  240. %s/\s\+$//ge
  241. exe "normal `z"
  242. endfunc
  243. autocmd BufWrite * :call DeleteTrailingWS()
  244. " Allow the use of ALT as a function key.
  245. let c='a'
  246. while c <= 'z'
  247. exec "set <A-".c.">=\e".c
  248. exec "imap \e".c." <A-".c.">"
  249. let c = nr2char(1+char2nr(c))
  250. endw
  251. " Close current window or vim if no unsaved windows are open.
  252. fun! CloseWindow()
  253. if &modified
  254. echo "Save first or manual exit."
  255. else
  256. if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
  257. q
  258. else
  259. :bd
  260. endif
  261. endif
  262. endfunction
  263. " For auto-aligning cucumber tables
  264. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  265. function! s:align()
  266. let p = '^\s*|\s.*\s|\s*$'
  267. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  268. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  269. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  270. Tabularize/|/l1
  271. normal! 0
  272. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  273. endif
  274. endfunction