-
Notifications
You must be signed in to change notification settings - Fork 5
/
.vimrc
536 lines (462 loc) · 15 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
" ~/.vimrc
"
" Like many .vimrc files, a lot of what is below was copied from other .vimrcs
" and modified to meet my specifications. Significant features were taken from
" Andre Pang's Vimacs plugin for vim:
" http://www.vim.org/scripts/script.php?script_id=300
" Thus, some emacs-native keybindings are present in this .vimrc.
"scriptencoding utf-8 " Use UTF-8
"set encoding=utf-8 " Default encoding should always be UTF-8
set nocompatible " Don't emulate vi's limitations
set tabstop=2 " Use 2 spaces for tabs
set shiftwidth=2 " Use 2 spaces for next line indent
set smarttab " Tab next line based on current line
set expandtab " Use spaces for tabs
set cindent " C indenting
set cinoptions=t0,(0,)60,u0,*100 " All sorts of options
set linebreak " Display long lines wrapped at word boundary
set incsearch " Enable incremental search
set ignorecase " Ignore case when searching
set infercase " Try to figure out the case when searching
set hlsearch " Highlight the search results
set ve=block " Visual Edit Blocking
set lazyredraw " Enable Lazy Redraw (faster macro execution)
set showmode " Show the current mode
set showmatch " Show matching brackets
set mat=2 " Blink (for mat*.1s) during bracket match
set wildmenu " Enable wildmenu
set wildmode=longest,full " Match the longest and full matches
set wildignore=*.o,*~ " Always ignore these files
set scrolloff=3 " Lines of context on vertical scroll
set sidescrolloff=2 " Columns of context on horizontal scroll
set whichwrap+=<,>,h,l " Backspace and cursor keys wrap
set backspace=2 " Normal backspace behavior
set textwidth=80 " Break lines at 80 characters
set showfulltag " Show full tags when doing completion
set history=1000 " lines of history
set isk+=_,$,@,%,#,- " ignore these in words (word dividers)
set hidden " Allow flipping of buffers without saving
set magic " Regular expression characters have special meaning
set noerrorbells " No noise
set cmdheight=2 " Show two lines for command history
set showcmd " Show partial command / info about visual selection
set background=dark " I use a black background
set tabpagemax=20 " Maximum number of tabs opened by -p
set number " Line numbers
colorscheme wombat256
" Backup locations
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/temp
set title " Set a title on the terminal
set shortmess=atI " Enable short messages (press a key is annoying)
" Customize the statusline
set statusline=(%n)\ %F%m%r%h%w\ (%{&ff}%(\ %y%))\ (%03l:%03v\ [0x%02B])%=(%p%%/%L)
set laststatus=2 " Always show the status line
let perl_extended_vars=1 " highlight advanced perl vars inside strings
" screen has broken this before...
if (&term != "screen" && &term != "screen-bce")
set mouse=a " Use mouse everywhere
endif
" selectively enable 256 colors
if (&term == "screen" || &term == "screen-bce" || &term == "xterm" || &term == "xterm-256color")
set t_Co=256
endif
if (v:version >= 700)
set nospell " Disable spell checking by default
set spelllang=en_us " Spelling check language
endif
if has("folding")
set nofoldenable " Require user to fold
set fillchars=fold:- " Fold characters should be -
" If window is greater than 90 characters, set a column for folds
if has("eval")
fun! <SID>WideFold()
if winwidth(0) > 90
setlocal foldcolumn=1
else
setlocal foldcolumn=0
endif
endfun
if has("autocmd")
"autocmd BufEnter * :call <SID>WideFold()
endif
endif
endif
if has("syntax")
syntax on " Enable syntax highlighting
endif
" Fix line number color if we don't have 256 colors
if (&t_Co != 256)
highlight LineNr ctermfg=DarkGray
endif
if has("eval")
filetype on " Detect filetype by extension
filetype indent on " Enable indents based on extensions
filetype plugin on " Load filetype plugins
endif
" Reset indendation for the buffer when called; 'filetype indent on' seems to
" break the standard C indentation (line continuation in particular) for Perl
" and PHP.
fun! <SID>ResetIndent()
set indentexpr=
set cindent
endfun
fun! <SID>Perl()
set cinkeys=0{,0},!^F,o,O,e " Perl-friendly reindent keys
set cinwords=if,else,while,do,for,elsif,sub
call <SID>ResetIndent()
endfun
au BufRead,BufNewFile *.txt,README setfiletype text
autocmd FileType perl :call <SID>Perl()
autocmd FileType php :call <SID>ResetIndent()
autocmd FileType mail :set nocindent
autocmd FileType tex :set nocindent
autocmd FileType text :set nocindent | set nosmarttab
" Highlight text beyond the set text width
highlight LongLines ctermfg=Red
au BufEnter *.py,*.c,*.cpp,*.cc,*.java,*.h,*.pl,*.php exec 'match LongLines /\%>'.&textwidth.'v.\+/'
" Turn off search highlight when idle
if has("autocmd")
autocmd CursorHold * nohls | redraw
endif
" Always refresh syntax from the start
if has("autocmd")
autocmd BufEnter * syntax sync fromstart
endif
" Subversion commit messages need not be backed up
if has("autocmd")
autocmd BufRead svn-commit.tmp :setlocal nobackup
endif
" Disable case insensitivity for source files
if has("autocmd")
autocmd BufEnter *
\ if &filetype == 'c' ||
\ &filetype == 'cs' ||
\ &filetype == 'cpp' ||
\ &filetype == 'java' |
\ set noignorecase noinfercase |
\ endif
endif
" Show trailing whitespace visually
" Shamelessly stolen from Ciaran McCreesh <[email protected]>
if v:version >= 700
set list listchars=tab:>-,trail:.,extends:>,nbsp:_
else
set list listchars=tab:>-,trail:.,extends:>
endif
highlight SpecialKey ctermbg=Gray ctermfg=Gray
autocmd FileType mail :set nolist
autocmd FileType mail :highlight SpecialKey NONE
autocmd FileType mail :set nohls
" Get rid of the annoying UI
if has("gui")
set guioptions-=t " Disable Menu tear-offs
set guioptions-=T " Disable the tool-bar
set guioptions-=m " Disable the menu
set guioptions-=l
set guioptions-=L
set guioptions-=r " Disable the scrollbar
set guioptions-=R
endif
" Link the imports in Java sources
if has("autocmd")
autocmd BufRead *.java set include=^#\s*import
autocmd BufRead *.java set includeexpr=substitute(v:fname,'\\.','/','g')
endif
" Map F3 to nohls (turn off highlighting -- from a search, for instance)
nmap <silent> <F3> :silent nohls<CR>
imap <silent> <F3> <ESC>:silent nohls<CR>i<Right>
" Map F12 to line numbering
nmap <silent> <F12> :silent set number!<CR>
imap <silent> <F12> <ESC>:silent set number!<CR>i<Right>
" Spell check can be annoying at times
nmap <silent> <F4> :silent set spell!<CR>
imap <silent> <F4> <ESC>:silent set spell!<CR>i<Right>
" Tab indents the selected block of code by &shiftwidth, in visual mode.
vmap <silent> <Tab> >gv
" Shift-Tab un-indents does the opposite in visual mode
vmap <silent> <S-Tab> <gv
" <C-c><C-q> reindents current block
imap <C-c><C-q> <C-o>=a{
nmap <C-c><C-q> =a{
" Go into insert mode immediately
startinsert
if has("eval")
" fix meta-keys which generate <esc>a .. <esc>z
let c='a'
while c != 'z'
exec "map <esc>".c." <M-".c.">"
exec "map! <esc>".c." <M-".c.">"
exec "map <esc>".toupper(c)." <M-".toupper(c).">"
exec "map! <esc>".toupper(c)." <M-".toupper(c).">"
let c = nr2char(1+char2nr(c))
endw
" same for numbers
let n = 0
while n != 9
exec "map <esc>".n." <M-".n.">"
exec "map! <esc>".n." <M-".n.">"
exec "map <esc>".n." <M-".n.">"
exec "map! <esc>".n." <M-".n.">"
let n = n+1
endw
" Fix arrow keys
map <esc>Od <C-Left>
map! <esc>Od <C-Left>
map <esc>Oc <C-Right>
map! <esc>Oc <C-Right>
map <esc>Oa <C-Up>
map! <esc>Oa <C-Up>
map <esc>Ob <C-Down>
map! <esc>Ob <C-Down>
map <esc>OD <Left>
map! <esc>OD <Left>
map <esc>[D <Left>
map! <esc>[D <Left>
map <esc>OC <Right>
map! <esc>OC <Right>
map <esc>[C <Right>
map! <esc>[C <Right>
map <esc>OA <Up>
map! <esc>OA <Up>
map <esc>[A <Up>
map! <esc>[A <Up>
map <esc>OB <Down>
map! <esc>OB <Down>
map <esc>[B <Down>
map! <esc>[B <Down>
map <esc><Space> <M-Space>
map! <esc><Space> <M-Space>
endif
" Make Alt-Backspace delete the last word
map! <m-del> <m-f><c-w>
map! <esc><del> <m-f><c-w>
map! ÿ <c-w>
map! <m-bs> <c-w>
map! <esc><bs> <c-w>
map! <c-w>
" Buffer switching with <C-n> and <C-p>
nmap <C-p> :tabprevious<CR>
vmap <C-p> :tabprevious<CR>
imap <C-p> <esc>:tabprevious<CR>i
nmap <C-n> :tabnext<CR>
vmap <C-n> :tabnext<CR>
imap <C-n> <esc>:tabnext<CR>i
" Switch tags with meta-#
if has("eval")
let n = 1
while n != 9
exec "imap <M-".n."> <C-o>:tabn ".n."<CR>"
exec "nmap <M-".n."> <C-o>:tabn ".n."<CR>"
exec "vmap <M-".n."> <C-o>:tabn ".n."<CR>"
let n = n + 1
endw
endif
" Map ctrl-delete to delete buffer
imap <esc>[3^ <C-o>:tabc
" emacs/shell keybindings
imap <M-x> <C-o>:
nmap <M-x> :
imap <C-x><C-s> <C-o>:update<CR>
nmap <C-x><C-s> :update<CR>
imap <C-x><C-f> <C-o>:tabedit<Space>
nmap <C-x><C-f> :tabedit<Space>
imap <C-x>s <C-o>:wall<CR>
imap <C-x>i <C-o>:read<Space>
imap <C-x><C-w> <C-o>:write<Space>
imap <C-x><C-q> <C-o>:set invreadonly<CR>
imap <C-x><C-r> <C-o>:hide view<Space>
inoremap <C-c> <nop>
inoremap <C-x> <nop>
inoremap <C-x><C-c> <C-o>:confirm qall<CR>
nmap <C-x><C-c> :confirm qall<CR>
map <C-z> :suspend!<CR>
imap <C-z> <C-o>:suspend!<CR>
imap <C-_> <C-o>u
inoremap <C-l> <C-o>zz<C-o><C-l>
nnoremap <C-l> zz<C-l>
" Navigation
map <M-f> <S-Right>
map! <M-f> <S-Right>
map <M-b> <S-Left>
map! <M-b> <S-Left>
map <C-a> <Home>
map! <C-a> <Home>
map <C-e> <End>
map! <C-e> <End>
map <C-f> <Right>
map! <C-f> <Right>
map <C-b> <Left>
map! <C-b> <Left>
map <C-d> <Del>
map! <C-d> <Del>
" Window Operations (Emacs style)
inoremap <C-x>2 <C-o><C-w>s
nnoremap <C-x>2 <C-w>s
inoremap <C-x>3 <C-o><C-w>v
nnoremap <C-x>3 <C-w>v
inoremap <C-x>0 <C-o><C-w>c
nnoremap <C-x>0 <C-w>c
inoremap <C-x>1 <C-o><C-w>o
nnoremap <C-x>1 <C-w>o
inoremap <C-x>o <C-o><C-w>w
nnoremap <C-x>o <C-w>w
inoremap <C-x>O <C-o><C-w>W
nnoremap <C-x>O <C-w>W
inoremap <C-Tab> <C-o><C-w>w
nnoremap <C-Tab> <C-w>w
inoremap <C-S-Tab> <C-o><C-w>W
nnoremap <C-S-Tab> <C-w>w
inoremap <C-x>+ <C-o><C-w>=
nnoremap <C-x>+ <C-w>=
" Aborting
map <C-g> <C-c>
map! <C-g> <C-c>
" Killing
inoremap <silent> <M-d> <C-r>=<SID>KillWord()<CR>
inoremap <silent> <C-k> <C-r>=<SID>KillLine()<CR>
vnoremap <C-w> "1d
" Pasting
inoremap <silent> <C-y> <C-o>:call <SID>ResetKillRing()<CR><C-r><C-o>"
inoremap <S-Ins> <C-r><C-o>*
set sel=exclusive
" Visual mode
inoremap <silent> <C-Space> <C-r>=<SID>StartVisualMode()<CR>
" Unix terminals produce <C-@>, not <C-Space>
imap <C-@> <C-Space>
vnoremap <C-x><C-Space> <Esc>
" Marking blocks
inoremap <M-Space> <C-o>:call <SID>StartMarkSel()<CR><C-o>viw
inoremap <M-h> <C-o>:call <SID>StartMarkSel()<CR><C-o>vap
inoremap <C-<> <C-o>:call <SID>StartMarkSel()<CR><C-o>v1G0o
inoremap <C->> <C-o>:call <SID>StartMarkSel()<CR><C-o>vG$o
inoremap <C-x>h <C-o>:call <SID>StartMarkSel()<CR><Esc>1G0vGo
" Fill/reformat paragraph
inoremap <silent> <M-q> <C-o>:call <SID>FillParagraph()<CR>
" Case Change
inoremap <M-l> <C-o>gul<C-o>w
inoremap <M-u> <C-o>gUe<C-o>w
inoremap <M-c> <C-o>gUl<C-o>w
function! <SID>StartMarkSel()
if &selectmode =~ 'key'
set keymodel-=stopsel
endif
endfunction
function! <SID>ResetKillRing()
let s:kill_ring_position = 3
endfunction
function! <SID>StartVisualMode()
call <SID>StartMarkSel()
if col('.') > strlen(getline('.'))
" At EOL
return "\<Right>\<C-o>v\<Left>"
else
return "\<C-o>v"
endif
endfunction
command! FillParagraph :call <SID>FillParagraph()
function! <SID>FillParagraph()
let old_cursor_pos = <SID>Mark()
normal! gqip
execute old_cursor_pos
endfunction
function! <SID>KillWord()
if col('.') > strlen(getline('.'))
return "\<Del>\<C-o>dw"
else
return "\<C-o>dw"
endif
endfunction
function! <SID>KillLine()
if col('.') > strlen(getline('.'))
" At EOL; join with next line
return "\<Del>"
else
" Not at EOL; kill until end of line
return "\<C-o>d$"
endif
endfunction
function! <SID>LetDefault(var_name, value)
if !exists(a:var_name)
execute 'let ' . a:var_name . '=' . a:value
endif
endfunction
function! <SID>Mark(...)
if a:0 == 0
let mark = line(".") . "G" . virtcol(".") . "|"
normal! H
let mark = "normal!" . line(".") . "Gzt" . mark
execute mark
return mark
elseif a:0 == 1
return "normal!" . a:1 . "G1|"
else
return "normal!" . a:1 . "G" . a:2 . "|"
endif
endfun
command! -nargs=+ LetDefault call s:LetDefault(<f-args>)
" Incremental Searching and Query Replace
inoremap <C-s> <C-o>:call <SID>StartSearch('/')<CR><C-o>/
inoremap <C-r> <C-o>:call <SID>StartSearch('?')<CR><C-o>?
inoremap <M-n> <C-o>:cnext<CR>
inoremap <M-p> <C-o>:cprevious<CR>
inoremap <C-M-s> <C-o>:call <SID>StartSearch('/')<CR><C-o>/
inoremap <C-M-r> <C-o>:call <SID>StartSearch('?')<CR><C-o>?
inoremap <M-s> <C-o>:set invhls<CR>
inoremap <M-%> <C-o>:call <SID>QueryReplace()()<CR>
inoremap <C-M-%> <C-o>:call <SID>QueryReplace()_regexp()<CR>
cnoremap <C-r> <CR><C-o>?<Up>
command! QueryReplace :call <SID>QueryReplace()()
command! QueryReplaceRegexp :call <SID>QueryReplace()_regexp()
LetDefault g:VM_SearchRepeatHighlight 0
function! <SID>StartSearch(search_dir)
let s:incsearch_status = &incsearch
let s:lazyredraw_status = &lazyredraw
set incsearch
cmap <C-c> <CR>
cnoremap <C-s> <CR><C-o>:call <SID>SearchAgain()<CR><C-o>/<Up>
cnoremap <C-r> <CR><C-o>:call <SID>SearchAgain()<CR><C-o>?<Up>
cnoremap <silent> <CR> <CR><C-o>:call <SID>StopSearch()<CR>
cnoremap <silent> <C-g> <C-c><C-o>:call <SID>AbortSearch()<CR>
cnoremap <silent> <Esc> <C-c><C-o>:call <SID>AbortSearch()<CR>
if a:search_dir == '/'
cnoremap <M-s> <CR><C-o>:set invhls<CR><Left><C-o>/<Up>
else
cnoremap <M-s> <CR><C-o>:set invhls<CR><Left><C-o>?<Up>
endif
let s:before_search_mark = <SID>Mark()
endfunction
function! <SID>StopSearch()
cunmap <C-c>
cunmap <C-s>
cunmap <C-r>
cunmap <CR>
cunmap <C-g>
cnoremap <C-g> <C-c>
if exists("s:incsearch_status")
let &incsearch = s:incsearch_status
unlet s:incsearch_status
endif
if g:VM_SearchRepeatHighlight == 1
if exists("s:hls_status")
let &hls = s:hls_status
unlet s:hls_status
endif
endif
endfunction
function! <SID>AbortSearch()
call <SID>StopSearch()
if exists("s:before_search_mark")
execute s:before_search_mark
unlet s:before_search_mark
endif
endfunction
function! <SID>SearchAgain()
if g:VM_SearchRepeatHighlight == 1
if !exists("s:hls_status")
let s:hls_status = &hls
endif
set hls
endif
endfunction