-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
759 lines (622 loc) · 16.8 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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
"
" ~/.vimrc
"
" Environment variables =========================================== {{{
if empty($XDG_CACHE_HOME)
let $XDG_CACHE_HOME=expand("$HOME/.cache")
endif
" }}}
" Vundle configuration ============================================ {{{
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" plugins
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'sirver/UltiSnips'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-fugitive'
Plugin 'tommcdo/vim-exchange'
Plugin 'sjl/splice.vim'
Plugin 'rking/ag.vim'
Plugin 'sjl/gundo.vim'
Plugin 'sjbach/lusty'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
Plugin 'scrooloose/syntastic'
Plugin 'ciaranm/securemodelines'
Plugin 'majutsushi/tagbar'
Plugin 'Shougo/neocomplete.vim'
Plugin 'Konfekt/FastFold'
Plugin 'lyuts/vim-rtags'
" language plugins
Plugin 'rust-lang/rust.vim'
Plugin 'racer-rust/vim-racer'
Plugin 'derekwyatt/vim-scala'
Plugin 'fatih/vim-go'
Plugin 'alisdair/vim-armasm'
" filetype plugins
Plugin 'hallison/vim-markdown'
Plugin 'kurayama/systemd-vim-syntax'
Plugin 'leshill/vim-json'
Plugin 'ekalinin/Dockerfile.vim'
Plugin 'cespare/vim-toml'
Plugin 'tfnico/vim-gradle'
" color themes
Plugin 'jpo/vim-railscasts-theme'
Plugin 'jnurmine/Zenburn'
Plugin 'tomasr/molokai'
Plugin 'zeis/vim-kolor'
Plugin 'fugalh/desert.vim'
Plugin 'cdaddr/gentooish.vim'
Plugin 'vim-scripts/oceandeep'
Plugin 'chriskempson/base16-vim'
Plugin 'dracula/vim'
Plugin 'nanotech/jellybeans.vim'
Plugin 'fxn/vim-monochrome'
Plugin 'xero/blaquemagick.vim'
call vundle#end()
filetype plugin indent on
augroup ft_vundle
au!
au FileType vundle nnoremap q ZZ
augroup END
" }}}
" General ========================================================= {{{
set encoding=utf-8
set showcmd
set showmode
set ttyfast
set ruler
set history=500
set laststatus=2
set autoindent
set hidden
set backspace=indent,eol,start
set visualbell
set notimeout
set ttimeout
set ttimeoutlen=10
set synmaxcol=600
set scrolloff=5 "Scroll when X lines from top/bottom
set sidescroll=1
set sidescrolloff=10
set cmdheight=2
set guioptions-=m
set guioptions-=T
set guioptions-=r
set guioptions-=L
" disable modeline, use SecureModelines
set modelines=0
set nomodeline
" Autosave on focus lost
au FocusLost * silent! wa
" Resize on window resize
au VimResized * :wincmd =
" Configure % key (via matchit plugin)
set matchpairs+=<:>,«:»
" please, fix my typos!
command! -bang Q q<bang>
command! -bang W w<bang>
command! -bang E e<bang>
command! -bang Qa qa<bang>
command! -bang QA qa<bang>
command! -bang Wq wq<bang>
command! -bang WQ wq<bang>
" }}}
" Cursor Line ===================================================== {{{
" Only show cursorline in current win
augroup cursor_line
au!
au WinLeave,InsertEnter * set nocursorline
au WinEnter,InsertLeave * set cursorline
augroup END
set cursorline
" }}}
" Line numbers ==================================================== {{{
augroup line_numbers
au!
au FocusGained,WinEnter,InsertLeave * call SaveRelative()
au FocusLost,WinLeave,InsertEnter * call SaveNumber()
augroup END
set relativenumber
function! SaveRelative()
if &number || &relativenumber
set relativenumber
endif
endfunction
function! SaveNumber()
if &number || &relativenumber
set number
endif
endfunction
function! SaveToggleNumber()
if &number || &relativenumber
if &number
set relativenumber
elseif &relativenumber
set number
endif
endif
endfunction
" }}}
" Line Return ===================================================== {{{
" Make sure Vim returns to the same line when you reopen a file.
" https://github.com/sjl/dotfiles/blob/master/vim/vimrc
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
"}}}
" Whitespace, wrapping stuff ====================================== {{{
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
"set showbreak=↪
" long lines
set wrap
set linebreak
set textwidth=80
set formatoptions=qrn1
set colorcolumn=81
command! -nargs=* Wrap set wrap linebreak nolist
set listchars=tab:▸\ ,extends:❯,precedes:❮,trail:␣
set list
"set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮,trail:␣
"
"augroup show_list
" au!
" au InsertEnter * set list
" au InsertLeave * set nolist
"augroup END
" }}}
" Leader ========================================================== {{{
let mapleader = ","
let maplocalleader = "\\"
" }}}
" Basic Keybindings =============================================== {{{
nnoremap ; :
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
inoremap jk <ESC>
" Don't move cursor!
nnoremap J mzJ`z
" surround with whitespace
map <leader><SPACE> ysiw(ds)
" surround with "
map <leader>" ysiw"
" save
nnoremap <leader>s :w!<CR>
" hex
nnoremap <Leader>hon :%!xxd<CR>
nnoremap <Leader>hof :%!xxd -r<CR>
" }}}
" Movement ======================================================== {{{
noremap j gj
noremap k gk
noremap gj j
noremap gk k
noremap H ^
noremap L $
vnoremap L g_
" center
nnoremap g, g,zz
nnoremap g; g;zz
" Move screen down and center cursor
nnoremap <C-D> <C-D>M
nnoremap <C-U> <C-U>M
" UltiSnips
let g:UltiSnipsJumpForwardTrigger="<C-j>"
let g:UltiSnipsJumpBackwardTrigger="<C-k>"
" }}}
" Searching ======================================================= {{{
set incsearch
set ignorecase
set smartcase
set showmatch
set hlsearch
set gdefault
nnoremap / /\v
vnoremap / /\v
nnoremap <silent> <leader>, :noh<CR>
" Keep search in the middle of the window
nnoremap n nzzzv
nnoremap N Nzzzv
" don't move!
nnoremap * *<C-o>
" search files for word under cursor
nnoremap <C-f> :execute "vimgrep /" . expand("<cword>") . "/j **" <Bar> cw<CR>
nnoremap <leader>k :cn<CR>
nnoremap <leader>j :cp<CR>
" }}}
" Windows ========================================================= {{{
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>w <C-w>s<C-w>j
nmap <C-left> :wincmd h<CR>
nmap <C-right> :wincmd l<CR>
nmap <C-up> :wincmd k<CR>
nmap <C-down> :wincmd j<CR>
nmap <S-left> <C-w>H
nmap <S-right> <C-w>L
nmap <S-up> <C-w>K
nmap <S-down> <C-w>j
" }}}
" Quickfix ======================================================== {{{
" http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
command! -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
unlet g:qfix_win
else
copen 10
let g:qfix_win = bufnr("$")
endif
endfunction
nmap <silent><leader>q :QFix<CR>
" }}}
" Backups ========================================================= {{{
set backup
set backupext=.bak
set noswapfile
set undofile
set undoreload=10000
set viminfo+=n$XDG_CACHE_HOME/vim/viminfo
set undodir=$XDG_CACHE_HOME/vim/undofiles
set backupdir=$XDG_CACHE_HOME/vim/backup
set directory=$XDG_CACHE_HOME/vim
set viewdir=$XDG_CACHE_HOME/vim/viewfiles
" delete old files
if filereadable(expand("$HOME/.viminfo"))
call delete(expand("$HOME/.viminfo"))
endif
" create directories
if !isdirectory(&undodir)
call mkdir(&undodir, "p")
endif
if !isdirectory(&backupdir)
call mkdir(&backupdir, "p")
endif
if !isdirectory(&directory)
call mkdir(&directory, "p")
endif
if !isdirectory(&viewdir)
call mkdir(&viewdir, "p")
endif
" }}}
" Colors / Font / Statusline ====================================== {{{
syntax on
if has("gui_running")
" colorscheme zenburn
colorscheme kolor
set guifont=Hack\ 10
else
" colorscheme monochrome
" colorscheme kolor
colorscheme blaquemagick
endif
hi User1 guifg=#eea040 guibg=#303030 ctermfg=172 ctermbg=236
hi User2 guifg=#dd3333 guibg=#303030 ctermfg=196 ctermbg=236
hi User3 guifg=#4682b4 guibg=#303030 ctermfg=12 ctermbg=236
hi User4 guifg=#a0ee40 guibg=#303030 ctermfg=70 ctermbg=236
hi User5 guifg=#eeee40 guibg=#303030 ctermfg=184 ctermbg=236
set statusline=
set statusline +=%1*\ %n\ %* "buffer number
set statusline +=%5*%{&ff}%* "file format
set statusline +=%1*\ (%{strlen(&fenc)?&fenc:'none'}) "file encoding
set statusline +=%3*\ %y%* "file type
set statusline +=%4*\ %<%F%* "full path
set statusline +=%2*%m%* "modified flag
set statusline +=%1*%=%5l%* "current line
set statusline +=%2*/%L%* "total lines
set statusline +=%1*%4v\ %* "virtual column number
set statusline +=%2*0x%04B\ %* "character under cursor
" }}}
" Folding ========================================================= {{{
set foldlevelstart=99
" toggle folds
nnoremap <silent> <Space> za
vnoremap <silent> <Space> za
" open all
nnoremap ZR zR
vnoremap ZR zR
" close all
nnoremap ZM zM
vnoremap ZM zM
" toggle recursive
nnoremap ZA zA
vnoremap ZA zA
nnoremap <silent> z0 zM
nnoremap <silent> z1 :set foldlevel=1<CR>
nnoremap <silent> z2 :set foldlevel=2<CR>
nnoremap <silent> z3 :set foldlevel=3<CR>
nnoremap <silent> z4 :set foldlevel=4<CR>
nnoremap <silent> z5 :set foldlevel=5<CR>
nnoremap <silent> z9 zR
set viewoptions=folds,cursor
" }}}
" Wildmenu ======================================================== {{{
set wildmenu
set wildmode=list:longest
set wildignore+=*.aux,*.out,*.toc,*.bbl " latex
set wildignore+=*.pyc " python
" }}}
" Abbreviations =================================================== {{{
" }}}
" Filetype stuff ================================================== {{{
" c {{{
augroup ft_c
au!
au FileType c setlocal ts=4 sts=4 shiftwidth=4 noet tw=120 cc=121
au FileType c setlocal foldmethod=syntax
augroup END
" }}}
" cpp {{{
augroup ft_cpp
au!
au FileType cpp setlocal ts=4 sts=4 shiftwidth=4 noet tw=120 cc=121
au FileType cpp setlocal foldmethod=syntax
augroup END
" }}}
" armasm {{{
augroup ft_armasm
au!
au FileType armasm let g:syntastic_asm_compiler="arm-none-eabi-gcc"
augroup END
" }}}
" go {{{
augroup ft_go
au!
au FileType godoc nnoremap q :close<CR>
au FileType go setlocal ts=8 sts=8 sw=8 tw=120 cc=121 noet
au FileType go setlocal foldmethod=syntax
au FileType go nnoremap <C-F> :GoFmt<CR>
au FileType go noremap <C-F5> :GoTest<CR>
augroup END
" }}}
" python {{{
augroup ft_python
au!
au FileType python setlocal ts=4 sts=4 shiftwidth=4
au FileType python setlocal foldmethod=indent foldlevel=99
au FileType python setlocal ofu=pythoncomplete#Complete cot=menuone,longest
augroup END
" }}}
" ruby {{{
augroup ft_ruby
au!
au FileType ruby setlocal ts=2 sts=2 shiftwidth=2
augroup END
" }}}
" javascript {{{
augroup ft_javascript
au!
au FileType javascript setlocal ts=2 sts=2 shiftwidth=2 expandtab
augroup END
" }}}
" Version control {{{
augroup ft_commit
au!
au FileType svn,*commit* call setpos('.', [0, 1, 1, 0])
au FileType svn,*commit* setlocal spell spelllang=en
augroup END
" }}}
" vim {{{
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" mail {{{
augroup ft_mail
au!
au FileType mail setlocal spell spelllang=en,de
augroup END
" }}}
" tex {{{
augroup ft_tex
au!
let g:tex_flavor='latex'
au FileType tex setlocal spell spelllang=de,en foldmethod=manual
au FileType tex setlocal tw=120 cc=121
augroup END
" }}}
" bashrc {{{
augroup ft_bashrc
au!
au FileType bashrc setlocal syntax=sh foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" zsh {{{
augroup ft_zsh
au!
au FileType zsh setlocal syntax=sh foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" conf {{{
augroup ft_conf
au!
au FileType conf setlocal foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" i3 {{{
augroup ft_i3
au!
au FileType i3 setlocal foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" xdefaults {{{
augroup ft_xdefaults
au!
au FileType xdefaults setlocal foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" sml {{{
augroup ft_sml
au!
au FileType sml setlocal textwidth=120 colorcolumn=121
augroup END
" }}}
" fstab {{{
augroup ft_fstab
au!
au FileType fstab setlocal colorcolumn=0
augroup END
" }}}
" sh {{{
augroup ft_sh
au!
au FileType sh setlocal syntax=sh foldmethod=marker foldmarker={{{,}}}
augroup END
" }}}
" nroff {{{
augroup ft_nroff
au!
au FileType nroff setlocal spell spelllang=en
augroup END
" }}}
" }}}
" Plugins ========================================================= {{{
" SecureModelines {{{
" https://github.com/ciaranm/securemodelines
let g:secure_modelines_verbose = 1
let g:secure_modelines_modelines = 5
let g:secure_modelines_allowed_items = [
\"textwidth", "tw",
\"softtabstop", "sts",
\"tabstop", "ts",
\"shiftwidth", "sw",
\"expandtab", "et",
\"noexpandtab", "noet",
\"autoindent", "ai",
\"noautoindent", "noai",
\"filetype", "ft",
\"fileformat", "ff",
\"fold", "fo",
\"rightleft", "rl",
\"norightleft", "norl",
\"foldmethod", "fdm",
\"foldlevel", "fdl",
\"colorcolumn", "cc",
\"fileencoding", "fenc",
\"spelllang", "spl"
\]
" }}}
" CtrlP {{{
" https://github.com/ctrlpvim/ctrlp.vim
" Match window
let g:ctrlp_match_window = 'bottom,order:btt,min:5,max:30'
" }}}
" UltiSnips {{{
" https://github.com/sirver/UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/UltiSnips']
" }}}
" NERDTree {{{
" https://github.com/scrooloose/nerdtree
noremap <F2> :NERDTreeToggle<CR>:NERDTreeMirror<CR>
inoremap <F2> <ESC>:NERDTreeToggle<CR>:NERDTreeMirror<CR>
let NERDTreeShowBookmarks = 1
let NERDTreeIgnore = ['\.pyc', '\~$', '\.swo$', '\.git', '\.hg', '\.svn', '\.bzr']
let NERDTreeChDirMode = 2
let NERDTreeQuitOnOpen = 0
let NERDTreeShowHidden = 0
let NERDTreeKeepTreeInNewTab = 1
let NERDTreeHighlightCursorline = 1
let NERDTreeMinimalUI = 0
let NERDTreeShowLineNumbers = 0
" start NERDTree automatically when vim starts and no file is specified
augroup nerd_tree
au!
au VimEnter * if !argc() | NERDTree | endif
au BufEnter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
augroup END
" }}}
" Tagbar {{{
" https://github.com/majutsushi/tagbar
noremap <F3> :TagbarToggle<CR>
inoremap <F3> <ESC>:TagbarToggle<CR>
" }}}
" Gundo {{{
" https://github.com/sjl/gundo.vim
noremap <F4> :GundoToggle<CR>
inoremap <F4> <ESC>:GundoToggle<CR>
" width of the graph
let g:gundo_width = 45
" height of the preview window
let g:gundo_preview_height = 20
" show preview window below current window, not below the graph
let g:gundo_preview_bottom = 1
" }}}
" LustyJuggler {{{
" https://github.com/vim-scripts/LustyJuggler
nnoremap <leader>b :LustyJuggler<CR>
" }}}
" syntastic {{{
" https://github.com/scrooloose/syntastic
let g:syntastic_check_on_open = 1
let g:syntastic_python_checker_args = ""
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++11'
" fix possible missbehaviour with vim-go
" https://github.com/fatih/vim-go#using-with-syntastic
let g:syntastic_go_checkers = ['golint', 'govet', 'errcheck']
let g:syntastic_mode_map = { 'mode': 'active', 'passive_filetypes': ['go'] }
let g:syntastic_sh_checkers = ['shellcheck']
let g:syntastic_bash_checkers = ['shellcheck']
" }}}
" Ag {{{
" https://github.com/rking/ag.vim
nnoremap <leader>a :NERDTreeClose<CR>:Ag <cword><CR>
" }}}
" neocomplete {{{
" https://github.com/Shougo/neocomplete.vim
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_auto_close_preview = 1
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<S-TAB>"
inoremap <expr><CR> pumvisible() ? "\<C-y>" : "<CR>"
" }}}
" }}}
" Quick file editing ============================================== {{{
nnoremap <leader>ev :tabedit ~/.vimrc<cr>
nnoremap <leader>ex :tabedit ~/.xinitrc<cr>
nnoremap <leader>eb :tabedit ~/.bashrc<cr>
nnoremap <leader>eg :tabedit ~/.config/git/config<cr>
nnoremap <leader>ei :tabedit ~/.config/i3/config<cr>
" }}}
" Vim help ======================================================== {{{
augroup ft_help
au!
" see: http://vim.wikia.com/wiki/Learn_to_use_help#Simplify_help_navigation
" `Enter` to jump to the subject under cursor
" `Backspace` to return to the previous subject
" `s` to find the next subject
" `S` to find the previous subject
" `o` to find the next option
" `O` to find the previous option
" `q` to close help buffer
au FileType help nnoremap <buffer> <CR> <C-]>
au FileType help nnoremap <buffer> <BS> <C-T>
au FileType help nnoremap <buffer> o /'\l\{2,\}'<CR>
au FileType help nnoremap <buffer> O ?'\l\{2,\}'<CR>
au FileType help nnoremap <buffer> s /\|\zs\S\+\ze\|<CR>
au FileType help nnoremap <buffer> S ?\|\zs\S\+\ze\|<CR>
au FileType help nnoremap <buffer> q :close<CR>
au BufEnter *.txt call HelpInNewTab()
augroup END
function! HelpInNewTab()
if &buftype == 'help'
"Convert the help window to a tab
execute "normal \<C-W>T"
endif
endfunction
" }}}
" vim: set ft=vim sts=2 ts=2 sw=2 et fdl=0: