forked from whiteinge/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
509 lines (397 loc) · 17.6 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
" Best Goddamn vimrc in the whole world.
" Author: Seth House <[email protected]>
" For more information type :help followed by the command.
set nocompatible "cp: turns off strct vi compatibility
filetype plugin indent on
call pathogen#infect()
" Search {{{
set incsearch "is: automatically begins searching as you type
set ignorecase "ic: ignores case when pattern matching
set smartcase "scs: ignores ignorecase when pattern contains uppercase characters
set hlsearch "hls: highlights search results
" Use leader-n to unhighlight search results in normal mode:
nmap <silent> <leader>n :silent noh<cr>
" Display the number of matches for the last search
nmap <leader># :%s:<C-R>/::gn<cr>
" Restore case-sensitivity for jumping to tags (set ic disables it)
map <silent> <C-]> :set noic<cr>g<C-]><silent>:set ic<cr>
" }}}
" Line Wrap {{{
set backspace=indent,eol,start "bs: allows you to backspace over the listed character types
set linebreak "lbr: causes vim to not wrap text in the middle of a word
set wrap "wrap: wraps lines by default
" Toggle line wrapping in normal mode:
nmap <silent> <C-P> :set nowrap!<cr>:set nowrap?<cr>
" }}}
" Editing {{{
set showmatch "sm: flashes matching brackets or parentheses
set nobackup "bk: does not write a persistent backup file of an edited file
set writebackup "wb: does keep a backup file while editing a file
set undofile "udf: persist the undo tree to a file; dir below will not be auto-created
set undodir=$HOME/.vim/undodir,.
" Searches the current directory as well as subdirectories with commands like :find, :grep, etc.
set path=.,**
set cindent "cin: enables the second-most configurable indentation (see :help C-indenting).
set cinoptions=l1,c4,(s,U1,w1,m1,j1,J1
set formatoptions+=j "fo: remove comment leader when joining lines
set expandtab "et: uses spaces instead of tab characters
set smarttab "sta: helps with backspacing because of expandtab
set softtabstop=4 "ts: number of spaces that a tab counts for
set shiftwidth=4 "sw: number of spaces to use for autoindent
set shiftround "sr: rounds indent to a multiple of shiftwidth
set nojoinspaces "nojs: prevents inserting two spaces after punctuation on a join (it's not 1990 anymore)
set lazyredraw "lz: will not redraw the screen while running macros (goes faster)
set pastetoggle=<F9> "pt: useful so auto-indenting doesn't mess up code when pasting
set complete=.,w,b,u "cpt: default insert completion minus tags and included files
set virtualedit=block "ve: let cursor move past the last char in <C-V> mode
set nostartofline "sol: avoid moving cursor to BOL when jumping around
set cryptmethod=blowfish "cm: use (much) stronger blowfish encryption
" Fix for legacy vi inconsistency
map Y y$
" Allow using the repeat operator with a visual selection (!)
" http://stackoverflow.com/a/8064607/127816
vnoremap . :normal .<cr>
" Allow undoing insert-mode ctrl-u and ctrl-w
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
" Add a line without changing position or leaving mode
map <leader>o :set paste<cr>m`o<esc>``:set nopaste<cr>
map <leader>O :set paste<cr>m`O<esc>``:set nopaste<cr>
" A shortcut to show the numbered register contents
map <F2> :reg "0123456789-*+:/<cr>
set colorcolumn=80 "cc: draw a visual line down the 80th column
" Toggle between line numbers and relative line numbers
nnoremap <silent><leader>u :exe "set " . (&relativenumber == 1 ? "norelativenumber" : "relativenumber")<cr>
"lcs: displays tabs with :set list & displays when a line runs off-screen
set listchars=tab:>-,trail:\ ,precedes:<,extends:>
" Toggle spell-checking
map <silent> <F10> :set nospell!<cr>:set nospell?<cr>
" Maps Omnicompletion to CTRL-space since ctrl-x ctrl-o is for Emacs-style RSI
inoremap <nul> <C-X><C-O>
" don't select first item, follow typing in autocomplete
set completeopt=longest,menuone,preview
" Change directory to the path of the current file
map <leader>cd :cd %:p:h<cr>
" Edit a new file starting in the same dir as the current file
map <leader>ce :e <C-R>=expand("%:p:h") . "/" <cr>
map <leader>cs :sp <C-R>=expand("%:p:h") . "/" <cr>
map <leader>ct :tabnew <C-R>=expand("%:p:h") . "/" <cr>
" Highlight problem lines: more than 80 chars, trailing spaces, only whitespace
" Toggle with \l
nnoremap <silent> <leader>l
\ :set nolist!<cr>:set nolist?<cr>
\ :if exists('w:long_line_match') <bar>
\ silent! call matchdelete(w:long_line_match) <bar>
\ unlet w:long_line_match <bar>
\ elseif &textwidth > 0 <bar>
\ let w:long_line_match = matchadd('ErrorMsg', '\%>'.&tw.'v.\+', -1) <bar>
\ else <bar>
\ let w:long_line_match = matchadd('ErrorMsg', '\%>80v.\+', -1) <bar>
\ endif<cr>
" Find merge conflict markers
map <leader>fc /\v^[<=>]{7}( .*\|$)<cr>
set dictionary=spell " dict: complete words from the spelling dict (when spell is on)
" set thesaurus " tsr: complete words from a thesaurus
" Use generic omnicompletion if something more specific isn't already set
if has("autocmd") && exists("+omnifunc")
au Filetype *
\ if &omnifunc == "" | setl omnifunc=syntaxcomplete#Complete | endif
endif
if has("autocmd")
" Helps if you have to use another editor on the same file
au FileChangedShell * Warn "File has been changed outside of Vim."
endif
" Restore last cursor position in file
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" If a ftplugin has defined the b:ftskeleton variable, try to load the
" skeleton template.
au BufNewFile * silent! exe "0r ". b:ftskeleton
" Insert timestamps by calling out to date; override format by filetype
let b:dateformat = ''
nmap <silent> <leader>dts :exe ':r !date '. escape(b:dateformat, '%')<cr>
" }}}
" Folding (spacebar toggles) {{{
" Spacebar toggles a fold, zi toggles all folding, zM closes all folds
noremap <silent> <space> :exe 'silent! normal! za'.(foldlevel('.')?'':'l')<cr>
set foldmethod=marker "fdm: looks for patterns of triple-braces in a file
set foldcolumn=4 "fdc: creates a small left-hand gutter for displaying fold info
" }}}
" Menu completion {{{
set suffixes+=.pyc,.pyo " Don't autocomplete these filetypes
set wildmenu "wmnu: enhanced ex command completion
set wildmode=longest:full,list:full "wim: helps wildmenu auto-completion
" }}}
" Window Layout {{{
set encoding=utf-8
set relativenumber "rnu: show line numbers relative to the current line; <leader>u to toggle
set number "nu: show the actual line number for the current line in relativenumber
set showmode "smd: shows current vi mode in lower left
set cursorline "cul: highlights the current line
set showcmd "sc: shows typed commands
set cmdheight=2 "ch: make a little more room for error messages
set sidescroll=2 "ss: only scroll horizontally little by little
set scrolloff=1 "so: places a line between the current line and the screen edge
set sidescrolloff=2 "siso: places a couple columns between the current column and the screen edge
set laststatus=2 "ls: makes the status bar always visible
set ttyfast "tf: improves redrawing for newer computers
set history=200 "hi: number of search patterns and ex commands to remember
" (also used by viminfo below for /, :, and @ options)
set viminfo='200 "vi: For a nice, huuuuuge viminfo file
if &columns < 88
" If we can't fit at least 80-cols, don't display these screen hogs
set nonumber
set foldcolumn=0
endif
" }}}
" Multi-buffer/window/tab editing {{{
set switchbuf=usetab "swb: Jumps to first tab or window that contains specified buffer instead of duplicating an open window
set showtabline=1 "stal: Display the tabbar if there are multiple tabs. Use :tab ball or invoke Vim with -p
set hidden "hid: allows opening a new buffer in place of an existing one without first saving the existing one
set splitright "spr: puts new vsplit windows to the right of the current
set splitbelow "sb: puts new split windows to the bottom of the current
set winminheight=0 "wmh: the minimal line height of any non-current window
set winminwidth=0 "wmw: the minimal column width of any non-current window
" Type <F1> follwed by a buffer number or name fragment to jump to it.
" Also replaces the annoying help button. Based on tip 821.
map <F1> :ls<cr>:b<space>
" Quickly jump to a tag if there's only one match, otherwise show the list
map <F3> :tj<space>
" Display a list of included files and quickly jump to one
map <F4> [I:let nr = input("Which one: ")<bar>exe "normal " . nr ."[\t"<cr>
" When restoring a hidden buffer Vim doesn't always keep the same view (like
" when your view shows beyond the end of the file). (Vim tip 1375)
if ! &diff
au BufLeave * let b:winview = winsaveview()
au BufEnter * if(exists('b:winview')) | call winrestview(b:winview) | endif
endif
" Shortcuts for working with quickfix/location lists
nmap ]q :cnext<cr>
nmap [q :cprev<cr>
nmap ]Q :clast<cr>
nmap [Q :cfirst<cr>
" Disable one diff window during a three-way diff allowing you to cut out the
" noise of a three-way diff and focus on just the changes between two versions
" at a time. Inspired by Steve Losh's Splice
function! DiffToggle(window)
" Save the cursor position and turn on diff for all windows
let l:save_cursor = getpos('.')
windo :diffthis
" Turn off diff for the specified window (but keep scrollbind) and move
" the cursor to the left-most diff window
exe a:window . "wincmd w"
diffoff
set scrollbind
set cursorbind
exe a:window . "wincmd " . (a:window == 1 ? "l" : "h")
" Update the diff and restore the cursor position
diffupdate
call setpos('.', l:save_cursor)
endfunction
" Toggle diff view on the left, center, or right windows
nmap <silent> <leader>dl :call DiffToggle(1)<cr>
nmap <silent> <leader>dm :call DiffToggle(2)<cr>
nmap <silent> <leader>dr :call DiffToggle(3)<cr>
nmap <silent> <leader>du :diffupdate<cr>
" }}}
" X11 Integration {{{
" (I.e.: don't do any automatic integration, please :)
set mouse= " Disable mouse control for console Vim (very annoying)
set clipboard= " Disable automatic X11 clipboard crossover
" }}}
" Color {{{
" All coloring options are for the non-GUI Vim (see :help cterm-colors).
" Make listchars (much) more noticable.
au ColorScheme * hi SpecialKey ctermfg=7 ctermbg=1
" A nice, minimalistic tabline.
au ColorScheme * hi TabLine cterm=bold,underline ctermfg=8 ctermbg=none
au ColorScheme * hi TabLineSel cterm=bold ctermfg=0 ctermbg=7
au ColorScheme * hi TabLineFill cterm=bold ctermbg=none
" Black ColorColumn to not catch the eye more than is necessary
au ColorScheme * hi ColorColumn ctermbg=0
" Makes the current line stand out with bold and in the numberline
au ColorScheme * hi CursorLine cterm=bold
au ColorScheme * hi LineNr cterm=bold ctermfg=0 ctermbg=none
" Match the Sign column to the number column
au ColorScheme * hi SignColumn cterm=bold ctermfg=0 ctermbg=none
" Refresh busted syntax highlighting (this happens too often)
map <F12> :syntax sync fromstart<cr>
" Shorten the timeout when looking for a paren match to highlight
let g:matchparen_insert_timeout = 5
set synmaxcol=500 "smc: Stop syntax highlighting on very long lines
syntax enable
colorscheme desert
" }}}
" Printing {{{
" Shows line numbers and adjusts the left margin not to be ridiculous
set printoptions=number:y,left:5pc
set printfont=Monaco:h8 " face-type (not size) ignored in PostScript output :-(
set printencoding=utf-8
" }}}
" :Explore mode {{{
let g:netrw_hide = 1 " Use the hiding list
" Hide the following file patterns (change to suit your needs):
" (I don't know what the fuck \~$ is, but file hiding seems to break without it appearing first in the list...)
let g:netrw_list_hide = '^\..*,\.pyc$'
" Commands for :Explore (verify these!)
let g:explVertical = 1 " open vertical split winow
let g:explSplitRight = 1 " Put new window to the right of the explorer
let g:explStartRight = 0 " new windows go to right of explorer window
" Tree view. Adaptable?
" ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
" }}}
" Scripting helpers {{{1
command -nargs=1 Warn echohl WarningMsg | echo <args> | echohl None
" }}}
" Make the current buffer a scratch buffer {{{1
function! Scratch()
setlocal buftype=nofile
setlocal bufhidden=delete
setlocal noswapfile
Warn "This file is now a scratch file!"
endfunction
nmap <silent> <leader>S :call Scratch()<cr>
" }}}
" Diff two registers {{{
" Open a diff of two registers in a new tabpage. Close the tabpage when
" finished. If no registers are specified it diffs the most recent yank with
" the most recent deletion.
" Usage:
" :DiffRegs
" :DiffRegs @a @b
function! DiffRegsFunc(...)
let l:left = a:0 == 2 ? a:1 : "@0"
let l:right = a:0 == 2 ? a:2 : "@1"
tabnew
exe 'put! ='. l:left
vnew
exe 'put! ='. l:right
windo call Scratch()
windo diffthis
winc t
endfunction
com -nargs=* DiffRegs call DiffRegsFunc(<f-args>)
" }}}
" YankList {{{1
" Is is possbile to store the ten most recent yanks using opfunc (similar to
" the built-in numbered registers)?
" NOTE: work in progress, this is currently non-functional
" noremap <silent> gy :set opfunc=YankList<cr>g@
" vmap <silent> gy :<C-U>call YankList(visualmode(), 1)<cr>
" map <silent> gyy Y
function! YankList(type, ...)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
echo "Something was copied!\n"
if a:0 " Invoked from Visual mode, use '< and '> marks.
silent exe "normal! `<" . a:type . "`>y"
elseif a:type == 'line' " Line
silent exe "normal! '[V']y"
elseif a:type == 'block' " Block
silent exe "normal! `[\<C-V>`]y"
else " ???
silent exe "normal! `[v`]y"
endif
endfunction
" }}}
" MyTabLine {{{
" Number the tabs.
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let curwinnr = tabpagewinnr(i,'$')
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let s .= '%' . i . 'T'
let s .= ' ' . i . ': '
let file = bufname(buflist[winnr - 1])
let file = fnamemodify(file, ':p:t')
if file == ''
let file = '[No Name]'
endif
let s .= file
let s .= (curwinnr > 1 ? ' (' . curwinnr .') ' : '')
let s .= ' '
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set tabline=%!MyTabLine()
" }}}
" Break any comma-seperated vals out on separate lines {{{
function! SplitItems(type, ...)
normal! `[v`]x
let @@ = substitute(@@, ',\s*', '\n', 'g')
set paste
exe "normal! i\<cr>\<esc>"
pu! "
set nopaste
endfunction
nnoremap <leader>s :set opfunc=SplitItems<cr>g@
vmap <silent> <leader>s :<C-U>call SplitItems(visualmode(), 1)<cr>
" }}}
" Plugin settings {{{
""" Run matchit without installing
if filereadable($VIMRUNTIME . "/macros/matchit.vim")
so $VIMRUNTIME/macros/matchit.vim
endif
""" Wordnet settings
noremap <F11> "wyiw:call WordNetOverviews(@w)<cr>
""" Gundo settings
nnoremap <F7> :GundoToggle<cr>
""" Syntastic settings
let g:syntastic_enable_highlighting = 0
let g:syntastic_check_on_wq = 0
let g:syntastic_error_symbol = 'E'
let g:syntastic_style_error_symbol = 'S'
let g:syntastic_warning_symbol = 'W'
let g:syntastic_style_warning_symbol = 'S'
let g:syntastic_always_populate_loc_list = 1
nmap <silent> <leader>y :SyntasticCheck<cr>
if ! &diff
let g:syntastic_check_on_open = 1
endif
""" Fugitive settings
" Open current buffer in a new tab and show Fugitive diff
nmap <silent> <leader>dd :tab split \| Gdiff \| wincmd h<cr>
nmap <silent> <leader>dc :Gcommit<cr>
nmap <silent> <leader>da :Gcommit --amend --reuse-message=HEAD<cr>
""" Tagbar plugin settings
map <F5> :TagbarToggle<cr>
let g:tagbar_sort = 0
let g:tagbar_compact = 1
let g:tagbar_autoshowtag = 1
let g:tagbar_width = 25
let g:tagbar_iconchars = ['+', '-']
" Auto-open tagbar only if not in diff mode and the term wide enough to also
" fit an 80-column window (plus eight for line numbers and the fold column).
if &columns > 118
if ! &diff
au VimEnter * nested :call tagbar#autoopen(1)
endif
else
let g:tagbar_autoclose = 1
let g:tagbar_autofocus = 1
endif
""" Airline settings
" let g:airline_powerline_fonts = 1
let g:airline_detect_whitespace = 2
let g:airline_whitespace_symbol = 'Ξ'
let g:airline_linecolumn_prefix = '␊ '
let g:airline_left_sep = '▞'
let g:airline_right_sep = '▚'
" Add the alternate buffer name next to the current file name
let g:airline_section_c = "%f%m %{bufname('#') != '' ? '('. expand('#:t') .')' : ''}"
" Dispatch mappings
nmap <silent> <leader>b :Make!<cr>
" }}}
" eof
" vim:ft=vim:fdm=marker:ff=unix:nowrap:tabstop=4:shiftwidth=4:softtabstop=4:smarttab:shiftround:expandtab