vimrc 9.1 KB

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