-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
1264 lines (1048 loc) · 39.2 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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" {{{ Home directory and swap files
let $VIMHOME = $HOME."/.vim"
if has('win32') || has('win64')
set runtimepath^=~/.vim
set noswapfile
else
set directory=$VIMHOME/swap//,.
set backupdir=$VIMHOME/backup//,.
if has('mac')
set noswapfile
endif
endif
call has('python3')
if empty(glob($VIMHOME . '/autoload/plug.vim'))
silent !curl -fLo $VIMHOME/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" }}}
" {{{ Plugins
call plug#begin($VIMHOME . '/bundle')
Plug 'ctrlpvim/ctrlp.vim'
" Completion & snippets & linting
if !has('win32')
Plug 'Valloric/YouCompleteMe', { 'do': 'python3 ./install.py --go-completer --ts-completer' }
endif
Plug 'Shougo/echodoc.vim'
Plug 'SirVer/ultisnips'
Plug 'neomake/neomake'
" Plug 'tom-doerr/vim_codex'
" Plug 'tpope/vim-apathy' " Disabled due to being incompatible with https://github.com/HerringtonDarkholme/yats.vim/issues/200
Plug 'AndrewRadev/splitjoin.vim'
Plug 'Konfekt/FastFold'
Plug 'airblade/vim-gitgutter'
Plug 'b4winckler/vim-angry'
Plug 'beloglazov/vim-textobj-quotes'
Plug 'chrisbra/matchit'
Plug 'christoomey/vim-sort-motion'
Plug 'godlygeek/tabular'
Plug 'janko/vim-test'
Plug 'jiangmiao/auto-pairs'
Plug 'kana/vim-textobj-function'
Plug 'kana/vim-textobj-user'
Plug 'knsh14/vim-github-link'
Plug 'majutsushi/tagbar'
Plug 'michaeljsmith/vim-indent-object'
Plug 'mogelbrod/vim-jsonpath'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'pechorin/any-jump.vim'
Plug 'prettier/vim-prettier', { 'do': 'npm install' }
Plug 'rickhowe/diffchar.vim'
Plug 'rizzatti/dash.vim'
Plug 'rking/ag.vim'
Plug 'romainl/vim-qf'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'sjl/gundo.vim'
Plug 'thinca/vim-textobj-function-javascript'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'yssl/QFEnter'
" Language specific plugins
" Plug 'othree/javascript-libraries-syntax.vim'
" Plug 'sheerun/vim-polyglot' " bundle of most popular file type plugins
Plug 'HerringtonDarkholme/yats.vim'
Plug 'MaxMEllon/vim-jsx-pretty'
Plug 'amadeus/vim-xml'
Plug 'chrisbra/csv.vim'
Plug 'digitaltoad/vim-jade'
Plug 'ekalinin/Dockerfile.vim'
Plug 'elzr/vim-json'
Plug 'fatih/vim-go'
Plug 'heavenshell/vim-jsdoc'
Plug 'jparise/vim-graphql'
Plug 'mattn/emmet-vim'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'othree/csscomplete.vim'
Plug 'othree/html5.vim'
Plug 'pangloss/vim-javascript'
Plug 'stephpy/vim-yaml'
Plug 'tpope/vim-git'
Plug 'vim-jp/vim-cpp'
call plug#end()
" }}}
" {{{ Basic settings and environment setup
syntax on
colorscheme mogelbrod
let mapleader = ","
" Use Unicode and Unix linebreaks
set termencoding=utf-8 encoding=utf-8 fileformat=unix
" Language settings
let $LANG='en'
set langmenu=en helplang=en
set nospell spelllang=en_us,sv
" Clipboard yanking
if has('unnamedplus')
set clipboard=unnamedplus
else
set clipboard=unnamed
end
" Don't show active mode in status line
set noshowmode
" Tabs expand to 2 spaces
set tabstop=2 shiftwidth=2 softtabstop=2 expandtab shiftround
set tags=./.tags;/,.tags,./tags,tags " tag files
" Buffer saving/reading
set nobackup nowritebackup " do not create backups when writing to files
set autowrite " autosave before making
set hidden " allow switching of buffers without saving them first
" UI elements / text appearance
set autoindent
set cursorline nocursorcolumn " highlight line but not column
set nonumber
set wrap linebreak " word wrap
set display=lastline " show as much as possible of the last line
set scrolloff=3 " minimum number of lines surrounding cursor
set listchars=tab:°\ ,trail:·,nbsp:· " whitespace visible on :set list
set diffopt+=iwhite " ignore whitespace when diffing
set splitbelow splitright " push new splits to bottom/right
set signcolumn=yes
" Search / highlight / replace
set nojoinspaces
set incsearch " show search results while being typed
set hlsearch " highlight matches
set smartcase "noignorecase
" Command line
set history=1000 " command line history length
set shellslash " always use forward slashes, even on windows
set nowildmenu
set wildmode=longest:list,full
set wildignore=*.o,*.bak,*.swc,*.swp,.git/*,.gitkeep,*.class
set wildignore+=*/tmp/*,*.so,*.zip
set wildignore+=tmp\*,*.zip,*.exe
" Insert mode completion
set complete=.,w,t,i,k
set completeopt=longest,menu
if has('popupwin')
set completeopt+=popup
set completepopup=border:off,highlight:Pmenu ",align:flip
end
" Shorten various messages in vim
set shortmess=filmnrxoOtTIc
if has("balloon_eval")
set noballooneval " disable annoying window popups
endif
" Disable bee/bell
set noerrorbells visualbell t_vb=
autocmd GUIEnter * set visualbell t_vb=
" Timeouts (t = mappings, tt = keycodes)
set timeout ttimeout timeoutlen=3000 ttimeoutlen=200
" Update external program settings
if executable('ag')
let g:ctrlp_user_command = 'ag %s -l --nocolor -g "" --ignore dist'
let g:ctrlp_use_caching = 0
let g:ag_prg = 'ag --nogroup --column --smart-case --ignore dist'
set grepprg=ag\ --nogroup\ --nocolor\ --ignore\ dist
elseif executable('ack')
set grepprg=ack\ -k
endif
" Session management
set sessionoptions=blank,buffers,tabpages,winsize,curdir,help
" }}}
" {{{ Buffer navigation
" Ctrl+Left/right switches between buffers
noremap <C-Left> :bprevious<CR>
noremap <C-Right> :bnext<CR>
noremap [D :bprevious<CR>
noremap [C :bnext<CR>
noremap [1;5D :bprevious<CR>
noremap [1;5C :bnext<CR>
noremap <C-u> <C-i>
noremap <C-t> :b#<CR>
" }}}
" {{{ Command mode
" Quick shortcut for entering command mode
noremap - :
noremap ö :
noremap Ö :
noremap ; :
" Usable bindings
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <Home>
cnoremap <End>
" Ctrl-Arrow word jump
cnoremap [D <S-Left>
cnoremap [C <S-Right>
" Alias capital W to write
cnoreabbrev W w
" Add :w!! command which will write file as sudo
cnoreabbrev w!! %!sudo tee > /dev/null %
" }}}
" {{{ Key behaviour & custom mappings
" Allow backspacing over everything
set backspace=indent,eol,start
" Have the cursor keys wrap between lines (like <Space> and <BkSpc> do)
set whichwrap=<,>,[,]
" Navigate through displayed lines, not physical
noremap <silent> j gj
noremap <silent> k gk
inoremap <silent> <Down> <C-o>gj
inoremap <silent> <Up> <C-o>gk
noremap <silent> <Down> gj
noremap <silent> <Up> gk
" Scroll screen with <C-j>/<C-k>
noremap <silent> <C-j> <C-d>
noremap <silent> <C-k> <C-u>
" Completion (C-x) key shortcuts
inoremap <C-l> <C-X><C-L>
inoremap <C-f> <C-X><C-F>
"nnoremap <F2> :set invpaste paste?<CR>
nnoremap <F2> :set paste<CR>i
" F2 toggles pasting mode
set pastetoggle=<F2>
" Disable paste after leaving insert mode
au InsertLeave * set nopaste
" F3 toggles highlighting of search results
noremap <F3> :set hls!<CR>
inoremap <F3> <C-o>:set hls!<CR>
" F5 toggle Gundo plugin
nnoremap <F4> :GundoToggle<CR>
" F7 displays syntax highlighting info for token under cursor
noremap <F7> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Ctrl+H replaces all occurences of the selected text with something else
vnoremap <C-h> "zy<Esc>:call ReplaceSelection()<CR>
fun! ReplaceSelection()
let replacement = input("Replacement for ".@z.": ")
exe "%s~\\M".escape(@z, '[]~\').'~'.escape(replacement, '&').'~gc'
endfun
fun! JsArrowToFunction()
s/\v(^|<const )\s*([a-zA-Z0-9_]+)\s*[=:]\s*\(?([^)>]{-})\)?\s*\=\>\s*\{/function \2(\3) {/
endfun
" Map P to replace selection without overwriting any registers
vnoremap P "_dP
" Map gp to select the last pasted (or changed) text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
noremap § <C-]>
noremap <C-w>§ <C-w>}
" Swap mark jump mappings
nnoremap ' `
nnoremap ` '
" Navigate quickfix list
nnoremap ]p :cprev<CR>
nnoremap ]n :cnext<CR>
nnoremap ]P :cpfile<CR>
nnoremap ]N :cnfile<CR>
" Navigate location list
nnoremap ], :lprev<CR>
nnoremap ]. :lnext<CR>
" Keep search matches in the middle of the window
nnoremap * *zzzv
nnoremap # #zzzv
nnoremap n nzzzv
nnoremap N Nzzzv
" }}} (
" {{{ Leader mappings
" Tab manipulation
noremap <silent> <leader>tn :tabnew<CR>
noremap <silent> <leader>tc :tabclose<CR>
noremap <silent> <leader>tm :tabmove<Space><C-r>=Input("New position")<CR><CR>
" Tab switching with <leader>number
noremap <silent> <leader>1 1gt
noremap <silent> <leader>2 2gt
noremap <silent> <leader>3 3gt
noremap <silent> <leader>4 4gt
noremap <silent> <leader>5 5gt
noremap <silent> <leader>6 6gt
noremap <silent> <leader>7 7gt
noremap <silent> <leader>8 8gt
noremap <silent> <leader>9 9gt
nore <leader>g :call RecursiveGrepCommand() <Bar> cw<CR><CR><CR>
nore <silent> <leader><leader>g <Esc>:Egrep ""<left>
vnore <leader>g "zy:call RecursiveGrepCommand(@z) <Bar> cw<CR><CR><CR>
nore <silent> <leader><leader>x TestFile
" Copy buffer contents to clipboard
map <silent> <leader>ya ggVG"+y''
" Copy Git(Hub) permalink to current/selected line(s)
nore <silent> <leader>yg :GetCommitLink<CR>
" Yank everything on the current side of a = character
nore <silent> <leader>ys <Esc>:call YankSide()<CR>
" Fold navigation
map <silent> <Leader><Up> [z
map <silent> <Leader><Down> ]z
" :cnext / :cprev
map <silent> <Leader>[ :cprev<CR>
map <silent> <Leader>] :cnext<CR>
" Toggle Indent guides
nmap <silent> <leader>i <Plug>IndentGuidesToggle
nnoremap <leader>j :AnyJump<CR>
xnoremap <leader>j :AnyJumpVisual<CR>
" Join visual selection lines with commas
" vmap <silent> <leader>j "zy:let @z=join(split(@z, "\n"), ", ")<CR>gv"zp
" Expand tabs to spaces in selection
vmap <leader>e :s#\t#\=repeat(" ", &l:ts)#g<CR>
nmap <leader>e :%s#\t#\=repeat(" ", &l:ts)#g<CR>
" Strip trailing whitespace
nmap <leader>$ :call Preserve("%s/\\s\\+$//e")<CR>
" Re-indent file
nmap <leader>= :call Preserve("normal mzgg=G'z")<CR>
nmap <leader>p :CtrlP <C-r>=expand('%:p:h')<CR><CR>
nmap <leader>l :CtrlP ~/src/
nmap <leader>a :Agext <C-r>=expand('%:e')<CR>
" Comment toggling
map <leader>7 <plug>NERDCommenterToggle
vmap <leader>7 <plug>NERDCommenterToggle
map <leader>/ <plug>NERDCommenterSexy
vmap <leader>/ <plug>NERDCommenterSexy
" Tabular plugin map
nmap <leader><space> :Tabularize /
vmap <leader><space> :Tabularize /
" Search for selection and replace with input() in all open buffers
vnoremap <leader>h "zy:bufdo! %s~\V<C-r>z~~ge<left><left><left>
noremap <leader>m :Make<space>
noremap <leader>c :Make<CR>
noremap <leader>n :cn<CR>
" Convert number(s) under cursor
nore <leader>sd <Esc>:call DecToHex()<CR>
vnore <leader>sd <Esc>:call DecToHex()<CR>
nore <leader>sh <Esc>:call HexToRGB()<CR>
" Open / reload vimrc
nmap <silent> <leader>V :e $MYVIMRC<CR>:filetype detect<CR>
nmap <silent> <leader>v :source $MYVIMRC<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" }}}
" {{{ (Re)formatting
" Using Tab and Shift-Tab to (un)indent
nore <tab> >>
nore <S-tab> <<
nore [Z <<
vnore <tab> >gv
vnore <S-tab> <gv
vnore [Z <gv
" Ensure UltiSnips doesn't override visual <tab>
au BufEnter * vnoremap <tab> >gv
" Formatting options (disable autocommenting)
set formatoptions=rjnq1
autocmd FileType * setlocal formatoptions-=co
" Do not reindent lines with a comment sign (removed 0#)
autocmd FileType * setlocal cinkeys=0{,0},0),:,!^F,o,O,e
" }}}
" {{{ Folding
" Folding (by braces)
set foldmethod=marker foldmarker={{{,}}}
" What actions should cause folds to open?
set foldopen=insert,hor,block,hor,mark,percent,quickfix,search,tag,undo
" Control fold open/closed with <Space>
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
" Fold text (title)
function! CustomFoldText(...) " {{{
if a:0 > 0
let line = a:1
let linecount = a:0 > 1 ? a:2 : -1
else
let line = getline(v:foldstart)
let linecount = v:foldend - v:foldstart + 1
endif
" Store indentation and later re-apply it
let spaces4tab = repeat(' ', &l:ts)
let indentation = substitute(matchstr(line, '^\s*'), "\t", spaces4tab, 'g')
" Remove fold marker if present
let foldmarkers = split(&foldmarker, ',')
let line = substitute(line, '\V' . foldmarkers[0] . '\%(\d\+\)\?', '', '')
" Remove known comment strings
let comment = split(&commentstring, '%s')
if comment[0] != ''
let comment_begin = comment[0]
let comment_end = ''
if len(comment) > 1
let comment_end = comment[1]
end
let pattern = '\V' . comment_begin . '\s\*' . comment_end . '\s\*\$'
if line =~ pattern
let line = substitute(line, pattern, '', '')
else
let line = substitute(line, '\V' . comment_begin, '', '')
if comment_end != ''
let line = substitute(line, '\V' . comment_end, '', '')
endif
endif
endif
" Remove additional comment prefixes
if &ft=='cpp' || &ft=='php'
let line = substitute(line, '\V//', '', '')
endif
" Remove any remaining leading/trailing whitespace
let line = substitute(line, '^\s*\(.\{-}\)\s*$', '\1', '') . ' '
" Reapply indentation
let line = indentation . line . ' '
" Line count
if linecount == -1
let linecount = ''
else
let linecount = ' '. linecount . ' lines | ' . v:foldlevel
end
let cols = winwidth(0) - (&nu ? &numberwidth : 0)
let fill = repeat('-', cols - strlen(substitute(line, '.', 'x', 'g')) - strlen(linecount))
let line = strpart(line, 0, cols - strlen(linecount)) . fill . linecount
return line
endfunction " }}}
set foldtext=CustomFoldText()
function! IndentationFoldExpr(ln) " {{{
let line = getline(a:ln)
if line =~ '^\s*$'
return '-1' "'='
end
let ind = indent(a:ln) / &sw
let ind_next = indent(nextnonblank(a:ln+1)) / &sw
if ind_next <= ind
return ind
elseif ind_next > ind
return '>'.ind_next
end
endfunction " }}}
" }}}
" {{{ Tabline
" TODO: Loop through windows in each tab to determine most appropriate tab name
" See https://github.com/webastien/vim-tabs/blob/master/plugin/tabs.vim
if exists('+showtabline')
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let bufnr = buflist[winnr - 1]
let file = bufname(bufnr)
let buftype = getbufvar(bufnr, 'buftype')
let s .= '%' . i . 'T' " tells vim which tab to show if clicked
let s .= (i == t ? '%1*%#TabNumSel#' : '%2*%#TabNum#')
let s .= ' ' . i " tab number
if getbufvar(bufnr, '&modified')
let s .= '+' " tab has modified contents
endif
let s .= ' %*'
" Tab name
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#') " highlight group
if buftype == 'nofile'
if file =~ '\/.'
let file = substitute(file, '.*\/\ze.', '', '')
endif
else
let file = fnamemodify(file, ':p:t')
endif
if file == ''
let file = '[NoName]'
endif
let s .= file . ' '
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
" Don't show close X
" let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set tabline=%!MyTabLine()
set showtabline=1
endif
" }}}
" {{{ Statusline
set laststatus=2 " always show status line
set showcmd " show incomplete commands
" %f(ile) [flags] {align} [%ft] %col %line/%total %percent
let g:statusline_mode={ 'n': 'N', 'no': 'Nop', 'v': 'Vis', 'V': 'Vln', '': 'Vbl', 's': 'Sel', 'S': 'Sln', '': 'Sbl', 'i': 'Ins', 'R': 'Rep', 'Rv': 'Rvr', 'c': 'Cmd', 'cv': 'vEX', 'ce': 'EX', 'r': 'Prompt', 'rm': 'More', 'r?': 'Confirm', '!': 'Shell' }
if !has('nvim')
function! MyStatusLine(active)
let bufnr = winbufnr(g:statusline_winid)
let st = ""
let st .= "%< %-f " " File path (truncated if necessary)
let st .= "%m%r%w %="
let st .= " %=" " Separation point
if a:active
" Show current mode in active window
let st .= "%{g:statusline_mode[mode()]} "
endif
let st .= neomake#statusline#get(bufnr, {
\ 'format_running': '({{running_job_names}}) ',
\ 'format_loclist_unknown': '',
\ 'format_loclist_ok': '✓',
\ 'format_quickfix_ok': '',
\ 'format_quickfix_issues': '%s',
\ })
let st .= " %y " " File type
let st .= "%4(%v%) %10(%l/%L%) %P" " Colum & line numbers
return st
endfunction
set statusline=%!MyStatusLine(1)
augroup statusline
au WinEnter * setlocal statusline=%!MyStatusLine(1)
au WinLeave * setlocal statusline=%!MyStatusLine(0)
augroup END
endif
" }}}
" {{{ Plugin configuration
" UltiSnips
let g:UltiSnipsNoPythonWarning = 1
let g:UltiSnipsEnableSnipMate = 0
let g:UltiSnipsJumpForwardTrigger = '<c-j>'
let g:UltiSnipsJumpBackwardTrigger = '<c-k>'
function! UltiSnips_Complete()
call UltiSnips#ExpandSnippet()
if g:ulti_expand_res == 0
return pumvisible() ? "\<c-n>" : "\<tab>"
endif
return ""
endfunction
augroup ultisnips
au!
au VimEnter * au! UltiSnips_AutoTrigger
au BufEnter * inoremap <buffer> <silent> <tab> <C-R>=UltiSnips_Complete()<cr>
au BufEnter * snoremap <buffer> <silent> <tab> <C-R>=UltiSnips_Complete()<cr>
augroup END
" YouCompleteMe / YCM
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_min_num_identifier_candidate_chars = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_complete_in_comments = 1
let g:ycm_autoclose_preview_window_after_insertion = 0
let g:ycm_auto_hover = ''
let g:ycm_error_symbol = '> '
let g:ycm_warning_symbol = '! '
let g:ycm_semantic_triggers = {
\ 'javascript': [ 're!([ ;] |\t|: |@)' ],
\ 'css,scss': [ '\t', ' ', '; ', ': ', '@' ],
\ }
let g:ycm_log_level = 'info'
let g:ycm_key_detailed_diagnostics = ''
" Any-jump
let g:any_jump_search_prefered_engine = 'ag'
let g:any_jump_window_width_ratio = 0.8
let g:any_jump_window_height_ratio = 0.8
let g:any_jump_disable_default_keybindings = 1
" EchoDoc
let g:echodoc#enable_at_startup = 1
" NeoMake
call neomake#configure#automake('w')
let g:neomake_open_list = 2
let g:neomake_list_height = 6
let g:neomake_place_signs = 1
let g:neomake_highlight_columns = 0
let g:neomake_javascript_enabled_makers = ['eslint']
let g:neomake_typescript_enabled_makers = ['eslint']
let g:neomake_graphql_enabled_makers = ['eslint']
function! EslintInitForJob(jobinfo) dict abort
let project_root = neomake#utils#get_project_root(a:jobinfo.bufnr)
if !a:jobinfo.file_mode
if empty(project_root)
call add(self.args, '.')
else
call add(self.args, project_root)
endif
endif
if !empty(project_root)
let self.cwd = project_root
let rc_path = project_root . '/.eslintrc'
if filereadable(rc_path . '.js')
let rc_path = rc_path . '.js'
elseif filereadable(rc_path . '.json')
let rc_path = rc_path . '.json'
elseif filereadable(rc_path . '.yml')
let rc_path = rc_path . '.yml'
endif
if filereadable(rc_path)
call add(self.args, '--config=' . rc_path)
endif
if filereadable(project_root . '/.eslintignore')
call add(self.args, '--ignore-path=' . project_root . '/.eslintignore')
endif
endif
endfunction
call neomake#config#set('ft.javascript.eslint.InitForJob', function('EslintInitForJob'))
call neomake#config#set('ft.typescript.eslint.InitForJob', function('EslintInitForJob'))
call neomake#config#set('ft.typescriptreact.eslint.InitForJob', function('EslintInitForJob'))
call neomake#config#set('ft.graphql.eslint.InitForJob', function('EslintInitForJob'))
" Configures neomake to use a project-local instance of a maker
function! SetNeomakeExe(ft_maker, file)
let bufvar = 'b:neomake_'.a:ft_maker.'_exe'
let path = findfile(a:file, '.;')
if path != ''
let path = fnamemodify(path, ':p')
exe 'let '.bufvar.' = "'.escape(path, '"').'"'
else
exe 'unlet! '.bufvar
endif
endfunction
" vim-prettier
noremap <leader>q :Prettier<CR>
let g:prettier#autoformat_config_present = 1
let g:prettier#exec_cmd_async = 1
let g:prettier#config#semi = 'false'
let g:prettier#config#single_quote = 'true'
let g:prettier#config#trailing_comma = 'all'
let g:prettier#config#jsx_bracket_same_line = 'false'
" vim-qf
let g:qf_loclist_window_bottom = 0
" vim-test
let g:test#strategy = 'neomake'
let g:test#runner_commands = ['Mocha']
let g:test#javascript#mocha#file_pattern = '\v(tests?/.*|.*\.(test|spec))\.(js|jsx|ts|tsx)$'
" GitGutter
let g:gitgutter_enabled = 0
noremap <silent> <leader>u :GitGutterToggle<CR>
" CtrlP plugin
noremap <C-p> :CtrlP<CR>
noremap <C-b> :CtrlPBuffer<CR>
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_switch_buffer = '0'
let g:ctrlp_open_new_file = 'r'
let g:ctrlp_max_depth = 10
let g:ctrlp_lazy_update = 100
let g:ctrlp_types = ['fil', 'buf']
let g:ctrlp_extensions = ['dir', 'tag']
let g:ctrlp_reuse_window = 'netrw'
let g:ctrlp_mruf_relative = 1
let g:ctrlp_mruf_max = 0 " attempt to disable MRU, just annoying in mixed mode
let g:ctrlp_match_current_file = 1
let g:ctrlp_custom_ignore = {
\ 'dir': '\v\.(git|hg|svn)$',
\ 'file': '\v\.(exe|so|dll|tar|bz2|gz|zip|jar|deb|jpe?g|png|gif|bmp|mp3|avi|mp4|mov|mpe?g|mkv|pdf)$'
\ }
let g:ctrlp_prompt_mappings = {
\ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>', '§', '<c-g>'],
\ 'PrtInsert()': ['<c-y>'],
\ }
" Auto-Pairs
let g:AutoPairsMapSpace = 0
let g:AutoPairsCenterLine = 0
let g:AutoPairsMultilineClose = 0
let g:AutoPairsShortcutJump = '<c-s>'
let g:AutoPairsShortcutFastWrap = '<c-b>' " default conflicts with å character
" splitjoin.vim
let g:splitjoin_trailing_comma=1
let g:splitjoin_html_attributes_bracket_on_new_line=1
" Emmet
let g:user_emmet_complete_tag = 1
let g:user_emmet_leader_key = '<C-e>'
imap <c-e><CR> <plug>(emmet-expand-abbr)
" let g:user_emmet_next_key = '<C-e>n'
" let g:user_emmet_prev_key = '<C-e>p'
" let g:user_emmet_balancetaginward_key = '<C-e>i'
" let g:user_emmet_balancetagoutward_key = '<C-e>a'
" let g:user_emmet_removetag_key = '<C-e>d'
" let g:user_emmet_togglecomment_key = '<C-e>c'
" let g:user_emmet_codepretty_keya = '<C-e>C'
" let g:user_emmet_anchorizeurl_key = '<C-e>l'
" let g:user_emmet_anchorizesummary_key = '<C-e>L'
let g:user_emmet_settings = {
\ 'javascript': { 'extends': 'jsx' },
\ 'typescript': { 'extends': 'jsx' },
\}
" Surround
" For nr to use :echo char2nr("-"))
let g:surround_13 = "{\n\t\r\n}" " enter
let g:surround_40 = "(\n\t\r\n)" " (
let g:surround_47 = "/*\n\r\n*/" " /
let g:surround_102 = "<React.Fragment>\n\r\n</React.Fragment>" " f
" NERDCommenter
let g:NERDCreateDefaultMappings = 0
let g:NERDSpaceDelims = 1
" NERDtree
map <F5> :NERDTreeToggle<CR>
let g:NERDTreeWinSize = 26
let g:NERDTreeMinimalUI = 1
let g:NERDTreeMapActivateNode = 'l'
let g:NERDTreeMapOpenRecursively = 'L'
let g:NERDTreeMapChangeRoot = 'cd'
let g:NERDTreeMapCWD = 'CD'
let g:NERDTreeMapChdir = 'CW'
" TagBar
nnore <silent> <F6> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
let g:tagbar_compact = 1
let g:tagbar_expand = 0
" Indent guides
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
let g:indent_guides_color_change_percent = 5
" Misc
let g:used_javascript_libs = 'jquery,react,requirejs'
let g:vim_json_syntax_conceal = 0
let g:yats_host_keyword = 0
let g:jsdoc_enable_es6 = 1
let g:jsdoc_underscore_private = 1
let g:go_fmt_command = 'goimports'
let g:go_highlight_functions = 1
let g:go_highlight_function_parameters = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 0
let g:go_highlight_variable_declarations = 1
let g:go_highlight_variable_assignments = 1
let g:gundo_prefer_python3 = 1
let g:jsonpath_register = '*'
let g:jsonpath_use_pyhon = 1
" }}}
" {{{ Custom functions and commands
" Make
command! -nargs=* -complete=file Make silent! make <args> | redraw! | botright cwindow 5
" Update tags file using ctags executable
command! -nargs=? Tags call GenerateTags(<args>) | cw
command! -nargs=+ -complete=dir Agext call AgExt(<q-args>)
command! -nargs=1 Egrep exe 'normal! :call RecursiveGrepCommand("'.<args>.'")<Bar> cw<CR><CR><CR>'
command! -nargs=0 IFold setlocal foldexpr=IndentationFoldExpr(v:lnum) foldmethod=expr nofoldenable
command! -nargs=1 Hex2RGB call HexToRGB(<args>)
command! -nargs=1 Dec2Hex call DecToHex(<args>)
command! -nargs=0 WipeHidden call WipeHiddenBuffers()
command! -nargs=0 HiName echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"
command! -nargs=0 ConcealTodo setlocal cole=2 <bar> call matchadd('Conceal', '/[*/] TODO: \zs.\{-}\ze\($\|\*/\)')
command! -nargs=? -range=% Space2Tab call IndentConvert(<line1>,<line2>,0,<q-args>)
command! -nargs=? -range=% Tab2Space call IndentConvert(<line1>,<line2>,1,<q-args>)
command! -nargs=? -range=% RetabIndent call IndentConvert(<line1>,<line2>,&et,<q-args>)
" Limit Ag command search to a specific file type
function! AgExt(...) "{{{
let words = split(a:1)
let ext = words[0]
let rest = join(words[1:-1], ' ')
echo "normal :Ag -G '\.(".ext.")$' ".rest."<CR>"
exe "Ag -G '\.(".ext.")$' ".rest
endfunction "}}}
" Generate new tags file recursively from cwd or a specific path
function! GenerateTags(...) "{{{
let path = a:0 > 0 ? a:1 : getcwd()
let path .= has("win32") ? "\\" : "/"
let cmd = "ctags -f ".path.".tags --tag-relative=yes --exclude=.git --exclude=.svn"
let langs = &ft
let extra = ''
if &ft == 'haml'
let langs = 'ruby'
elseif &ft == 'php'
let extra = " --PHP-kinds=+ivcf \\
\ --regex-PHP='/(abstract)?\\s+class\\s+([^ ]+)/\\2/c/' \\
\ --regex-PHP='/(static|abstract|public|protected|private)\\s+function\\s+(\\&\\s+)?([^ (]+)/\\3/f/' \\
\ --regex-PHP='/interface\\s+([^ ]+)/\\1/i/' \\
\ --regex-PHP='/\\$([a-zA-Z_][a-zA-Z0-9_]*)/\\1/v/'"
endif
call system(cmd . " --languages=".langs . " -R ".path . extra)
echo "Tags file generated at: " . path.".tags"
endfunction "}}}
" External grep (recursive) on word under cursor or a given string
function! RecursiveGrepCommand(...) "{{{
if a:0 > 0
let str = a:1
else
let str = expand("<cword>")
endif
if &grepprg == "ack -k" || match(&grepprg, "ag ") == 0
let call = 'grep "'.str.'"'
else
let str = escape(str, '<>~.\*+[]^$')
" TODO: don't add word boundary prefix/suffix when a word boundary character already starts/ends the string
let filter = (expand("%:e") == '' ? '.' : '*.'.expand("%:e"))
if has('win32') || has ('win64')
" TODO: don't change grepprg on windows?
set grepprg=findstr\ /spn
let call = 'grep "\<'.str.'\>"'.filter
else
if len(filter) > 1
let filter = '**/'.filter
endif
let call = 'grep -srnw --binary-files=without-match --exclude-dir=.git "\b'.str.'\b" '.filter
endif
endif
exe call
endfunction "}}}
" Display hex color under cursor as RGB combo
function! HexToRGB(...) "{{{
if a:0 > 0
let str = string(a:1)
else
let str = expand("<cword>")
endif
let parts = matchlist(str, '\c\v#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})')
if len(parts) < 1
echo "Word under cursor does not appear to be a hexcolor"
return
endif
let out = "#".parts[1].parts[2].parts[3]." = RGB( "
for i in range(1, 3)
let out = out . printf("%d ", "0x" . parts[i])
endfor
echo out . ")"
endfunction "}}}
" Display the decimal number under cursor in hexadecimal format
function! DecToHex(...) "{{{
if a:0 > 0
let str = string(a:1)
else
let str = expand("<cword>")
endif
let m = matchlist(str, '\c\v([0-9.]+)')
if len(m) < 1
echo "Word under cursor does not appear to be a decimal number"
return
endif
echo printf("%s = 0x%x", m[1], m[1])
endfunction "}}}
" Copy everything on current side of equals sign (=)
function! YankSide() "{{{
let line = getline('.')
let cur_col = col('.') " cursor column
let eq_col = match(line, '=') " equal sign column
if eq_col < cur_col " we are on the right side
let line = substitute(line, '^[^=]\+=\s*', '', '')
elseif eq_col > cur_col " we are on the left side
let line = substitute(line, '\s*=.\+', '', '')
endif
call setreg(&clipboard == 'unnamed' ? '*' : '"', line)
endfunction "}}}
" Helper function which can be used to prompt for input in mappings and macros
" (call with <C-r>=Input("prompt")<CR>)
function! Input(prompt) "{{{
call inputsave()
let text = input(a:prompt . ': ')
call inputrestore()
return text
endfunction "}}}
function! Preserve(command) "{{{
" Preparation: save last search, and cursor position
let _s=@/
let l = line(".")
let c = col(".")