vimrc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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 mouse=a
  31. set number " Line numbers
  32. set nowrap " Line Wrapping
  33. set hidden " Just hide buffer when :bd'ing
  34. set autoread " Automatically update externally updated files
  35. set cc=80 " Which line is the 80th column?
  36. set tw=80 " Text width line wrapping
  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. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  52. command! -nargs=0 Save if &modified | confirm write | endif
  53. nnoremap <silent> <C-s> :Save<CR>
  54. inoremap <C-s> <C-o>:Save<CR>
  55. vnoremap <C-s> <C-o>:Save<CR>
  56. " CTRL+w to close the current buffer
  57. nnoremap <silent> <C-w> :Sayonara<CR>
  58. nnoremap <silent> <S-w> :hide<CR>
  59. " Buffer magic
  60. nnoremap <leader>l :ls<CR>:b<space>
  61. nnoremap <leader>; :tabs<CR>:tabn<space>
  62. " Switch indentation settings
  63. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  64. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  65. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  66. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  67. " To wrap or not to wrap
  68. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  69. " Window Switching and Resizing
  70. nnoremap <silent> <C-k> :wincmd k<CR>
  71. nnoremap <silent> <C-j> :wincmd j<CR>
  72. nnoremap <silent> <C-h> :wincmd h<CR>
  73. nnoremap <silent> <C-l> :wincmd l<CR>
  74. if has("nvim")
  75. nnoremap <silent> <A-K> :wincmd K<CR>
  76. nnoremap <silent> <A-J> :wincmd J<CR>
  77. nnoremap <silent> <A-H> :wincmd H<CR>
  78. nnoremap <silent> <A-L> :wincmd L<CR>
  79. nnoremap <silent> <A-T> :wincmd T<CR>
  80. else
  81. nnoremap <silent> K :wincmd K<CR>
  82. nnoremap <silent> J :wincmd J<CR>
  83. nnoremap <silent> H :wincmd H<CR>
  84. nnoremap <silent> L :wincmd L<CR>
  85. nnoremap <silent> T :wincmd T<CR>
  86. endif
  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 <A-]> <C-]>
  95. nmap <A-[> <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 <A-d> "yyy"yp
  99. vnoremap <A-d> "yy<C-o>"yp
  100. inoremap <A-d> <C-o>:yank<CR><C-o>:put<CR>
  101. " Yank/put to clipboard
  102. nnoremap <A-p> "+p
  103. vnoremap <A-p> "+p
  104. nnoremap <expr> <silent> <A-y> '"+' . (v:count ? v:count : '') . 'y'
  105. vnoremap <A-y> "+y
  106. " Move lines of text via alt+[jk]
  107. nnoremap <silent> <A-j> :m+1<CR>==
  108. nnoremap <silent> <A-k> :m-2<CR>==
  109. vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
  110. vnoremap <silent> <A-k> :m '<-2<CR>gv=gv
  111. " Move text left/right via alt+[hl]
  112. nnoremap <silent> <A-l> "mx"mp
  113. nnoremap <silent> <A-h> "mxhh"mp
  114. " TODO: Maintain selection
  115. vnoremap <silent> <A-l> "mx"mp
  116. vnoremap <silent> <A-h> "mxhh"mp
  117. " Clear searches so there aren't underlined words.
  118. nnoremap <silent> <C-i> :nohlsearch<CR>
  119. " Formatting
  120. nmap <silent> =j :FormatJSON<CR>
  121. nmap <silent> =x :FormatXML<CR>
  122. " Set specific directories for swap, undo, and backups.
  123. set backupdir=~/.vim/tmp/backup//
  124. set directory=~/.vim/tmp/swap//
  125. set undodir=~/.vim/tmp/undo//
  126. set viewdir=~/.vim/tmp/view//
  127. set undofile
  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. let g:ctrlp_cmd = 'CtrlPLastMode'
  144. let g:ctrlp_extensions = ['line']
  145. " Move Ctrl-P to top of the screen
  146. let g:ctrlp_match_window_bottom = 0
  147. let g:ctrlp_match_window_reversed = 0
  148. " Ignore some filetypes
  149. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  150. let g:ctrlp_switch_buffer = 'E'
  151. "let g:ctrlp_by_filename = 1
  152. let g:ctrlp_clear_cache_on_exit = 0
  153. " Uncomment to show hidden directories.
  154. "let g:ctrlp_show_hidden = 1
  155. """"""""""""""""""""""""""""
  156. " Airline (Powerline replacement)
  157. """"""""""""""""""""""""""""
  158. let g:airline_theme = 'powerlineish'
  159. let g:airline_powerline_fonts = 1
  160. """"""""""""""""""""""""""""
  161. " NerdTree
  162. """"""""""""""""""""""""""""
  163. " Directory tree toggle
  164. nnoremap <leader>e :NERDTreeToggle<CR>
  165. """"""""""""""""""""""""""""
  166. " NerdCommenter
  167. """"""""""""""""""""""""""""
  168. map <leader>cc <plug>NERDCommenterToggle
  169. " For some reason, CommentToggle doesn't work unless this is
  170. " remapped, so remapping it to something I won't ever use.
  171. map <leader><A-/><space> <plug>NERDCommenterComment
  172. """"""""""""""""""""""""""""
  173. " Easytags
  174. """"""""""""""""""""""""""""
  175. set regexpengine=1
  176. let g:easytags_updatetime_min = 4000
  177. let g:easytags_cmd = '/usr/bin/ctags'
  178. """"""""""""""""""""""""""""
  179. " Tex Settings
  180. """"""""""""""""""""""""""""
  181. let g:tex_flavor = "latex"
  182. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  183. au FileType tex setlocal spell spelllang=en_us
  184. """"""""""""""""""""""""""""
  185. " Rails.vim
  186. """"""""""""""""""""""""""""
  187. let g:rails_gem_projections = {
  188. \ "fabrication": {
  189. \ "spec/fabricators/*_fabricator.rb": {
  190. \ "command": "fabricator",
  191. \ "affinity": "model",
  192. \ "alternate": "app/models/%s.rb",
  193. \ "related": "db/schema.rb#%p",
  194. \ "test": "spec/models/%s_spec.rb",
  195. \ "template": "Fabricator :%s do\nend",
  196. \ "keywords": "Fabricate Fabricator sequence"
  197. \ }
  198. \ },
  199. \ "factory_girl_rails": {
  200. \ "spec/factories/*_factory.rb": {
  201. \ "command": "factory",
  202. \ "affinity": "collection",
  203. \ "alternate": "app/models/%i.rb",
  204. \ "related": "db/schema.rb#%s",
  205. \ "test": "spec/models/%i_spec.rb",
  206. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  207. \ "keywords": "factory sequence"
  208. \ }
  209. \ },
  210. \ "factory_girl": {
  211. \ "spec/factories/*_factory.rb": {
  212. \ "command": "factory",
  213. \ "affinity": "collection",
  214. \ "alternate": "app/models/%i.rb",
  215. \ "related": "db/schema.rb#%s",
  216. \ "test": "spec/models/%i_spec.rb",
  217. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  218. \ "keywords": "factory sequence"
  219. \ }
  220. \ },
  221. \ "jasmine": {
  222. \ "spec/javascripts/*_spec.coffee": {
  223. \ "command": "rice",
  224. \ "template": "describe %S, ->\n ",
  225. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  226. \ },
  227. \ "spec/javascripts/*_spec.js": {
  228. \ "command": "rice",
  229. \ "template": "describe(%S, function() {\n \n})",
  230. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  231. \ }
  232. \ },
  233. \ "interactor-rails": {
  234. \ "app/interactors/*.rb": {
  235. \ "command": "interactor",
  236. \ "template": "class %S\n\nend"
  237. \ },
  238. \ },
  239. \ "cucumber-rails": {
  240. \ "features/*.feature": {
  241. \ "command": "feature",
  242. \ "template": "Feature: %h\n\n Scenario: " ,
  243. \ },
  244. \ "features/step_definitions/*_steps.rb": {
  245. \ "command": "steps",
  246. \ "affinity": "collection"
  247. \ }
  248. \ },
  249. \ "draper": {
  250. \ "app/decorators/*_decorator.rb": {
  251. \ "command": "decorator",
  252. \ "affinity": "model",
  253. \ "alternate": "app/models/%s.rb",
  254. \ "related": "db/schema.rb#%p",
  255. \ "test": "spec/decorators/%s_decorator_spec.rb",
  256. \ "template": "class %SDecorator < Draper::Decorator\n\nend",
  257. \ "keywords": "delegate_all"
  258. \ }
  259. \ }
  260. \ }
  261. let g:rails_projections = {
  262. \ "app/services/*.rb": {"command": "service"}
  263. \ }
  264. """"""""""""""""""""""""""""
  265. " delimitMate
  266. """"""""""""""""""""""""""""
  267. let g:delimitMate_expand_space = 1
  268. let g:delimitMate_expand_cr = 1
  269. """"""""""""""""""""""""""""
  270. " YCM Settings
  271. """"""""""""""""""""""""""""
  272. let g:ycm_register_as_syntastic_checker = 0
  273. let g:ycm_autoclose_preview_window_after_completion = 1
  274. let g:ycm_server_log_level = 'error'
  275. """"""""""""""""""""""""""""
  276. " Colors and Themes
  277. """"""""""""""""""""""""""""
  278. syntax enable
  279. "Set 256 color mode (not always needed).
  280. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  281. set t_Co=256
  282. endif
  283. " Use a nice color scheme
  284. colors monokai
  285. " but override matchparen color
  286. hi MatchParen ctermfg=160 ctermbg=NONE cterm=underline guifg=#df0000 guibg=NONE gui=underline
  287. """"""""""""""""""""""""""""""""""""""""
  288. " Useful Stuff
  289. """"""""""""""""""""""""""""""""""""""""
  290. " Delete trailing whitespaces on saving.
  291. function! DeleteTrailingWS()
  292. if !exists('b:noStrip')
  293. exe "normal mz"
  294. %s/\s\+$//ge
  295. exe "normal `z"
  296. endif
  297. endfunction
  298. au BufWrite * :call DeleteTrailingWS()
  299. au FileType go let b:noStrip=1
  300. if !has("nvim")
  301. " Allow the use of ALT as a function key.
  302. let c='a'
  303. while c <= 'z'
  304. exec "set <A-".c.">=\e".c
  305. exec "imap \e".c." <A-".c.">"
  306. let c = nr2char(1+char2nr(c))
  307. endw
  308. endif
  309. " Smart indent when entering insert mode with i on empty lines
  310. function! IndentWithI()
  311. if len(getline('.')) == 0
  312. return "\"_cc"
  313. else
  314. return "i"
  315. endif
  316. endfunction
  317. nnoremap <expr> i IndentWithI()
  318. " For auto-aligning '|' delimited tables
  319. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  320. function! s:align()
  321. let p = '^\s*|\s.*\s|\s*$'
  322. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  323. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  324. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  325. Tabularize/|/l1
  326. normal! 0
  327. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  328. endif
  329. endfunction
  330. " Set tabline at the top
  331. function! Tabline()
  332. let s = ''
  333. for i in range(tabpagenr('$'))
  334. let tab = i + 1
  335. let bufnr = tabpagebuflist(tab)[tabpagewinnr(tab) - 1]
  336. let bufname = bufname(bufnr)
  337. let bufmodified = getbufvar(bufnr, "&mod")
  338. let s .= '%' . tab . 'T'
  339. let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  340. let s .= ' ' . tab . (bufmodified ? '+' : '') . ': '
  341. let s .= (bufname != '' ? fnamemodify(bufname, ':t') . ' ' : '--- ')
  342. endfor
  343. let s .= '%#TabLineFill#'
  344. return s
  345. endfunction
  346. set tabline=%!Tabline()
  347. " Go settings
  348. au BufRead,BufNewFile *.go set filetype=go
  349. au BufWritePre *.go :GoImports
  350. au FileType go map <buffer> <silent> <leader>t :GoTest<CR>
  351. let g:go_highlight_functions = 1
  352. let g:go_highlight_methods = 1
  353. let g:go_highlight_fields = 1
  354. let g:go_highlight_types = 1
  355. let g:go_highlight_operators = 0
  356. let g:go_highlight_extra_types = 1
  357. let g:go_highlight_format_strings = 1
  358. let g:go_highlight_generate_tags = 1
  359. let g:go_fmt_autosave = 0 " Let syntastic do this
  360. let g:syntastic_go_checkers = ['gofmt']
  361. let g:go_fmt_experimental = 1 " Maintain folds after GoFmt + write
  362. set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
  363. " JSON things
  364. let g:vim_json_syntax_conceal = 1
  365. com! FormatJSON %!python -m json.tool
  366. com! FormatXML %!xmllint --format -
  367. " Operator highlighting
  368. let g:ophigh_highlight_link_group = "Operator"
  369. let g:ophigh_container_color = "208"
  370. let g:ophigh_container_color_gui = "#fd971f"
  371. " Filetypes
  372. au BufRead,BufNewFile *.Dockerfile set filetype=dockerfile
  373. au BufRead,BufNewFile *.xsd set filetype=xml
  374. au BufRead,BufNewFile *.wsdl set filetype=xml
  375. map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
  376. \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
  377. \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
  378. let g:rustfmt_autosave = 1
  379. let g:ycm_rust_src_path = '/usr/src/rust/src'