vimrc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. " Use pathogen to load other plugins
  2. execute pathogen#infect()
  3. Helptags
  4. filetype plugin indent on
  5. set encoding=utf-8
  6. set spelllang=en_us
  7. " Search settings
  8. set incsearch
  9. set ignorecase
  10. set smartcase
  11. set hlsearch
  12. " Indentation and tab functionality
  13. set tabstop=2
  14. set shiftwidth=2
  15. set softtabstop=2
  16. set expandtab
  17. set autoindent
  18. set smarttab
  19. set smartindent
  20. " Code Folding
  21. set foldopen-=block
  22. set nofoldenable
  23. set foldmethod=indent
  24. set foldnestmax=10
  25. set viewoptions=cursor,folds,slash,unix
  26. " Command expiration
  27. set timeout
  28. set ttimeoutlen=15
  29. " Set font for (m|g)vim
  30. set guifont=Meslo\ LG\ S\ for\ Powerline:h11
  31. set guioptions=ce
  32. set number " Line numbers
  33. set nowrap " Line Wrapping
  34. set hidden " Just hide buffer when :bd'ing
  35. set autoread " Automatically update externally updated files
  36. set cc=80 " Which line is the 80th column?
  37. set splitright " New window split settings
  38. set splitbelow " New window split settings
  39. set viminfo^=% " Remember buffer info on close
  40. set completeopt=menu
  41. set maxmempattern=8171906 " Because some files are big
  42. """"""""""""""""""""""""""""
  43. " Keybinds
  44. """"""""""""""""""""""""""""
  45. com! W w
  46. com! Q q
  47. let mapleader="\<space>"
  48. " Wrapped lines treated like normal ones
  49. nnoremap j gj
  50. nnoremap k gk
  51. nnoremap <leader>S :call ToggleSpellCheck()<cr>
  52. function! ToggleSpellCheck()
  53. if &spell ==# "nospell"
  54. set spell
  55. else
  56. set nospell
  57. endif
  58. endfunction
  59. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  60. command! -nargs=0 Save if &modified | confirm write | endif
  61. nnoremap <silent> <C-s> :Save<CR>
  62. inoremap <C-s> <C-o>:Save<CR>
  63. vnoremap <C-s> <C-o>:Save<CR>
  64. " CTRL+w to close the current buffer
  65. nnoremap <silent> <C-w> :Sayonara<CR>
  66. nnoremap <silent> <S-w> :hide<CR>
  67. " Buffer magic
  68. nnoremap <leader>l :ls<CR>:b<space>
  69. nnoremap <leader>; :tabs<CR>:tabn<space>
  70. " Switch indentation settings
  71. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  72. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  73. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  74. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  75. " To wrap or not to wrap
  76. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  77. " Window Switching and Resizing
  78. nnoremap <silent> <C-k> :wincmd k<CR>
  79. nnoremap <silent> <C-j> :wincmd j<CR>
  80. nnoremap <silent> <C-h> :wincmd h<CR>
  81. nnoremap <silent> <C-l> :wincmd l<CR>
  82. nnoremap <silent> <D-K> :wincmd K<CR>
  83. nnoremap <silent> <D-J> :wincmd J<CR>
  84. nnoremap <silent> <D-H> :wincmd H<CR>
  85. nnoremap <silent> <D-L> :wincmd L<CR>
  86. nnoremap <silent> <D-T> :wincmd T<CR>
  87. nnoremap <silent> + :wincmd +<CR>
  88. nnoremap <silent> _ :wincmd -<CR>
  89. nnoremap <silent> ) :wincmd ><CR>
  90. nnoremap <silent> ( :wincmd <<CR>
  91. nnoremap <silent> <leader>r :wincmd r<CR>
  92. nnoremap <silent> <leader>R :wincmd R<CR>
  93. " Navigate tag stack
  94. nmap <D-]> <C-]>
  95. nmap <D-[> <C-T>
  96. " ALt+d to duplicate a line, vmode version is best for SHIFT+V, not the others
  97. nmap Y y$
  98. nnoremap <D-d> yyp
  99. vnoremap <D-d> y<C-o>p
  100. inoremap <D-d> <C-o>:yank<CR><C-o>:put<CR>
  101. " Open new files in new buffer or new windows
  102. nnoremap <C-p> :sp<space>
  103. nnoremap <D-p> :vs<space>
  104. " Move lines of text via Cmd+[jk]
  105. nnoremap <silent> <D-j> :m+1<CR>==
  106. nnoremap <silent> <D-k> :m-2<CR>==
  107. vnoremap <silent> <D-j> :m '>+1<CR>gv=gv
  108. vnoremap <silent> <D-k> :m '<-2<CR>gv=gv
  109. " Move text left/right via alt+[hl]
  110. nnoremap <silent> <D-l> "mx"mp
  111. nnoremap <silent> <D-h> "mxhh"mp
  112. " TODO: Maintain selection
  113. vnoremap <silent> <D-l> "mx"mp
  114. vnoremap <silent> <D-h> "mxhh"mp
  115. " Clear searches so there aren't underlined words.
  116. nnoremap <silent> <C-i> :nohlsearch<CR>
  117. " Formatting
  118. nmap <silent> =j :FormatJSON<CR>
  119. nmap <silent> =x :FormatXML<CR>
  120. nmap <silent> =, :s/$/,/<CR><C-i>
  121. " Set specific directories for swap, undo, and backups.
  122. set backupdir=~/.vim/tmp/backup//
  123. set directory=~/.vim/tmp/swap//
  124. set undodir=~/.vim/tmp/undo//
  125. set viewdir=~/.vim/tmp/view//
  126. set undofile
  127. macmenu File.Print key=<nop>
  128. map <S-k> <nop>
  129. map <S-q> <nop>
  130. """"""""""""""""""""""""""""
  131. " vim-rspec
  132. """"""""""""""""""""""""""""
  133. map <silent> <leader>t :call RunCurrentSpecFile()<CR>
  134. map <silent> <leader>a :call RunAllSpecs()<CR>
  135. map <silent> <leader>s :call RunNearestSpec()<CR>
  136. map <silent> <leader>k :call RunLastSpec()<CR>
  137. let g:rspec_command = "if command -v rspec >/dev/null 2>&1; then rspec {spec}; else bundle exec spec {spec}; fi"
  138. """"""""""""""""""""""""""""
  139. " Ctrl-P Settings
  140. """"""""""""""""""""""""""""
  141. " Keybinding and functionality
  142. let g:ctrlp_map = "<leader>o"
  143. " Move Ctrl-P to top of the screen
  144. let g:ctrlp_match_window_bottom = 0
  145. let g:ctrlp_match_window_reversed = 0
  146. " Ignore some filetypes
  147. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  148. "let g:ctrlp_by_filename = 1
  149. let g:ctrlp_clear_cache_on_exit = 0
  150. " Uncomment to show hidden directories.
  151. "let g:ctrlp_show_hidden = 1
  152. """"""""""""""""""""""""""""
  153. " Airline (Powerline replacement)
  154. """"""""""""""""""""""""""""
  155. let g:airline_theme = 'powerlineish'
  156. let g:airline_powerline_fonts = 1
  157. """"""""""""""""""""""""""""
  158. " NerdTree
  159. """"""""""""""""""""""""""""
  160. " Directory tree toggle
  161. nnoremap <leader>e :NERDTreeToggle<CR>
  162. """"""""""""""""""""""""""""
  163. " NerdCommenter
  164. """"""""""""""""""""""""""""
  165. map <leader>cc <plug>NERDCommenterToggle
  166. " For some reason, CommentToggle doesn't work unless this is
  167. " remapped, so remapping it to something I won't ever use.
  168. map <leader><D-/><space> <plug>NERDCommenterComment
  169. """"""""""""""""""""""""""""""""""""""""
  170. " UltiSnips
  171. """"""""""""""""""""""""""""""""""""""""
  172. let g:UltiSnipsExpandTrigger = "<D-C>"
  173. let g:UltiSnipsJumpForwardTrigger = "<D-W>"
  174. let g:UltiSnipsJumpBackwardTrigger = "<D-S>"
  175. """"""""""""""""""""""""""""
  176. " TeX Settings
  177. """"""""""""""""""""""""""""
  178. let g:tex_flavor = "latex"
  179. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  180. """"""""""""""""""""""""""""
  181. " Rails.vim
  182. """"""""""""""""""""""""""""
  183. let g:rails_gem_projections = {
  184. \ "fabrication": {
  185. \ "spec/fabricators/*_fabricator.rb": {
  186. \ "command": "fabricator",
  187. \ "affinity": "model",
  188. \ "alternate": "app/models/%s.rb",
  189. \ "related": "db/schema.rb#%p",
  190. \ "test": "spec/models/%s_spec.rb",
  191. \ "template": "Fabricator :%s do\nend",
  192. \ "keywords": "Fabricate Fabricator sequence"
  193. \ }
  194. \ },
  195. \ "factory_girl_rails": {
  196. \ "spec/factories/*_factory.rb": {
  197. \ "command": "factory",
  198. \ "affinity": "collection",
  199. \ "alternate": "app/models/%i.rb",
  200. \ "related": "db/schema.rb#%s",
  201. \ "test": "spec/models/%i_spec.rb",
  202. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  203. \ "keywords": "factory sequence"
  204. \ }
  205. \ },
  206. \ "factory_girl": {
  207. \ "spec/factories/*_factory.rb": {
  208. \ "command": "factory",
  209. \ "affinity": "collection",
  210. \ "alternate": "app/models/%i.rb",
  211. \ "related": "db/schema.rb#%s",
  212. \ "test": "spec/models/%i_spec.rb",
  213. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  214. \ "keywords": "factory sequence"
  215. \ }
  216. \ },
  217. \ "jasmine": {
  218. \ "spec/javascripts/*_spec.coffee": {
  219. \ "command": "rice",
  220. \ "template": "describe %S, ->\n ",
  221. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  222. \ },
  223. \ "spec/javascripts/*_spec.js": {
  224. \ "command": "rice",
  225. \ "template": "describe(%S, function() {\n \n})",
  226. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  227. \ }
  228. \ },
  229. \ "interactor-rails": {
  230. \ "app/interactors/*.rb": {
  231. \ "command": "interactor",
  232. \ "template": "class %S\n\nend"
  233. \ },
  234. \ },
  235. \ "cucumber-rails": {
  236. \ "features/*.feature": {
  237. \ "command": "feature",
  238. \ "template": "Feature: %h\n\n Scenario: " ,
  239. \ },
  240. \ "features/step_definitions/*_steps.rb": {
  241. \ "command": "steps",
  242. \ "affinity": "collection"
  243. \ }
  244. \ },
  245. \ "draper": {
  246. \ "app/decorators/*_decorator.rb": {
  247. \ "command": "decorator",
  248. \ "affinity": "model",
  249. \ "alternate": "app/models/%s.rb",
  250. \ "related": "db/schema.rb#%p",
  251. \ "test": "spec/decorators/%s_decorator_spec.rb",
  252. \ "template": "class %SDecorator < Draper::Decorator\n\nend",
  253. \ "keywords": "delegate_all"
  254. \ }
  255. \ }
  256. \ }
  257. let g:rails_projections = {
  258. \ "app/services/*.rb": {"command": "service"}
  259. \ }
  260. """"""""""""""""""""""""""""
  261. " delimitMate
  262. """"""""""""""""""""""""""""
  263. let g:delimitMate_expand_space = 1
  264. let g:delimitMate_expand_cr = 1
  265. """"""""""""""""""""""""""""
  266. " YCM Settings
  267. """"""""""""""""""""""""""""
  268. let g:ycm_register_as_syntastic_checker = 0
  269. let g:ycm_autoclose_preview_window_after_completion = 1
  270. let g:ycm_server_log_level = 'error'
  271. """"""""""""""""""""""""""""
  272. " Colors and Themes
  273. """"""""""""""""""""""""""""
  274. syntax enable
  275. "Set 256 color mode (not always needed).
  276. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  277. set t_Co=256
  278. endif
  279. " Use a nice color scheme
  280. colors monokai
  281. " but override matchparen color
  282. hi MatchParen ctermfg=160 ctermbg=NONE cterm=underline guifg=#df0000 guibg=NONE gui=underline
  283. """"""""""""""""""""""""""""""""""""""""
  284. " Useful Stuff
  285. """"""""""""""""""""""""""""""""""""""""
  286. " Delete trailing whitespaces on saving.
  287. function! DeleteTrailingWS()
  288. if !exists('b:noStrip')
  289. exe "normal mz"
  290. %s/\s\+$//ge
  291. exe "normal `z"
  292. endif
  293. endfunction
  294. au BufWrite * :call DeleteTrailingWS()
  295. au FileType go let b:noStrip=1
  296. " Allow the use of ALT as a function key.
  297. let c='a'
  298. while c <= 'z'
  299. exec "set <A-".c.">=\e".c
  300. exec "imap \e".c." <A-".c.">"
  301. let c = nr2char(1+char2nr(c))
  302. endw
  303. " Smart indent when entering insert mode with i on empty lines
  304. function! IndentWithI()
  305. if len(getline('.')) == 0
  306. return "\"_cc"
  307. else
  308. return "i"
  309. endif
  310. endfunction
  311. nnoremap <expr> i IndentWithI()
  312. " Smart indent when entering insert mode with i on empty lines
  313. function! IndentWithI()
  314. if len(getline('.')) == 0
  315. return "\"_cc"
  316. else
  317. return "i"
  318. endif
  319. endfunction
  320. nnoremap <expr> i IndentWithI()
  321. " For auto-aligning '|' delimited tables
  322. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  323. function! s:align()
  324. let p = '^\s*|\s.*\s|\s*$'
  325. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  326. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  327. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  328. Tabularize/|/l1
  329. normal! 0
  330. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  331. endif
  332. endfunction
  333. " Set tabline at the top
  334. function! Tabline()
  335. let s = ''
  336. for i in range(tabpagenr('$'))
  337. let tab = i + 1
  338. let bufnr = tabpagebuflist(tab)[tabpagewinnr(tab) - 1]
  339. let bufname = bufname(bufnr)
  340. let bufmodified = getbufvar(bufnr, "&mod")
  341. let s .= '%' . tab . 'T'
  342. let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  343. let s .= ' ' . tab . (bufmodified ? '+' : '') . ': '
  344. let s .= (bufname != '' ? fnamemodify(bufname, ':t') . ' ' : '--- ')
  345. endfor
  346. let s .= '%#TabLineFill#'
  347. return s
  348. endfunction
  349. set tabline=%!Tabline()
  350. " Go settings
  351. au BufRead,BufNewFile *.go set filetype=go
  352. au BufWritePre *.go :GoImports
  353. au FileType go map <buffer> <silent> <leader>t :GoTest<CR>
  354. let g:go_highlight_functions = 1
  355. let g:go_highlight_methods = 1
  356. let g:go_highlight_fields = 1
  357. let g:go_highlight_types = 1
  358. let g:go_highlight_operators = 0
  359. let g:go_highlight_extra_types = 1
  360. let g:go_highlight_format_strings = 1
  361. let g:go_highlight_generate_tags = 1
  362. let g:go_fmt_autosave = 0 " Let syntastic do this
  363. let g:go_fmt_experimental = 1 " Maintain folds after GoFmt + write
  364. let g:syntastic_go_checkers = ['gofmt']
  365. set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
  366. au BufRead,BufNewFile *.go map <leader>d :GoDeclsDir<cr>
  367. " JSON things
  368. let g:vim_json_syntax_conceal = 1
  369. com! FormatJSON %!python -m json.tool
  370. com! FormatXML %!xmllint --format -
  371. " Operator highlighting
  372. let g:ophigh_highlight_link_group = "Operator"
  373. let g:ophigh_container_color = "208"
  374. let g:ophigh_container_color_gui = "#fd971f"
  375. " Filetypes
  376. au BufRead,BufNewFile *.Dockerfile set filetype=dockerfile
  377. au BufRead,BufNewFile *.xsd set filetype=xml
  378. au BufRead,BufNewFile *.wsdl set filetype=xml
  379. map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
  380. \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
  381. \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
  382. let g:rustfmt_autosave = 1
  383. let g:ycm_rust_src_path = '/usr/src/rust/src'