-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
vimrc
592 lines (508 loc) · 19 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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
" vim:fdm=marker:ts=2:sw=2:et:
" _
" __ _(_)_ __ ___ _ __ ___
" \ \ / / | '_ ` _ \| '__/ __|
" \ V /| | | | | | | | | (__
" \_/ |_|_| |_| |_|_| \___|
"
" Ian's .vimrc file
"
" Section: Key mappings {{{1
"--------------------------------------------------------------------------
" useful macros I use the most
nmap \A :set formatoptions+=a<CR>:echo "autowrap enabled"<CR>
nmap \M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
nmap \T :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
nmap \a :set formatoptions-=a<CR>:echo "autowrap disabled"<CR>
nmap \b :set nocin tw=80<CR>:set formatoptions+=a<CR>
nmap \c :call TmuxPaneClear()<CR>
nmap \e :NERDTreeToggle<CR>
nmap \f mt:Goyo<CR>'tzz
nmap \g :Gstatus<CR>
nmap \h :call ToggleHex()<CR>
nmap \i vip:sort<CR>
nmap \l :setlocal number!<CR>:setlocal number?<CR>
nmap \m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
nmap \o :set paste!<CR>:set paste?<CR>
nmap \p :ProseMode<CR>
nmap \q :nohlsearch<CR>
nmap \r :call TmuxPaneRepeat()<CR>
nmap \s :setlocal invspell<CR>
nmap \t :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
nmap \u :setlocal list!<CR>:setlocal list?<CR>
nmap \w :setlocal wrap!<CR>:setlocal wrap?<CR>
nmap \x :cclose<CR>
nmap \z :w<CR>:!open %<CR><CR>
" You don't know what you're missing if you don't use this.
nmap <C-e> :e#<CR>
" Move between open buffers.
map <C-n> :bnext<CR>
map <C-p> :bprev<CR>
" Emacs-like bindings in normal mode
nmap <C-x>0 <C-w>c
nmap <C-x>1 <C-w>o
nmap <C-x>1 <C-w>s
nmap <C-x>1 <C-w>v
nmap <C-x>o <C-w><C-w>
nmap <M-o> <C-w><C-w>
" Emacs-like bindings in insert mode
imap <C-e> <C-o>$
" Emacs-like bindings in command line -- `:help emacs-keys`
cnoremap <C-a> <Home>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-d> <Del>
cnoremap <C-e> <End>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
cnoremap <M-d> <S-right><Delete>
cnoremap <Esc>b <S-Left>
cnoremap <Esc>f <S-Right>
cnoremap <Esc>d <S-right><Delete>
cnoremap <C-g> <C-c>
" Why not use the space or return keys to toggle folds?
nnoremap <space> za
vnoremap <space> zf
" Window movement shortcuts from Mark
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Search for the word under the cursor in the current directory
nmap <M-k> :Ack! "\b<cword>\b" <CR>
nmap <Esc>k :Ack! "\b<cword>\b" <CR>
nmap ˚ :Ack! "\b<cword>\b" <CR>
nmap <M-S-k> :Ggrep! "\b<cword>\b" <CR>
nmap <Esc>K :Ggrep! "\b<cword>\b" <CR>
" Alt-W to delete a buffer and remove it from the list but keep the window
" (courtesy bufkill.vim)
nmap <Esc>w :BD<CR>
nmap ∑ :BD<CR>
" Don't scroll like crazy in the QuickFix and other fixes
autocmd FileType qf setlocal number nolist scrolloff=0
autocmd Filetype qf wincmd J
" Hex mode from http://vim.wikia.com/wiki/Improved_hex_editing
" ex command for toggling hex mode - define mapping if desired
command -bar Hexmode call ToggleHex()
" helper function to toggle hex mode
function ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
%!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
%!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endfunction
" Use \r to repeat the last command in a tmux pane of my choosing.
function TmuxPaneRepeat()
write
silent execute ':!tmux send-keys -t' g:tmux_console_pane 'C-p' 'C-j'
redraw!
endfunction
" Use \c to add some space in a tmux pane.
function TmuxPaneClear()
silent execute ':!tmux send-keys -t' g:tmux_server_pane 'C-j' 'C-j' 'C-j' 'C-j' 'C-j' 'C-j' 'C-j'
redraw!
endfunction
" Section: Hacks {{{1
"--------------------------------------------------------------------------
" Make j & k linewise {{{2
" turn off linewise keys -- normally, the `j' and `k' keys move the cursor down
" one entire line. with line wrapping on, this can cause the cursor to actually
" skip a few lines on the screen because it's moving from line N to line N+1 in
" the file. I want this to act more visually -- I want `down' to mean the next
" line on the screen
map j gj
map k gk
" having Ex mode start or showing me the command history
" is a complete pain in the ass if i mistype
map Q <silent>
map q: <silent>
map K <silent>
"map q <silent>
" Make the cursor stay on the same line when window switching {{{2
function! KeepCurrentLine(motion)
let theLine = line('.')
let theCol = col('.')
exec 'wincmd ' . a:motion
if &diff
call cursor(theLine, theCol)
endif
endfunction
nnoremap <C-w>h :silent call KeepCurrentLine('h')<CR>
nnoremap <C-w>l :silent call KeepCurrentLine('l')<CR>
" Section: Abbrevations {{{1
"--------------------------------------------------------------------------
" Vim command line: $c
" URL: http://www.vim.org/tips/tip.php?tip_id=1055
cno $c e <C-\>eCurrentFileDir()<CR>
function! CurrentFileDir()
return "e " . expand("%:p:h") . "/"
endfunction
" I never type these right
abbr conosle console
abbr comopnent component
" Temporary debugging helpers
autocmd BufEnter *.py iabbr xxx print('XXX
autocmd BufEnter *.py iabbr yyy print('YYY
autocmd BufEnter *.py iabbr zzz print('ZZZ
autocmd BufEnter *.coffee iabbr xxx console.log 'XXX',
autocmd BufEnter *.coffee iabbr yyy console.log 'YYY',
autocmd BufEnter *.coffee iabbr zzz console.log 'ZZZ',
autocmd BufEnter *.js iabbr xxx console.log('XXX',
autocmd BufEnter *.js iabbr yyy console.log('YYY',
autocmd BufEnter *.js iabbr zzz console.log('ZZZ',
autocmd BufEnter *.rb iabbr xxx puts "XXX
autocmd BufEnter *.rb iabbr yyy puts "YYY
autocmd BufEnter *.rb iabbr zzz puts "ZZZ
autocmd BufEnter *.rb iabbr ppp require 'pp'; pp
" Section: Vim options {{{1
"--------------------------------------------------------------------------
set autoindent " Carry over indenting from previous line
set autoread " Don't bother me hen a file changes
set autowrite " Write on :next/:prev/^Z
set backspace=indent,eol,start
" Allow backspace beyond insertion point
set cindent " Automatic program indenting
set cinkeys-=0# " Comments don't fiddle with indenting
set cino= " See :h cinoptions-values
set commentstring=\ \ #%s " When folds are created, add them to this
set copyindent " Make autoindent use the same chars as prev line
set directory-=. " Don't store temp files in cwd
set encoding=utf8 " UTF-8 by default
set expandtab " No tabs
set fileformats=unix,dos,mac " Prefer Unix
set fillchars=vert:\ ,stl:\ ,stlnc:\ ,fold:-,diff:┄
" Unicode chars for diffs/folds, and rely on
" Colors for window borders
silent! set foldmethod=marker " Use braces by default
set formatoptions=tcqn1 " t - autowrap normal text
" c - autowrap comments
" q - gq formats comments
" n - autowrap lists
" 1 - break _before_ single-letter words
" 2 - use indenting from 2nd line of para
set hidden " Don't prompt to save hidden windows until exit
set history=200 " How many lines of history to save
set hlsearch " Hilight searching
set ignorecase " Case insensitive
set incsearch " Search as you type
set infercase " Completion recognizes capitalization
set laststatus=2 " Always show the status bar
set linebreak " Break long lines by word, not char
set list " Show whitespace as special chars - see listchars
set listchars=tab:»\ ,extends:›,precedes:‹,nbsp:·,trail:· " Unicode characters for various things
set matchtime=2 " Tenths of second to hilight matching paren
set modelines=5 " How many lines of head & tail to look for ml's
silent! set mouse=nvc " Use the mouse, but not in insert mode
set nobackup " No backups left after done editing
set nonumber " No line numbers to start
set visualbell t_vb= " No flashing or beeping at all
set nowritebackup " No backups made while editing
set printoptions=paper:letter " US paper
set ruler " Show row/col and percentage
set scroll=4 " Number of lines to scroll with ^U/^D
set scrolloff=15 " Keep cursor away from this many chars top/bot
set sessionoptions-=options " Don't save runtimepath in Vim session (see tpope/vim-pathogen docs)
set shiftround " Shift to certain columns, not just n spaces
set shiftwidth=2 " Number of spaces to shift for autoindent or >,<
set shortmess+=A " Don't bother me when a swapfile exists
set showbreak= " Show for lines that have been wrapped, like Emacs
set showmatch " Hilight matching braces/parens/etc.
set sidescrolloff=3 " Keep cursor away from this many chars left/right
set smartcase " Lets you search for ALL CAPS
set softtabstop=2 " Spaces 'feel' like tabs
set suffixes+=.pyc " Ignore these files when tab-completing
set tabstop=2 " The One True Tab
set textwidth=100 " 100 is the new 80
set thesaurus+=~/.vim/mthes10/mthesaur.txt
set notitle " Don't set the title of the Vim window
set wildmenu " Show possible completions on command line
set wildmode=list:longest,full " List all options and complete
set wildignore=*.class,*.o,*~,*.pyc,.git,node_modules " Ignore certain files in tab-completion
" Section: Commands & Functions {{{1
"--------------------------------------------------------------------------
" i always, ALWAYS hit ":W" instead of ":w"
command! Q q
command! W w
" http://stackoverflow.com/questions/1005/getting-root-permissions-on-a-file-inside-of-vi
cmap w!! w !sudo tee >/dev/null %
" trim spaces at EOL
command! TEOL %s/\s\+$//
command! CLEAN retab | TEOL
" Close all buffers except this one
command! BufCloseOthers %bd|e#
" hightlight more than 80 characters
function! HighlightTooLongLines()
highlight def link RightMargin Error
if &textwidth != 0
exec 'match RightMargin /\%<' . (&textwidth + 4) . 'v.\%>' . (&textwidth + 2) . 'v/'
endif
endfunction
" Rename.vim - Rename a buffer within Vim and on the disk
" Copyright June 2007 by Christian J. Robinson <infynity@onewest.net>
" Distributed under the terms of the Vim license. See ":help license".
" http://www.infynity.spodzone.com/vim/Rename.vim
" Usage: :Rename[!] {newname}
command! -nargs=* -complete=file -bang Rename :call Rename("<args>", "<bang>")
function! Rename(name, bang)
let l:curfile = expand("%:p")
let v:errmsg = ""
silent! exe "saveas" . a:bang . " " . a:name
if v:errmsg =~# '^$\|^E329'
if expand("%:p") !=# l:curfile && filewritable(expand("%:p"))
silent exe "bwipe! " . l:curfile
if delete(l:curfile)
echoerr "Could not delete " . l:curfile
endif
endif
else
echoerr v:errmsg
endif
endfunction
" Section: Python specifics {{{1
"--------------------------------------------------------------------------
if has('python')
python << EOF
import os
import sys
sys.path.append(os.path.join(os.getenv('HOME'), '.vim', 'python'))
EOF
endif
" Section: Plugin settings {{{1
"--------------------------------------------------------------------------
" A new Vim package system
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
" for any plugins that use this, make their keymappings use comma
let mapleader = ","
let maplocalleader = ","
" Explore.vim (comes with Vim 6)
let explVertical = 1
let explSplitRight = 1
let explWinSize = 30
let explHideFiles = '^\.,\.(class|swp|pyc|pyo)$,^CVS$'
let explDirsFirst = -1
" vimspell.vim
let spell_auto_type = ""
" NERD_tree.vim
let NERDTreeIgnore = ['\~$', '\.pyc$']
" FZF (replaces Ctrl-P, FuzzyFinder and Command-T)
set rtp+=/usr/local/opt/fzf
set rtp+=~/.fzf
nmap ; :Buffers<CR>
nmap <Leader>r :Tags<CR>
nmap <Leader>t :Files<CR>
nmap <Leader>a :Ag<CR>
" ack -> ag
let g:ackprg = 'ag --vimgrep'
" fugitive
autocmd QuickFixCmdPost *grep* cwindow
" GitGutter
let g:gitgutter_sign_added = '∙'
let g:gitgutter_sign_modified = '∙'
let g:gitgutter_sign_removed = '∙'
let g:gitgutter_sign_modified_removed = '∙'
" supertab
let g:SuperTabLongestEnhanced=1
let g:SuperTabLongestHighlight=1
" Zenburn
let g:zenburn_high_Contrast = 1
" incsearch.vim
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" markdown.vim
let g:vim_markdown_frontmatter = 1
" enable filetype plugins -- e.g., ftplugin/xml.vim
filetype plugin indent on
" ALE
let g:ale_sign_warning = '▲'
let g:ale_sign_error = '✗'
highlight link ALEWarningSign String
highlight link ALEErrorSign Title
" Lightline
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [['mode', 'paste'], ['filename', 'modified']],
\ 'right': [['lineinfo'], ['percent'], ['readonly', 'linter_warnings', 'linter_errors', 'linter_ok']]
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK'
\ },
\ 'component_type': {
\ 'readonly': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ }
function! LightlineLinterWarnings() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ◆', all_non_errors)
endfunction
function! LightlineLinterErrors() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ✗', all_errors)
endfunction
function! LightlineLinterOK() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✓ ' : ''
endfunction
autocmd User ALELint call s:MaybeUpdateLightline()
" Update and show lightline but only if it's visible (e.g., not in Goyo)
function! s:MaybeUpdateLightline()
if exists('#lightline')
call lightline#update()
end
endfunction
" Section: Color and syntax {{{1
"--------------------------------------------------------------------------
" Make sure colored syntax mode is on, and make it Just Work with newer 256
" color terminals like iTerm2.
set background=dark
let g:rehash256 = 1
colorscheme molokai
if !has('gui_running')
if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "gnome-terminal"
set t_Co=256
elseif has("terminfo")
colorscheme default
set t_Co=8
set t_Sf=[3%p1%dm
set t_Sb=[4%p1%dm
else
colorscheme default
set t_Co=8
set t_Sf=[3%dm
set t_Sb=[4%dm
endif
" Disable Background Color Erase when within tmux - https://stackoverflow.com/q/6427650/102704
if $TMUX != ""
set t_ut=
endif
endif
syntax on
" window splits & ruler were too bright - change to white on grey
" (shouldn't change GUI or non-color term appearance)
highlight StatusLine cterm=NONE ctermbg=blue ctermfg=white
highlight StatusLineNC cterm=NONE ctermbg=black ctermfg=white
highlight VertSplit cterm=NONE ctermbg=black ctermfg=white
" unfortunately, taglist.vim's filenames is linked to LineNr, which sucks
highlight def link MyTagListFileName Statement
highlight def link MyTagListTagName Question
" turn off coloring for CDATA
highlight def link xmlCdata NONE
" custom incorrect spelling colors
highlight SpellBad term=underline cterm=underline ctermbg=NONE ctermfg=205
highlight SpellCap term=underline cterm=underline ctermbg=NONE ctermfg=33
highlight SpellRare term=underline cterm=underline ctermbg=NONE ctermfg=217
highlight SpellLocal term=underline cterm=underline ctermbg=NONE ctermfg=72
" ignore should be... ignored
silent! highlight Ignore cterm=bold ctermfg=black ctermbg=bg
highlight clear FoldColumn
highlight def link FoldColumn Ignore
highlight clear Folded
highlight link Folded Ignore
highlight clear LineNr
highlight! def link LineNr Ignore
" nice-looking hilight if I remember to set my terminal colors
highlight clear Search
highlight Search term=NONE cterm=NONE ctermfg=white ctermbg=black
" make hilighted matching parents less offensive
highlight clear MatchParen
highlight link MatchParen Search
" colors for NERD_tree
highlight def link NERDTreeRO NERDTreeFile
" make trailing spaces visible
highlight SpecialKey ctermbg=Yellow guibg=Yellow
" make menu selections visible
highlight PmenuSel ctermfg=black ctermbg=magenta
" the sign column slows down remote terminals
highlight clear SignColumn
highlight link SignColumn Ignore
" Markdown could be more fruit salady.
highlight link markdownH1 PreProc
highlight link markdownH2 PreProc
highlight link markdownLink Character
highlight link markdownBold String
highlight link markdownItalic Statement
highlight link markdownCode Delimiter
highlight link markdownCodeBlock Delimiter
highlight link markdownListMarker Todo
" prose mode
function! ProseMode()
"set formatoptions=1an
call goyo#execute(0, [])
set spell noci nosi noai nolist noshowmode noshowcmd
set complete+=s
set bg=light
if !has('gui_running')
let g:solarized_underline = 1
let g:solarized_termcolors=256
endif
colors solarized
endfunction
command! ProseMode call ProseMode()
" Section: File types {{{1
"--------------------------------------------------------------------------
" Remove ALL autocommands for the current group.
augroup vimrc
autocmd!
" File types that get huge and slow
au BufNewFile,BufRead *.coffee syn sync fromstart
au BufNewFile,BufRead *.md,*.markdown setlocal foldlevel=999 tw=0 nocin
au BufNewFile,BufRead *.json set ft=json
au BufNewFile,BufRead *.vert,*.frag set ft=glsl
au BufNewFile,BufRead *.gyp set ft=python
au BufNewFile,BufRead *.cson set ft=coffee
au FileType json setlocal conceallevel=0 foldmethod=syntax foldlevel=999
au BufNewFile,BufRead *.i7x setf inform7
au FileType inform7 setlocal nolist tw=0 ts=4 sw=4 noet foldlevel=999
autocmd Filetype gitcommit setlocal tw=80
augroup END
" Section: Load ~/.vimlocal {{{1
"--------------------------------------------------------------------------
" Some plugin seems to search for something at startup
silent! nohlsearch
" Now load specifics to this host
if filereadable(expand("~/.vimlocal"))
source ~/.vimlocal
endif