-
Notifications
You must be signed in to change notification settings - Fork 5
/
.vimrc
496 lines (373 loc) · 16.9 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
" ---------------------------------------------------------------------------
" Pathogen initialization
" ---------------------------------------------------------------------------
filetype off
call pathogen#runtime_append_all_bundles() " using pathogen for a bunch of plugins
filetype plugin indent on " load filetype plugin
call pathogen#helptags()
" ---------------------------------------------------------------------------
" General
" ---------------------------------------------------------------------------
set nocompatible
let mapleader = ","
set history=1000 " lots of command line history
set viminfo='10,\"100,:20,%,n~/.viminfo " remember certain things when we exit
set autoread " reload files changed outside of Vim
set autowrite " some commands should cause an automatic write
set nrformats= " improves incrementing when there are leading 0's.
set cpo+=J " sentences are followed by 2 spaces.
set linebreak " wrapping preserves words.
" ----------------------------------------------------------------------------
" UI
" ----------------------------------------------------------------------------
set ruler " show the cursor position all the time
set backspace=start,indent,eol " allow backspacing over anything in insert mode
set wm=2 " wrap margin on the right
set scrolloff=2 " keep some context when scrolling
set nowrap " do not wrap lines
set antialias " of course
set synmaxcol=200 " limit syntax highlighting for long lines
" ----------------------------------------------------------------------------
" Visual cues
" ----------------------------------------------------------------------------
set laststatus=2 " always show the status line
set visualbell " quiet
set noerrorbells " quiet
set showcmd " show size of visual selection
set wildmenu " show possible matches for command completions using tab
set wildmode=list:longest,full " full list using common string. Then full complete.
" ----------------------------------------------------------------------------
" NerdTree config
" ----------------------------------------------------------------------------
let NERDTreeWinSize=31 " how wide nerdtree ought to be
let NERDTreeMinimalUI=1 " don't need to the noise
let NERDTreeDirArrows=1 " prettier arrows
" ----------------------------------------------------------------------------
" Tabs
" ----------------------------------------------------------------------------
set tabstop=4
set softtabstop=2 " yep, two
set shiftwidth=2
set nosmarttab " no tabs, thanks.
set autoindent " automatically indent new lines
set expandtab " expand tabs to spaces
" ----------------------------------------------------------------------------
" Backups
" ----------------------------------------------------------------------------
set nobackup " do not keep backups after close
set nowritebackup " do not keep a backup while working
set noswapfile " don't keep swp files either
set backupdir=~/.vim/backups " store backups under ~/.vim/backup
set backupcopy=yes " keep attributes of original file
set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set directory=~/.vim/tmp " where to keep swp files
" ----------------------------------------------------------------------------
" Searching
" ----------------------------------------------------------------------------
nnoremap / /\v
vnoremap / /\v
set ignorecase " make searches case insensitive
set smartcase " care about case sensitivity if there's a capital letter
set incsearch " do incremental searching
set nohlsearch " don't highlight searches
" ---------------------------------------------------------------------------
" Mappings
" ---------------------------------------------------------------------------
" show/hide nerdtree
nnoremap <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" highlight the current buffer in the nerdtree
nnoremap <leader>n :NERDTreeFind<CR>
" make it easy to move to adjacent files in the dir
nmap gj :NERDTreeFind<CR><C-j><Enter>
nmap gk :NERDTreeFind<CR><C-k><Enter>
" navigating search results
nnoremap <leader>1 :cprevious <CR>
nnoremap <leader>2 :cnext <CR>
" space is much easier to press than %
map <space> %
" clean up cucumber tables
nnoremap <leader>= :Tabularize /\|<CR>
" move between windows
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" speed up viewport scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
" resize windows
nmap <C-Left> <C-W><<C-W><
nmap <C-Right> <C-W>><C-W>>
nmap <C-Up> <C-W>+<C-W>+
nmap <C-Down> <C-W>-<C-W>-
" Emacs bindings in command line mode
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" add the dir of the current file to the command
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" command-t plugin
" silent! nmap <unique> <silent> <Leader>f :CommandT<CR>
" nnoremap <leader>F :CommandTFlush<CR>:CommandT<CR>
" ctrlp plugin
nnoremap <leader>f :CtrlP<CR>
nnoremap <leader>F :CtrlPClearCache<CR>:CtrlP<CR>
set wildignore+=vendor/plugins/**,vendor/ruby/**,vendor/gems/**,vendor/cache/**,vendor/rails/**,public/assets/**,vendor/assets/javascripts/**,coverage/**,tmp/**
" ack shortcuts
nnoremap <leader>A :Ack<cword><CR>
nnoremap <leader>a :Ack<space>
vmap <leader>A "ry:Ack<space>"<C-r>r"<CR>
" normal mode shortcuts
nmap <leader><Enter> [<space>
nnoremap <leader><space> i<space><Esc>
" Easier to get to the end of the line
noremap gl g_
" Easier to get to the first non-blank character of the line
noremap gh ^
" ctags shortcuts
nmap <C-\> <C-]>
nmap g<C-\> g]
" auto complete shortcut
imap <S-space> <C-n>
" switch it up with the switch plugin
nnoremap <S-space> :Switch<CR>
" hash syntax shortcut
inoremap <C-l> <space>=><space>
" allow multiple pastes of the same content when pasting in visual mode.
vnoremap p pgvy
" delete the line below/above the current cursor position
nnoremap do jddk^
nnoremap dO kdd^
" Shortcut to make splits
nnoremap <leader>s :sp<cr><C-w>j
nnoremap <leader>v :vsp<cr><C-w>l
" edit vimrc
nmap <leader>c :sp ~/.vimrc<CR><C-W>_
nmap <leader>C :source $MYVIMRC<CR>:source $MYGVIMRC<CR>:filetype detect<CR><leader>d<leader>d<C-L>:exe ":echo 'vimrc reloaded'"<CR>
" Shortcut to easily edit a mail message.
nnoremap <leader>e :sp /tmp/duff_mail.mail<CR><C-W>_
" Remove trailing whitespace
nnoremap <leader>h :FixWhitespace<cr>
" Save a few keystrokes
nnoremap <Leader>q :q<CR>
nnoremap <Leader>w :w<CR>
nnoremap <Leader>x :x<CR>
" I often use a Scratch buffer
nnoremap <leader>S :Scratch<CR>
" Visually select the text that was last edited/pasted
nmap gV `[v`]
" Bubble lines
nmap ˚ [e
nmap ∆ ]e
vmap ˚ [egv
vmap ∆ ]egv
" Easily replay the macro recorded in register q
nnoremap <Leader>m @q
" Hook up ctrl-i to navigate the jump list. I don't know why ctrl-i
" doesn't seem to work for me by default.
nmap <C-i> <C-tab>
" Better goto mark default
nnoremap ' `
nnoremap ` '
" switch between the last 2 files
nnoremap go <c-^>
" switch to a 1.9 hash
nnoremap <leader>y F:xea:<esc>llxxx
" some rails helpers
nnoremap <leader>k :Rake<CR>
nnoremap <leader>K :.Rake<CR>
map <silent> <C-N> :se invhlsearch<CR>
" start a :%s with the visual selection.
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
" ---------------------------------------------------------------------------
" primary rails navigation
" ---------------------------------------------------------------------------
nnoremap <leader><leader>m :CtrlP app/models<cr>
nnoremap <leader><leader>v :CtrlP app/views<cr>
nnoremap <leader><leader>c :CtrlP app/controllers<cr>
nnoremap <leader><leader>h :CtrlP app/helpers<cr>
nnoremap <leader><leader>l :CtrlP lib<cr>
nnoremap <leader><leader>f :CtrlP features<cr>
nnoremap <leader><leader>u :CtrlP test<cr>
nnoremap <leader><leader>r :CtrlP spec<cr>
nnoremap <leader><leader>o :CtrlP source<cr>
nnoremap <leader><leader>p :CtrlP app/presenters<cr>
nnoremap <leader><leader>j :CtrlP app/assets/javascripts<cr>
nnoremap <leader><leader>s :CtrlP app/assets/stylesheets<cr>
nnoremap <leader><leader>i :Einitializer<space>
nnoremap <leader><leader>e :Eenvironment<space>
nnoremap <leader><leader>t :Etask<space>
nnoremap <leader><leader>d :Emigration<space>
nnoremap <leader><leader>g :e Gemfile<cr>
" ---------------------------------------------------------------------------
" other navigation
" ---------------------------------------------------------------------------
" Command-T of the directory of the current file
" nmap <leader>gf :CommandT %%<cr>
" ---------------------------------------------------------------------------
" custom commands - use these at the : command prompt
" ---------------------------------------------------------------------------
" Forgot to `sudo vim`. This saves the file anyway.
command! SudoWrite w !sudo tee %
" Reload snipmate snippets
command! SnipmateReloadSnippets call ReloadAllSnippets()
command! MarkdownPreview call LivedownPreview()
" ---------------------------------------------------------------------------
" rails.vim autocommands
" ---------------------------------------------------------------------------
autocmd User Rails silent! Rnavcommand feature features -glob=**/* -suffix=.feature
autocmd User Rails silent! Rnavcommand stepdefinitions features/step_definitions -glob=**/* -suffix=_steps.rb
" ---------------------------------------------------------------------------
" Status line customization
" ---------------------------------------------------------------------------
set statusline=
set statusline+=%f\ " filename
set statusline+=%h%m%r%w " status flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}] " file type
set statusline+=%= " right align remainder
set statusline+=%-14(%l,%c%V%) " line, character
set statusline+=%<%P " file position
" ---------------------------------------------------------------------------
" CtrlP customization
" ---------------------------------------------------------------------------
let g:ctrlp_match_window = 'order:ttb,max:20'
let g:ctrlp_switch_buffer = 'E'
" let g:ctrlp_by_filename = 1
let g:ctrlp_prompt_mappings = {
\ 'PrtClearCache()': ['<c-c>'],
\ 'PrtExit()': ['<esc>', '<c-g>'],
\ }
" ---------------------------------------------------------------------------
" Command-t customization
" ---------------------------------------------------------------------------
" let g:CommandTMaxHeight=20
" ---------------------------------------------------------------------------
" Gundo customization
" ---------------------------------------------------------------------------
let g:gundo_right=1
" ---------------------------------------------------------------------------
" ctags-vim-johnson customization
" ---------------------------------------------------------------------------
let g:ctags_statusline=1
" ---------------------------------------------------------------------------
" GitHub-Comment customization
" ---------------------------------------------------------------------------
let g:github_comment_open_browser = 1
" ---------------------------------------------------------------------------
" Notes plugin customization
" ---------------------------------------------------------------------------
let g:notes_directories = ['~/Documents/Notes']
let g:notes_suffix = '.txt'
let g:notes_smart_quotes = 0
" ---------------------------------------------------------------------------
" Colors/Theme
" ---------------------------------------------------------------------------
syntax on
" ---------------------------------------------------------------------------
" Surround plugin - allow # to be used for string interpolation.
" ---------------------------------------------------------------------------
autocmd FileType ruby let g:surround_113 = "#{\r}" " v
autocmd FileType ruby let g:surround_35 = "#{\r}" " #
" ---------------------------------------------------------------------------
" persistent undo
" ---------------------------------------------------------------------------
if v:version >= 703 " Only available in Vim 7.3 or greater
set undofile
set undodir=~/.vim/.undo
endif
" ---------------------------------------------------------------------------
" Buffers
" ---------------------------------------------------------------------------
set hidden " Let me leave buffers even when they're changed.
" Write all named, changed buffers when Vim loses focus
au FocusLost * :wall
" ---------------------------------------------------------------------------
" omnicomplete
" ---------------------------------------------------------------------------
set ofu=syntaxcomplete#Complete
autocmd FileType ruby set omnifunc=rubycomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
" ---------------------------------------------------------------------------
" Use The Silver Searcher for everything
" ---------------------------------------------------------------------------
let g:ackprg = 'ag --nogroup --column --hidden'
set grepprg=ag\ --nogroup\ --nocolor
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ---------------------------------------------------------------------------
" Misc stuff
" ---------------------------------------------------------------------------
" set grepformat=%f:%l:%m
set completeopt=longest,menu,preview " insert mode comletion options
set complete=.
" Improve navigation of the popup menu for completion.
inoremap <expr> <C-n> pumvisible() ? '<C-n>' : '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
" Yank to the * register (system clipboard) to easily paste into other apps.
set clipboard+=unnamed
" Make mail files behave appropriately
au BufRead,BufNewFile *.mail set filetype=mail spell spelllang=en_us textwidth=67
au BufRead,BufNewFile *.txt set spell spelllang=en_us textwidth=0
au BufRead,BufNewFile *.md set textwidth=80
au BufRead,BufNewFile *.csv set synmaxcol=8000
autocmd BufRead,BufNewFile *.md.erb setlocal filetype=eruby.markdown textwidth=80
" Elixir hackery
au BufRead,BufNewFile *.ex set nospell textwidth=0
au BufRead,BufNewFile *.exs set nospell textwidth=0
augroup myfiletypes
"clear old autocmds in group
autocmd!
"for ruby, autoindent with two spaces, always expand tabs
autocmd FileType ruby,haml,eruby,yaml set ai sw=2 sts=2 et
autocmd FileType gitcommit setlocal spell
augroup END
augroup markdown
autocmd BufRead *.markdown setlocal spell ai formatoptions=tcroqn2 comments=n:>
augroup END
let g:liquid_highlight_types=["html","erb=eruby","html+erb=eruby.html"]
" ---------------------------------------------------------------------------
" Jump to last saved position of buffer when re-opening
" ---------------------------------------------------------------------------
autocmd BufReadPost *
\ if !(bufname("%") =~ '\(COMMIT_EDITMSG\)') && line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" ---------------------------------------------------------------------------
" Open url on current line in browser
" ---------------------------------------------------------------------------
function! HandleURI()
let s:uri = matchstr(getline("."), '[a-z]*:\/\/[^ >,;:]*')
echo s:uri
if s:uri != ""
exec "!open \"" . s:uri . "\""
else
echo "No URI found in line."
endif
endfunction
nmap <Leader>b :call HandleURI()<CR>
" ---------------------------------------------------------------------------
" Allow toggling of the quickfix window
" ---------------------------------------------------------------------------
command! -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
else
execute "copen 15"
endif
endfunction
nmap Q :QFix<CR>
augroup QFixToggle
autocmd!
autocmd BufWinEnter quickfix let g:qfix_win = bufnr("$")
autocmd BufWinLeave * if exists("g:qfix_win") && expand("<abuf>") == g:qfix_win | unlet! g:qfix_win | endif
augroup END
if $TERM == 'screen'
set term=xterm
endif
function! s:DetectElixirShellScript()
if getline(1) =~ '^#!.*\<elixir\>'
set filetype=elixir
endif
endfunction
autocmd BufNewFile,BufRead * call s:DetectElixirShellScript()