-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
456 lines (378 loc) · 11 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
set encoding=utf-8
scriptencoding utf-8
augroup vimrc
autocmd!
augroup END
" Shell "{{{
if &shell =~# 'fish$'
set shell=sh
endif
" Shell "}}}
" Terminal "{{{
" Modern terminals must be able to print UTF-8 characters!
let g:term_utf8 = 1
if &term == 'dumb' || &term == 'linux'
let g:term_utf8 = 0
endif
" T_RBG passing though screen/tmux.
if exists('&t_RB')
if exists('$TMUX')
" https://github.com/vim/vim/issues/7867#issuecomment-781799099
let &t_RB = "\ePtmux;\e\e]11;?\007\e\\"
elseif $TERM =~ "screen"
let &t_RB = "\eP\e]11;?\x07\e\\"
endif
endif
" Usually, the color mode and background color are guessed correctly, but when
" it doesn't work, we use $VIM_256COLOR and $VIM_BACKGROUND to adjust them.
if exists('$VIM_256COLOR')
set t_Co=256
endif
if exists('$VIM_BACKGROUND')
let &background = $VIM_BACKGROUND
endif
" GNU screen.
if &term =~ 'screen'
set ttymouse=xterm2
set t_ts=]2; " set window title start (to status line)
set t_fs= " set window title end (from status line)
" Fix keycods.
map OH <Home>
map OF <End>
map! OH <Home>
map! OF <End>
map [1~ <Home>
map [4~ <End>
imap [1~ <Home>
imap [4~ <End>
endif
"}}}
" General behaviour "{{{
set backspace=indent,eol,start
set fileformats=unix,dos,mac
set hidden
set mouse=a
set showcmd
set showmatch
set visualbell t_vb= " no beep or flash
set whichwrap=b,s,<,>,[,]
set wildmenu
set wildmode=full
set wildignore+=*.o,*.exe
set wildignore+=*.pyc,*.pyo,*/__pycache__/*
set wildignore+=CMakeCache.txt,*/CMakefiles/*,CTestTestfile.cmake,cmake_install.cmake
set wildignore+=gradlew,gradlew.bat
set wildignore+=*.aux,*.ax1,*.ax2,*.bbl,*.blg,*.fls,*.spl,*.toc
set wildignore+=*.nav,*.spl,*.snm,*.vrb
set wildignore+=*.dvi,*.pdf
" Automatically reload files.
" https://stackoverflow.com/a/50476532/9105334
" https://stackoverflow.com/a/48296697/9105334
set autoread
function! Checktime() abort
let l:winview = winsaveview()
checktime
call winrestview(l:winview)
endfunction
augroup vimrc
autocmd CursorHold,FocusGained,BufEnter * call Checktime() | call feedkeys('lh')
augroup END
" Prevent a delay when pressing ESC.
if !has('gui_running')
set notimeout
set ttimeout
set timeoutlen=10
augroup vimrc
autocmd InsertEnter * set timeout
autocmd InsertLeave * set notimeout
augroup END
endif
" Close Quickfix window when no other windows.
" http://hail2u.net/blog/software/vim-auto-close-quickfix-window.html
autocmd vimrc WinEnter * if (winnr('$') == 1) && (getbufvar(winbufnr(0), '&buftype')) == 'quickfix' | quit | endif
" Automatically change the current directory
"autocmd BufEnter * silent! lcd %:p:h
"}}}
" View "{{{
set nocursorline
set number
set ruler
set title
set nowrap
if g:term_utf8
set list
execute "set listchars=tab:› ,eol:⇂,extends:»,precedes:«"
else
set nolist
endif
if exists('&ambiwidth')
set ambiwidth=double
endif
if exists('+colorcolumn')
set colorcolumn=81
endif
if exists('&breakindent')
set breakindent
endif
"}}}
" Searching "{{{
set hlsearch
set incsearch
set ignorecase
set smartcase
set nowrapscan
" Hide search highlights when ESC pressed twice.
nmap <silent> <Esc><Esc> :nohlsearch<CR><Esc>
"}}}
" Indent "{{{
set autoindent
set nocindent
set smartindent
set nosmarttab
" TabIndent <tabwidth>
" SpaceIndent <tabwidth>
command! -nargs=1 TabIndent setlocal noexpandtab shiftwidth=<args> softtabstop=0 tabstop=<args>
command! -nargs=1 SpaceIndent setlocal expandtab shiftwidth=<args> softtabstop=<args> tabstop=8
" Default indent (SpaceIndent 2)
set expandtab shiftwidth=2 softtabstop=2 tabstop=8
"}}}
" Spell checking "{{{
set spell
" Disable the spell checker for Japanese.
if v:version > 704 || (v:version == 704 && has('patch89'))
set spelllang+=cjk
endif
" Disable the spell checker for Japanese.
function! DisableSpellCheckCJK()
if v:version > 704 || (v:version == 704 && has('patch89'))
setlocal spelllang+=cjk
endif
endfunction
" Slow, but accurate.
function! SpellPrecisely()
syntax sync fromstart
endfunction
" Sort *.add files.
function! SpellFileSort()
for f in glob('~/.vim/spell/*.add', 1, 1)
if filereadable(f)
execute '!sort -u -o ' . fnameescape(f) . ' ' . fnameescape(f)
endif
endfor
endfunction
" Rebuild *.add.spl files.
function! SpellFileRebuild()
for f in glob('~/.vim/spell/*.add', 1, 1)
if filereadable(f) && (!filereadable(f . '.spl') || getftime(f) > getftime(f . '.spl'))
execute 'mkspell! ' . fnameescape(f)
endif
endfor
endfunction
command! SpellCheck call SpellPrecisely()
command! SpellCheckGB setlocal spell spelllang=en_gb
\ | call DisableSpellCheckCJK()
\ | call SpellPrecisely()
command! SpellCheckUS setlocal spell spelllang=en_us
\ | call DisableSpellCheckCJK()
\ | call SpellPrecisely()
"}}}
" Key mappings "{{{
" C-A -> Start of line, C-E -> End of line
map <C-a> <Home>
map <C-e> <End>
map! <C-a> <Home>
map! <C-e> <End>
" C-S: Save the file.
nmap <c-s> :update<CR>
imap <c-s> <Esc>:update<CR>a
"}}}
" File type detection "{{{
augroup vimrc
autocmd BufNewFile,BufRead *.m setlocal filetype=mma
autocmd BufNewFile,BufRead * call DetectFileType()
augroup end
function! DetectFileType()
let l = getline(1)
" Shebang
if l =~ '^#!'
if l =~ '\<sh\>'
for i in range(2, 10)
let l = getline(i)
if l =~ 'exec \+perl'
setlocal filetype=perl
return
endif
if l =~ 'exec \+python'
setlocal filetype=python
return
endif
if l =~ 'exec \+ruby'
setlocal filetype=ruby
return
endif
endfor
setlocal filetype=sh
return
endif
if l =~ '\<bash\>'
setlocal filetype=sh
return
endif
if l =~ '\<perl\>'
setlocal filetype=perl
return
endif
if l =~ '\<python\>'
setlocal filetype=python
return
endif
if l =~ '\<ruby\>'
setlocal filetype=ruby
return
endif
endif
" Emacs file mode
if l =~ '-\*-.*-\*-'
if l =~ '-\*-.*\<c\>.*-\*-'
set filetype=c
return
endif
if l =~ '-\*-.*\<fortran\>.*-\*-'
set filetype=fortran
return
endif
if l =~ '-\*-.*\<form\>.*-\*-'
set filetype=form
return
endif
if l =~ '-\*-.*\<reduce\>.*-\*-'
set filetype=reduce
return
endif
endif
endfunction
"}}}
" File type specific settings "{{{
augroup vimrc
autocmd FileType automake execute 'TabIndent 4'
autocmd FileType fortran setlocal colorcolumn=73
autocmd FileType gitcommit setlocal colorcolumn=73
autocmd FileType java setlocal colorcolumn=101
autocmd FileType make execute 'TabIndent 4'
autocmd FileType python execute 'SpaceIndent 4' | setlocal colorcolumn=80 | setlocal foldcolumn=4
autocmd FileType qf setlocal colorcolumn=0
autocmd FileType rust setlocal colorcolumn=101
autocmd FileType tex setlocal colorcolumn=81 | setlocal foldcolumn=4
autocmd FileType unite highlight link ExtraWhitespace Normal
autocmd BufNewFile,BufRead *.tex setlocal filetype=tex
autocmd BufNewFile,BufRead *.dtx setlocal colorcolumn=73
autocmd BufNewFile,BufRead *.ins setlocal colorcolumn=73
" FORM sources
autocmd BufNewFile,BufRead */form*/sources/*.c call FORMCSource()
autocmd BufNewFile,BufRead */form*/sources/*.cc call FORMCSource()
autocmd BufNewFile,BufRead */form*/sources/*.h call FORMCSource()
autocmd BufNewFile,BufRead */form*/configure.ac execute 'TabIndent 4'
augroup end
function! FORMCSource()
execute 'TabIndent 4'
setlocal foldmethod=marker foldmarker=#[,#] foldcolumn=4
endfunction
"}}}
" Some commands "{{{
command! RemoveCarriageReturn %s///g
command! RemoveTrailingWhitespace %s/[ ]\+$//g
command! Dark set background=dark
command! Light set background=light
command! NoList set nolist
command! C setlocal filetype=c
command! CC setlocal filetype=cpp
command! F setlocal filetype=fortran
command! F77 let b:fortran_fixed_source=1 | setlocal filetype=fortran | setlocal colorcolumn=73
command! F90 let b:fortran_fixed_source=0 | setlocal filetype=fortran | setlocal colorcolumn=133
command! Fortran setlocal filetype=fortran
command! FORM setlocal filetype=form
command! MMA setlocal filetype=mma
command! REDUCE setlocal filetype=reduce
command! TeX setlocal filetype=tex
command! ReopenAsEUCJP e ++enc=euc-jp
command! ReopenAsSJIS e ++enc=sjis
command! ReopenAsUTF8 e ++enc=utf-8
" Use FORM foldings.
function! FORMFold()
if &foldmethod == "manual"
setlocal foldmethod=marker foldmarker=#[,#] foldcolumn=4
elseif &foldmethod == "marker"
setlocal foldmethod=manual foldmarker={{{,}}} foldcolumn=0
else
if &foldcolumn == 0
setlocal foldcolumn=4
elseif &foldcolumn == 4
setlocal foldcolumn=0
endif
endif
endfunction
command! Z call FORMFold()
" Add the mode line to the file.
function! s:AppendModeLine()
if &expandtab == 0
let l:et = "noet"
else
let l:et = "et"
endif
let l:modeline = printf("ft=%s %s ts=%d sts=%d sw=%d",
\ &filetype, l:et, &tabstop, &softtabstop, &shiftwidth)
if &filetype == "cpp"
let l:modeline = printf("// vim: %s", l:modeline)
elseif &filetype == "form"
let l:modeline = printf("* vim: %s", l:modeline)
elseif &filetype == "tex"
let l:modeline = printf("%% vim: %s", l:modeline)
elseif &filetype == "sh" || &filetype == "perl" || &filetype == "python" || &filetype == "ruby"
let l:modeline = printf("# vim: %s", l:modeline)
elseif &filetype == "vim"
let l:modeline = printf("\" vim: %s", l:modeline)
elseif &filetype == "mma" " strange &commentstring @ v7.3.62
let l:modeline = printf("(* vim: set %s: *)", l:modeline)
else
let l:modeline = printf(" vim: set %s: ", l:modeline)
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
endif
call append(line("$"), l:modeline)
endfunction
command! AppendModeLine call s:AppendModeLine()
" CD = Change to the directory of the current file
command! CD cd %:p:h
"}}}
" Plugins "{{{
if v:version >= 800
let s:dein_dir = expand('~/.cache/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
" Clone dein.vim if not found.
if &runtimepath !~# '/dein.vim'
if !isdirectory(s:dein_repo_dir)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
endif
execute 'set runtimepath+=' . fnamemodify(s:dein_repo_dir, ':p')
endif
if dein#load_state(s:dein_dir)
call dein#begin(s:dein_dir)
let s:rc_dir = expand('~/.vim')
let s:toml = s:rc_dir . '/dein.toml'
let s:lazy_toml = s:rc_dir . '/dein_lazy.toml'
call dein#load_toml(s:toml, {'lazy': 0})
call dein#load_toml(s:lazy_toml, {'lazy': 1})
" For developing plugins.
" call dein#local(s:rc_dir . '/bundle')
call dein#end()
call dein#save_state()
endif
if has('vim_starting') && dein#check_install()
call dein#install()
endif
endif
"}}}
filetype plugin indent on
syntax on
set secure
" vim: ft=vim et ts=8 sts=2 sw=2 fdm=marker fmr={{{,}}} fdc=4