-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
490 lines (427 loc) · 14.4 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
if has('win32') || has('win64')
let $HOME=$USERPROFILE
endif
" On Windows, force use of .viminfo filename instead of _viminfo.
set viminfofile=$HOME/.viminfo
" On Windows, vim defaults to $HOME/vimfiles, but .vim is just fine.
set rtp^=$GOROOT/misc/vim
set rtp^=$HOME/.vim
set rtp+=$HOME/.vim/after
set rtp-=$HOME/vimfiles
set rtp-=$HOME/vimfiles/after
set encoding=utf-8
" Backups
set directory=$HOME/.vimbak//
set backupdir=$HOME/.vimbak//
set backupskip=/tmp/*,/var/tmp/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
set backup writebackup
" Rotate backup suffix on every write
fun! InitBackupSuffix()
let &backupext=strftime("~{%Y%m%dT%H%M}")
endfun
autocmd BufWritePre * call InitBackupSuffix()
set history=200
set suffixes=.bak,~,.o,.obj,.swp
set updatecount=40 " number of characters typed before updating swapfile
set updatetime=1000 " milliseconds before updating swapfile
" If Windows shell integration ("Edit with Vim") throws errors about
" missing functions and plugins, change the following registry key:
" [HKEY_CLASSES_ROOT\*\shell\gvim\command]
" (default) = "path\to\gvim.exe" --cmd "set rtp+=$USERPROFILE/.vim" "%L"
" To disable a plugin, add it's bundle name to the following list
let g:pathogen_disabled = ['vimwiki']
call pathogen#infect()
" Wiki
let g:vimwiki_list = [
\ { 'path': '~/User/Documents/Notes', 'syntax' : 'markdown', 'ext': '.md' }
\ ]
let g:vimwiki_listsyms = ' .x'
let g:vimwiki_listsym_rejected = '-'
let g:vimwiki_ext2syntax = {}
augroup filetypedetect
au! BufRead,BufNewFile */Wiki/* set filetype=vimwiki
augroup END
if !has('gui_running')
" Request terminal info; response is returned in v:termresponse
silent echo &t_RV
endif
" Map a key in all modes
function s:map_all(mapping) " {{{
exec 'map' a:mapping
exec 'map!' a:mapping
endfunction " }}}
" Map a key that intentionally escapes insert mode
function s:map_force_normal(from, to) " {{{
exec 'nmap <silent>' a:from a:to
exec 'imap <silent>' a:from '<Esc>'.a:to
endfunction " }}}
" Windows terminal config {{{
if &term == "win32"
" Enable 256 colours.
let &t_Co=256
endif
" }}}
" Mintty terminal config {{{
if v:termresponse =~ ">77;"
" mintty: Avoid spurious CSI.
let &t_ti.="\e[?7727h"
let &t_te.="\e[?7727l"
map <Esc>O[ <Esc>
imap <Esc>O[ <Esc>
cmap <Esc>O[ <C-c>
" mintty: Mappings are not respected in paste mode, so switch back to
" normal <Esc> handling to make sure we can exit insert/command modes.
au OptionSet paste :if &paste | exe "silent !echo -ne \e[?7727l" | else | exe "silent !echo -ne \e[?7727h" | endif
" mintty: Map C-Tab/C-S-Tab key codes
set <F13>=[9;5u
set <F14>=[1;6Z
set <F15>=[48;5u " Ctrl,0
set <F16>=[45;5u " Ctrl,-
set <F17>=[61;5u " Ctrl,+
call s:map_all('<F13> <C-Tab>')
call s:map_all('<F14> <C-S-Tab>')
call s:map_all('<F15> :silent !echo -ne "\e]7770;\e\\"<cr>')
call s:map_all('<F16> :silent !echo -ne "\e]7770;-1\e\\"<cr>')
call s:map_all('<F17> :silent !echo -ne "\e]7770;+1\e\\"<cr>')
endif
" }}}
" Mode cursor {{{
let &t_ti.="\e[1 q"
let &t_SR.="\e[3 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
" }}}
" Copy yanked text into system clipboard on WSL
if has('linux') && system('uname -r') =~ "[Mm]icrosoft"
" Workaround for vim sometimes starting in replace mode when it receives an
" ambiguous utf8 character in response to cursor position request (WSL only)
" See: https://superuser.com/a/1525060
set t_u7=
augroup Yank
autocmd!
autocmd TextYankPost * :call system('clip.exe ',@")
augroup END
endif
" No modelines for security reasons [http://www.guninski.com/vim1.html]
set modelines=0
set nocompatible
set secure " don't allow FS modifications in CWD .vimrc/.exrc
set autoindent smartindent " sane indenting
set tw=98
set ts=2
set sw=2
set sts=2
set expandtab " make sure that ^T, <<, >>, and the like use spaces
set formatoptions=cjlq
set cinoptions=l1,g0.5s,h0.5s,i2s,+2s,(0,W2s
" Relative line numbers in normal mode
set nu
set rnu
au BufEnter * :set rnu
au BufLeave * :set nornu
au WinEnter * :set rnu
au WinLeave * :set nornu
au InsertEnter * :set nornu
au InsertLeave * :set rnu
au FocusLost * :set nornu
au FocusGained * :set rnu
set visualbell t_vb=
" Use system clipboard for yank/paste
set clipboard=unnamed
set colorcolumn=89,99
set cursorline
set mouse=a
set noerrorbells
set nowrap
set nohidden " close the buffer when I close a tab
set noautowrite " don't automagically write on :next
set lazyredraw " don't redraw when don't have to
set ttyfast
set showcmd
set showmatch
set noshowmode
set ruler
set incsearch " incremental search
set hlsearch " highlight previous search results
set diffopt+=vertical " always arrange diff windows vertically
set backspace=indent,eol,start
set matchpairs+=<:> " add < and > to match pairs
set whichwrap+=<,>,[,] " cursor keys wrap too
set wildmode=longest:full,full " *wild* mode
set wildignore+=*.o,*~,.lo,*.pyc,*.class,.git
set wildmenu " menu has tab completion
let mapleader=',' " shortcuts start with ,
let maplocalleader=','
set laststatus=2
set foldmethod=marker
syn on " enable syntax coloring
filetype on " enable filetype detection
filetype indent on " enable filetype-specific indenting
filetype plugin on " enable filetype-specific plugins
" Make it so that tabs and trailing spaces are always visible.
set list
set listchars=tab:⌐\ ,trail:·,nbsp:·,extends:»,precedes:«
set fillchars+=vert:│
" Customise syntax highlighting {{{
set background=dark
colorscheme off
" Non-syntax elements
hi Folded guibg=#303030 ctermbg=236
hi ColorColumn guibg=#303030 ctermbg=236
hi CursorLineNr guifg=#F3E430 guibg=NONE ctermfg=11 ctermbg=NONE
hi LineNr guifg=#545454 guibg=NONE ctermfg=240 ctermbg=NONE
hi Visual guibg=#424242 guifg=#F1F1F1 ctermbg=8 ctermfg=15
" Syntax elements
hi Comment guifg=#545454 guibg=NONE ctermfg=240 ctermbg=NONE
hi SpecialKey guifg=#E32791 guibg=NONE ctermfg=1 ctermbg=NONE
hi String guibg=#303030 guifg=NONE ctermbg=236 ctermfg=NONE
hi! link Todo Special
if version >= 700
hi SpellBad guisp=#cc0000 gui=undercurl guifg=NONE guibg=NONE ctermfg=Red ctermbg=NONE cterm=underline term=underline
hi SpellCap guisp=#cf6a4c gui=undercurl guifg=NONE guibg=NONE ctermfg=Red ctermbg=NONE cterm=underline term=underline
hi SpellRare guisp=#cc00cc gui=undercurl guifg=NONE guibg=NONE ctermfg=Magenta ctermbg=NONE cterm=underline term=underline
hi SpellLocal guisp=#cc00cc gui=undercurl guifg=NONE guibg=NONE ctermfg=Magenta ctermbg=NONE cterm=underline term=underline
hi Search guisp=#fcdc00 gui=underline guifg=NONE guibg=NONE ctermfg=Yellow ctermbg=Black cterm=underline term=underline
hi IncSearch guisp=NONE gui=NONE guifg=#000000 guibg=#fcdc00 ctermfg=Black ctermbg=Yellow cterm=NONE term=NONE
endif
" highlight help file links
hi! link helpHyperTextEntry String
hi! link helpHyperTextJump String
" }}}
" Customise status line (lightline) {{{
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['ctrlp_modes'] ],
\ 'right': [ [ 'lineinfo' ], ['percent'], [ 'fileformat', 'fileencoding', 'filetype', 'ctrlp_flags' ] ]
\ },
\ 'component_function': {
\ 'fugitive': 'LightLineFugitive',
\ 'filename': 'LightLineFilename',
\ 'fileformat': 'LightLineFileformat',
\ 'filetype': 'LightLineFiletype',
\ 'fileencoding': 'LightLineFileencoding',
\ 'mode': 'LightLineMode',
\ 'ctrlp_modes': 'LightLineCtrlpModes',
\ 'ctrlp_flags': 'LightLineCtrlpFlags',
\ },
\ 'mode_map': {
\ 'n' : 'N',
\ 'c' : 'C',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'v' : 'V',
\ 'V' : 'V',
\ '\<C-v>': 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '\<C-s>': 'S',
\ '?' : ' '
\ }}
let g:lightline.separator = { 'left': '', 'right': '' }
let g:lightline.subseparator = { 'left': '', 'right': '' }
function! LightLineModified()
return &ft =~ 'help\|vimfiler' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
function! LightLineReadonly()
return &ft !~? 'help\|vimfiler' && &readonly ? '' : ''
endfunction
function! LightLineFilename()
let fname = expand('%:t')
if fname =~ 'ControlP'
return g:lightline.ctrlp_item
endif
return ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ (&ft == 'vimfiler' ? vimfiler#get_status_string() :
\ &ft == 'vimshell' ? vimshell#get_status_string() :
\ fname != '' ? fname : '[No Name]') .
\ ('' != LightLineModified() ? ' ' . LightLineModified() : '')
endfunction
function! LightLineFugitive()
if &ft !~? 'vimfiler' && exists('*FugitiveHead')
let _ = FugitiveHead()
return strlen(_) ? ' '._ : ''
endif
return ''
endfunction
function! LightLineFileformat()
return expand('%:t') =~ 'ControlP' ? '' : winwidth(0) > 70 ? &fileformat : ''
endfunction
function! LightLineFiletype()
return expand('%:t') =~ 'ControlP' ? '' : winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
endfunction
function! LightLineFileencoding()
return expand('%:t') =~ 'ControlP' ? '' : winwidth(0) > 70 ? (strlen(&fenc) ? &fenc : &enc) : ''
endfunction
function! LightLineMode()
let fname = expand('%:t')
if fname =~ 'ControlP'
call lightline#link('nR'[g:lightline.ctrlp_regex])
return '^P'
endif
return &ft == 'help' ? 'Help' :
\ &ft == 'vimfiler' ? 'Filer' :
\ &ft == 'vimshell' ? 'Shell' : lightline#mode()
endfunction
function! LightLineCtrlpModes()
let fname = expand('%:t')
if fname =~ 'ControlP'
return lightline#concatenate([g:lightline.ctrlp_next, g:lightline.ctrlp_prev], 0)
else
return ''
endif
endfunction
function! LightLineCtrlpFlags()
let fname = expand('%:t')
if fname =~ 'ControlP'
return lightline#concatenate([g:lightline.ctrlp_regex, g:lightline.ctrlp_file], 1)
else
return ''
endif
endfunction
" }}}
" Customise ctrl-p {{{
let g:ctrlp_prompt_mappings = {
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ }
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files . -co --exclude-standard']
let g:ctrlp_status_func = {
\ 'main': 'CtrlPStatusFunc_1',
\ 'prog': 'CtrlPStatusFunc_2',
\ }
function! CtrlPStatusFunc_1(focus, byfname, regex, prev, item, next, marked)
let g:lightline.ctrlp_regex = (a:regex == 1 ? 'regex' : '')
let g:lightline.ctrlp_file = a:byfname
let g:lightline.ctrlp_prev = a:prev
let g:lightline.ctrlp_item = a:item
let g:lightline.ctrlp_next = a:next
return lightline#statusline(0)
endfunction
function! CtrlPStatusFunc_2(str)
return lightline#statusline(0)
endfunction
" }}}
" Disable quote concealing in json files (vim-json)
let g:vim_json_syntax_conceal = 0
" Load per-project vimrc files
let g:localvimrc_ask = 0
let g:jsx_ext_required = 0
if has("gui_running")
set lines=40 columns=160
set linespace=0
set showtabline=2 " always show tabs
" On Windows, must be executed before gui is shown (.gvimrc is too late).
set guioptions=ce
" Input font settings:
" --asterisk=height
" --i=serifs_round
" --l=serifs_round
" --zero=slash
" --lineHeight=1.3
set gfn=InputMono:h10
end
if !has('gui_running')
set ttimeoutlen=100
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" ---------------------------------------------------------------------------
" Shortcuts
"
" Avoid accidental scroll after shifted commands
map <S-Up> <Up>
map <S-Down> <Down>
map <S-Left> <Left>
map <S-Right> <Right>
imap <S-Up> <Up>
imap <S-Down> <Down>
imap <S-Left> <Left>
imap <S-Right> <Right>
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" don't use ex mode, use Q for macro recording
nnoremap Q q
nnoremap q <Nop>
" yank to end of line
map Y y$
" correct typos on write and exit
nmap q: :q
" clear search
nmap <leader>/ :noh<cr>
" toggle buffers
nmap <leader><leader> :b#<cr>
" toggle paste mode
nmap <leader>p :set paste!<cr>
" toggle wrapping
nmap <leader>w :set wrap!<cr>
" toggle list mode
nmap <leader>l :set list!<cr>
" get rid of trailing whitespace
map <leader>d :s/[ <Tab>]\+$//<cr>
map <leader>D :%s/[ <Tab>]\+$//<cr>
" insert timestamp at current cursor position
nmap <leader>t :r! date "+\%Y-\%m-\%d \%T\%Z"<cr>
nmap <leader>T :-1r! date "+\%Y-\%m-\%d \%T\%Z"<cr>
" fuzzy find
map <leader>f :CtrlP<cr>
map <leader>F :CtrlPClearCache<cr>\|:CtrlP<cr>
" highlight stack via hilinks
let g:hilinks_fmtwidth = 30
let g:hilinks_nobeval = 1
" ugh!
silent! unmap <leader>hlt
map <silent> <leader>hl :call <SNR>34_HiLinkTrace(0)<CR>
" Switch windows easily
nmap <silent> <leader><Tab> <C-w><C-w>
" Cycle tabs with ctrl-tab and ctrl-shift-tab (gvim only)
call s:map_force_normal('<C-Tab>', 'gt')
call s:map_force_normal('<C-S-Tab>', 'gT')
call s:map_force_normal('<F2>', 'gT')
call s:map_force_normal('<F3>', 'gt')
" Switch to a specific tab with number shortcut
call s:map_force_normal('<C-1>', '1gt')
call s:map_force_normal('<C-2>', '2gt')
call s:map_force_normal('<C-3>', '3gt')
call s:map_force_normal('<C-4>', '4gt')
call s:map_force_normal('<C-5>', '5gt')
call s:map_force_normal('<C-6>', '6gt')
call s:map_force_normal('<C-7>', '7gt')
call s:map_force_normal('<C-8>', '8gt')
call s:map_force_normal('<C-9>', '9gt')
" Spelling
nmap <F7> :setlocal invspell<cr>
imap <silent> <F7> <C-O>:silent setlocal invspell<cr>
" Diff with saved version of the file
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
" Settings for NERDTree
map <silent> <F4> :NERDTreeToggle<cr>
let NERDTreeDirArrows=0
let NERDTreeMinimalUI=1
let NERDTreeQuitOnOpen=1
let NERDTreeShowBookmarks=1
let NERDTreeWinSize=40
" Autoload commands
if has("autocmd")
autocmd BufRead *.as set filetype=actionscript
autocmd BufRead *.mxml set filetype=mxml
" When editing a file, always jump to the last cursor position
autocmd BufReadPost * if line("'\"") | exe "'\"" | endif
" Use 4-space indentation for markdown
autocmd FileType markdown setlocal et ts=4 sw=4 sts=4
" Use tabs for makefiles
autocmd FileType make setlocal noet ts=2 sw=2 sts=2
" Use tabs for go
autocmd FileType go setlocal noet ts=2 sw=2 sts=2
endif