vimrc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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 splitright " New window split settings
  37. set splitbelow " New window split settings
  38. set viminfo^=% " Remember buffer info on close
  39. set completeopt=menu
  40. set maxmempattern=8171906 " Because some files are big
  41. """"""""""""""""""""""""""""
  42. " Keybinds
  43. """"""""""""""""""""""""""""
  44. let mapleader="\<space>"
  45. " Wrapped lines treated like normal ones
  46. nnoremap j gj
  47. nnoremap k gk
  48. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  49. command! -nargs=0 Save if &modified | confirm write | endif
  50. nnoremap <silent> <C-s> :Save<CR>
  51. inoremap <C-s> <C-o>:Save<CR>
  52. vnoremap <C-s> <C-o>:Save<CR>
  53. " CTRL+w to close the current buffer
  54. nnoremap <silent> <C-w> :Sayonara<CR>
  55. nnoremap <silent> <S-w> :hide<CR>
  56. " Buffer magic
  57. nnoremap <leader>l :ls<CR>:b<space>
  58. nnoremap <leader>; :tabs<CR>:tabn<space>
  59. " Switch indentation settings
  60. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  61. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  62. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  63. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  64. " To wrap or not to wrap
  65. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  66. " Window Switching and Resizing
  67. nnoremap <silent> <C-k> :wincmd k<CR>
  68. nnoremap <silent> <C-j> :wincmd j<CR>
  69. nnoremap <silent> <C-h> :wincmd h<CR>
  70. nnoremap <silent> <C-l> :wincmd l<CR>
  71. if has("nvim")
  72. nnoremap <silent> <A-K> :wincmd K<CR>
  73. nnoremap <silent> <A-J> :wincmd J<CR>
  74. nnoremap <silent> <A-H> :wincmd H<CR>
  75. nnoremap <silent> <A-L> :wincmd L<CR>
  76. nnoremap <silent> <A-T> :wincmd T<CR>
  77. else
  78. nnoremap <silent> K :wincmd K<CR>
  79. nnoremap <silent> J :wincmd J<CR>
  80. nnoremap <silent> H :wincmd H<CR>
  81. nnoremap <silent> L :wincmd L<CR>
  82. nnoremap <silent> T :wincmd T<CR>
  83. endif
  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. nmap Y y$
  92. nnoremap <A-d> yyp
  93. vnoremap <A-d> y<C-o>p
  94. inoremap <A-d> <C-o>:yank<CR><C-o>:put<CR>
  95. " Open new files in new buffer or new windows
  96. nnoremap <C-p> :sp<space>
  97. nnoremap <A-p> :vs<space>
  98. " Move lines of text via alt+[jk]
  99. nnoremap <silent> <A-j> :m+1<CR>==
  100. nnoremap <silent> <A-k> :m-2<CR>==
  101. vnoremap <silent> <A-j> :m '>+1<CR>gv=gv
  102. vnoremap <silent> <A-k> :m '<-2<CR>gv=gv
  103. " Clear searches so there aren't underlined words.
  104. nnoremap <silent> <C-i> :nohlsearch<CR>
  105. " JSON formatting
  106. nmap <silent> =j :FormatJSON<CR>
  107. " Set specific directories for swap, undo, and backups.
  108. set backupdir=~/.vim/tmp/backup//
  109. set directory=~/.vim/tmp/swap//
  110. set undodir=~/.vim/tmp/undo//
  111. set viewdir=~/.vim/tmp/view//
  112. set undofile
  113. map <S-k> <nop>
  114. map <S-q> <nop>
  115. """"""""""""""""""""""""""""
  116. " vim-rspec
  117. """"""""""""""""""""""""""""
  118. map <silent> <leader>t :call RunCurrentSpecFile()<CR>
  119. map <silent> <leader>a :call RunAllSpecs()<CR>
  120. map <silent> <leader>s :call RunNearestSpec()<CR>
  121. map <silent> <leader>k :call RunLastSpec()<CR>
  122. let g:rspec_command = "!if command -v rspec >/dev/null 2>&1; then rspec {spec}; else; bundle exec spec {spec}; fi"
  123. """"""""""""""""""""""""""""
  124. " Ctrl-P Settings
  125. """"""""""""""""""""""""""""
  126. " Keybinding and functionality
  127. let g:ctrlp_map = "<leader>o"
  128. let g:ctrlp_cmd = 'CtrlPLastMode'
  129. let g:ctrlp_extensions = ['line']
  130. " Move Ctrl-P to top of the screen
  131. let g:ctrlp_match_window_bottom = 0
  132. let g:ctrlp_match_window_reversed = 0
  133. " Ignore some filetypes
  134. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  135. let g:ctrlp_switch_buffer = 'E'
  136. "let g:ctrlp_by_filename = 1
  137. let g:ctrlp_clear_cache_on_exit = 0
  138. " Uncomment to show hidden directories.
  139. "let g:ctrlp_show_hidden = 1
  140. """"""""""""""""""""""""""""
  141. " Airline (Powerline replacement)
  142. """"""""""""""""""""""""""""
  143. let g:airline_theme = 'powerlineish'
  144. let g:airline_powerline_fonts = 1
  145. """"""""""""""""""""""""""""
  146. " NerdTree
  147. """"""""""""""""""""""""""""
  148. " Directory tree toggle
  149. nnoremap <leader>e :NERDTreeToggle<CR>
  150. """"""""""""""""""""""""""""
  151. " NerdCommenter
  152. """"""""""""""""""""""""""""
  153. map <leader>cc <plug>NERDCommenterToggle
  154. " For some reason, CommentToggle doesn't work unless this is
  155. " remapped, so remapping it to something I won't ever use.
  156. map <leader><A-/><space> <plug>NERDCommenterComment
  157. """"""""""""""""""""""""""""
  158. " Easytags
  159. """"""""""""""""""""""""""""
  160. set regexpengine=1
  161. let g:easytags_updatetime_min = 4000
  162. """"""""""""""""""""""""""""
  163. " Tex Settings
  164. """"""""""""""""""""""""""""
  165. let g:tex_flavor = "latex"
  166. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  167. au FileType tex setlocal spell spelllang=en_us
  168. """"""""""""""""""""""""""""
  169. " Rails.vim
  170. """"""""""""""""""""""""""""
  171. let g:rails_gem_projections = {
  172. \ "fabrication": {
  173. \ "spec/fabricators/*_fabricator.rb": {
  174. \ "command": "fabricator",
  175. \ "affinity": "model",
  176. \ "alternate": "app/models/%s.rb",
  177. \ "related": "db/schema.rb#%p",
  178. \ "test": "spec/models/%s_spec.rb",
  179. \ "template": "Fabricator :%s do\nend",
  180. \ "keywords": "Fabricate Fabricator sequence"
  181. \ }
  182. \ },
  183. \ "factory_girl_rails": {
  184. \ "spec/factories/*_factory.rb": {
  185. \ "command": "factory",
  186. \ "affinity": "collection",
  187. \ "alternate": "app/models/%i.rb",
  188. \ "related": "db/schema.rb#%s",
  189. \ "test": "spec/models/%i_spec.rb",
  190. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  191. \ "keywords": "factory sequence"
  192. \ }
  193. \ },
  194. \ "factory_girl": {
  195. \ "spec/factories/*_factory.rb": {
  196. \ "command": "factory",
  197. \ "affinity": "collection",
  198. \ "alternate": "app/models/%i.rb",
  199. \ "related": "db/schema.rb#%s",
  200. \ "test": "spec/models/%i_spec.rb",
  201. \ "template": "FactoryGirl.define do\n factory :%i do\n end\nend",
  202. \ "keywords": "factory sequence"
  203. \ }
  204. \ },
  205. \ "jasmine": {
  206. \ "spec/javascripts/*_spec.coffee": {
  207. \ "command": "rice",
  208. \ "template": "describe %S, ->\n ",
  209. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  210. \ },
  211. \ "spec/javascripts/*_spec.js": {
  212. \ "command": "rice",
  213. \ "template": "describe(%S, function() {\n \n})",
  214. \ "keywords": "describe it beforeEach expect loadFixtures xit"
  215. \ }
  216. \ },
  217. \ "interactor-rails": {
  218. \ "app/interactors/*.rb": {
  219. \ "command": "interactor",
  220. \ "template": "class %S\n\nend"
  221. \ },
  222. \ },
  223. \ "cucumber-rails": {
  224. \ "features/*.feature": {
  225. \ "command": "feature",
  226. \ "template": "Feature: %h\n\n Scenario: " ,
  227. \ },
  228. \ "features/step_definitions/*_steps.rb": {
  229. \ "command": "steps",
  230. \ "affinity": "collection"
  231. \ }
  232. \ },
  233. \ "draper": {
  234. \ "app/decorators/*_decorator.rb": {
  235. \ "command": "decorator",
  236. \ "affinity": "model",
  237. \ "alternate": "app/models/%s.rb",
  238. \ "related": "db/schema.rb#%p",
  239. \ "test": "spec/decorators/%s_decorator_spec.rb",
  240. \ "template": "class %SDecorator < Draper::Decorator\n\nend",
  241. \ "keywords": "delegate_all"
  242. \ }
  243. \ }
  244. \ }
  245. let g:rails_projections = {
  246. \ "app/services/*.rb": {"command": "service"}
  247. \ }
  248. """"""""""""""""""""""""""""
  249. " delimitMate
  250. """"""""""""""""""""""""""""
  251. let g:delimitMate_expand_space = 1
  252. let g:delimitMate_expand_cr = 1
  253. """"""""""""""""""""""""""""
  254. " YCM Settings
  255. """"""""""""""""""""""""""""
  256. let g:ycm_register_as_syntastic_checker = 0
  257. let g:ycm_autoclose_preview_window_after_completion = 1
  258. let g:ycm_server_log_level = 'error'
  259. """"""""""""""""""""""""""""
  260. " Colors and Themes
  261. """"""""""""""""""""""""""""
  262. syntax enable
  263. "Set 256 color mode (not always needed).
  264. if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "xfce4-terminal"
  265. set t_Co=256
  266. endif
  267. " Use a nice color scheme
  268. colors monokai
  269. """"""""""""""""""""""""""""""""""""""""
  270. " Useful Stuff
  271. """"""""""""""""""""""""""""""""""""""""
  272. " Delete trailing whitespaces on saving.
  273. function! DeleteTrailingWS()
  274. if !exists('b:noStrip')
  275. exe "normal mz"
  276. %s/\s\+$//ge
  277. exe "normal `z"
  278. endif
  279. endfunction
  280. au BufWrite * :call DeleteTrailingWS()
  281. au FileType go let b:noStrip=1
  282. if !has("nvim")
  283. " Allow the use of ALT as a function key.
  284. let c='a'
  285. while c <= 'z'
  286. exec "set <A-".c.">=\e".c
  287. exec "imap \e".c." <A-".c.">"
  288. let c = nr2char(1+char2nr(c))
  289. endw
  290. endif
  291. " For auto-aligning '|' delimited tables
  292. inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
  293. function! s:align()
  294. let p = '^\s*|\s.*\s|\s*$'
  295. if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
  296. let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
  297. let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
  298. Tabularize/|/l1
  299. normal! 0
  300. call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  301. endif
  302. endfunction
  303. " Set tabline at the top
  304. function! Tabline()
  305. let s = ''
  306. for i in range(tabpagenr('$'))
  307. let tab = i + 1
  308. let bufnr = tabpagebuflist(tab)[tabpagewinnr(tab) - 1]
  309. let bufname = bufname(bufnr)
  310. let bufmodified = getbufvar(bufnr, "&mod")
  311. let s .= '%' . tab . 'T'
  312. let s .= (tab == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#')
  313. let s .= ' ' . tab . (bufmodified ? '+' : '') . ': '
  314. let s .= (bufname != '' ? fnamemodify(bufname, ':t') . ' ' : '--- ')
  315. endfor
  316. let s .= '%#TabLineFill#'
  317. return s
  318. endfunction
  319. set tabline=%!Tabline()
  320. " Go settings
  321. au BufRead,BufNewFile *.go set filetype=go
  322. au BufWrite *.go :GoImports
  323. au FileType go map <buffer> <silent> <leader>t :GoTest<CR>
  324. let g:go_highlight_functions = 1
  325. let g:go_highlight_methods = 1
  326. let g:go_highlight_fields = 1
  327. let g:go_highlight_types = 1
  328. let g:go_highlight_operators = 0
  329. let g:go_highlight_extra_types = 1
  330. let g:go_highlight_format_strings = 1
  331. let g:go_highlight_generate_tags = 1
  332. let g:syntastic_go_checkers = ['go', 'gofmt', 'golint', 'govet', 'errcheck']
  333. set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
  334. " JSON things
  335. let g:vim_json_syntax_conceal = 1
  336. com! FormatJSON %!python -m json.tool
  337. " Operator highlighting
  338. let g:ophigh_highlight_link_group = "Operator"
  339. " Filetypes
  340. au BufRead,BufNewFile *.Dockerfile set filetype=dockerfile
  341. au BufRead,BufNewFile *.xsd set filetype=xml
  342. au BufRead,BufNewFile *.wsdl set filetype=xml