-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
2718 lines (2343 loc) · 102 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
if &compatible | set nocompatible | endif " Avoid side effects if `nocp` already set
scriptencoding utf-8
"Xxx: this needs .term_detect script support in shell
let s:term_program=$TERM_PROGRAM
let s:term_version=$TERM_VERSION
if s:term_version ==# ''
let s:term_version = 0
endif
let s:in_screen = $STY !=# ''
let s:in_tmux = $TMUX !=# ''
if has('nvim')
" It is not possible to control/override behavior of nvim by setting &term or &t_ sequences
" So the only way how to do it is by setting the TERM variable BEFORE starting nvim
" e.g. `TERM=xterm-256color nvim` or `TERM=screen-256-color nvim` (when running in GNU screen)
" Check terminfo capabilities with `infocmp` tool
if &t_Co < 256
echohl Warning
echomsg 'Only ' . &t_Co . ' colors are defined in the terminfo of ' . $TERM
\. ' (try setting TERM before running nvim)'
echohl None
endif
endif
if s:term_program ==# 'lxterminal' || s:term_program ==# 'gnome-terminal' ||
\ s:term_program ==# 'xterm' || s:term_program ==# 'Konsole' ||
\ s:term_program ==# 'PuTTY' || s:term_program ==# 'Cygwin'
let &term = 'xterm'
elseif s:term_program ==# 'rxvt' || s:term_program ==# 'urxvt'
let &term = 'rxvt'
elseif s:term_program ==# 'old-gnome-terminal'
let &term = 'xterm'
"Note: workaround for bracketed paste mode in Vim 8.0.569 (see discussion https://github.com/vim/vim/issues/1671)
let &t_BE=''
else
"Todo: this is a hack for screen-bce/screen.rxvt to behave as xterm/rxvt in Vim
if &term ==# 'screen-bce' || &term ==# 'screen'
if s:in_screen == 0
"ssh to devpc from inside of a screen (let's fake STY)
let s:in_screen = 1
let $STY = '0.dev'
endif
let &term = 'xterm'
elseif &term ==# 'screen.rxvt'
let &term = 'rxvt'
elseif &term =~# 'rxvt' "for urxvt and 256 color variants
let &term = 'rxvt'
endif
endif
function! s:ScreenEscape(line)
if s:in_screen
" Screen has an escape hatch for talking to the real terminal. Use it.
let l:escaped = a:line
return "\eP" . l:escaped . "\e\\"
else
return a:line
endif
endfunction
function! s:TmuxEscape(line)
if s:in_tmux
" Tmux has an escape hatch for talking to the real terminal. Use it.
let l:escaped = substitute(a:line, "\\e", "\e\e", 'g')
return "\ePtmux;" . l:escaped . "\e\\"
else
return a:line
endif
endfunction
function! s:MultiplexerEscape(line)
if s:in_screen
return s:ScreenEscape(a:line)
elseif s:in_tmux
return s:TmuxEscape(a:line)
else
return a:line
endif
endfunction
if has('win64') || has('win32') || has('win16')
let g:OS_name='windows'
let g:OS_dir_separator = '\'
let g:OS_cat_command = 'type'
let g:OS_mkdir_command = 'mkdir'
"TODO: change to cygwin later
let g:OS_ctags_command = 'c:\Apps\ctags57\ctags.exe'
let g:OS_system_includes_dir = 'c:\Apps\Dev-Cpp\include'
let g:OS_vimrc = '_vimrc'
"windows vista uses $HOME\.vim path, xp uses $HOME\vimfiles path
"so in xp we change it to $HOME\.vim and $HOME\.vim\after
"but only the first and last component
let &runtimepath=substitute(&runtimepath, '\(^[^,]*\)vimfiles', '\1.vim', '') "replace first occurrence
let &runtimepath=substitute(&runtimepath, '\(,[^,]*\)vimfiles\([^,]*\)$', '\1.vim\2', '') "replace last occurrence
"behave mswin
"source $VIMRUNTIME/mswin.vim
"let $VIMRUNTIME=fnamemodify($_, ":p")
language mes en
" replace all directory separators in runtimepath to OS specific
let &runtimepath=substitute(&runtimepath, '[\/]', g:OS_dir_separator, 'g')
else
"if SHELL env variable is set incorrectly and VIM cannot start shell, then
" uncomment following line, that overrides SHELL env variable
"set shell=/bin/sh
" let g:OS_name=system('uname -s') "system call is slow (~6ms)
let g:OS_name='linux' "changed to linux (not needed to be specific, any string other than windows is enough)
let g:OS_dir_separator = '/'
let g:OS_cat_command = 'cat'
let g:OS_mkdir_command = 'mkdir -p'
let g:OS_ctags_command = 'ctags'
let g:OS_system_includes_dir = '/usr/include,/usr/local/include'
let g:OS_vimrc = '.vimrc'
"
" It's possible that $VIMRUNTIME does not exist.
" Let's see if there is a directory vimshare below where we were started
"
if isdirectory($VIMRUNTIME) == 0
"
" What was the name that we were called as?
"
let g:vimshare=substitute(fnamemodify($_, ':p'), '^\(.*[/]\).*$', '\1', '') . 'vimshare'
if isdirectory(g:vimshare) == 1
let $VIMRUNTIME=g:vimshare . '/vim' . substitute(v:version, '50', '5', '')
let &helpfile=g:vimshare . '/vim' . substitute(v:version, '50', '5', '') . '/doc/help.txt'
endif
endif
endif
if !has('gui_running')
if g:OS_name !=# 'windows'
"set t_Cc=1
"set t_pa=32767
if &term =~# 'xterm'
"general termcap options
"must go before first shell execute command (e.g. execute !ls) from .vimrc
"sets alternate screen mode
let &t_ti="\e[?1049h"
let &t_ts="\e]0;"
let &t_fs="\007"
"override terminfo setting to enable 256 colors
let &t_Co=256
"let &t_AB="'\e[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m'"
"let &t_AF="'\e[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m'"
let &t_AB="\e[4%p1%dm"
let &t_AF="\e[3%p1%dm"
let &t_mb="\e[5m"
let &t_nd="\e[C"
let &t_op="\e[39;49m"
let &t_se="\e[27m"
let &t_te="\e[?1049l"
let &t_vi="\e[?25l"
let &t_vs="\e[?12;25h"
let &t_vb="\e[?5h$<100/>\e[?5l"
let &t_ve="\e[?12l\e[?25h"
let &t_ti="\e[?1049h"
"not necessary, as t_AB,t_AF are used instead
let &t_Sb="\e[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m"
let &t_Sf="\e[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m"
"see vim help -> :help xterm-function-keys
set timeout timeoutlen=1000 ttimeoutlen=100
"terminal detection (based on ^[[>c or in better form "\e[>c"), in screen surround query
" string with \eP...\e\\ (as always, when we want to talk to terminal underneath screen)
" the terminal's response is already stored in v:termresponse in Vim
"
"^[ is code for escape key (written as two character to not have
" special keys directly in this .vimrc file)
"Screen "old versions???" (nothing)
"Xterm Xterm(278) ^[[>0;278;0c
"Xterm Xterm(317) ^[[>41;317;0c
"Lxterminal lxterminal (0.1.11-4ubuntu3) ^[[>1;2802;0c
"Cygwin ^[[>77;10103;0c
"PuTTY 0.62 ^[[>0;136;0c
"Screen 4.00.03 (FAU) ^[[>83;40003;0c
"Screen 4.01.00devel (GNU) 2-May-06 ^[[>83;40100;0c
"Gnome-terminal GNOME Terminal 3.6.2 ^[[>1;3409;0c
"Konsole 2.13.2 ^[[>0;115;0c
"see vim help v:termresponse
"callback is called after response to t_RV reception -> TermResponse autocommand event
"only then is can be used for terminal identification
"echomsg "testing..." . v:termresponse
"
"for PuTTY answerback may be probably also used (based on ^E)
" query terminal via: echo -n -e "^E"
" PuTTY usually shows PuTTY as a result
" beware ^E is really one keycode entered by typing CTRL+V + CTRL+E in terminal
"TODO: implement somehow :-)
"old xterm/lxterminal F1-F4 (used only for no mod case - e.g. ^[OP, ...)
execute "set <F1>=\eO;*P"
execute "set <F2>=\eO;*Q"
execute "set <F3>=\eO;*R"
execute "set <F4>=\eO;*S"
execute "set <Home>=\eO;*H"
execute "set <End>=\eO;*F"
"konsole (universal case covers also the above for no mod case)
execute "set <F1>=\eO*P"
execute "set <F2>=\eO*Q"
execute "set <F3>=\eO*R"
execute "set <F4>=\eO*S"
"new xterm (wildcard used to handle all alt,control,shift combinations)
execute "set <xF1>=\e[1;*P"
execute "set <xF2>=\e[1;*Q"
execute "set <xF3>=\e[1;*R"
execute "set <xF4>=\e[1;*S"
execute "set <xHome>=\e[1;*H"
execute "set <xEnd>=\e[1;*F"
if v:version >= 700
execute "set <zHome>=\e[;*H"
execute "set <zEnd>=\e[;*F"
endif
execute "set <F17>=\eOE"
"Todo: specify correct version for old/new xterm bindings (for now 278 - Ubuntu 13.04 timeframe is the limit)
if s:term_program ==# 'gnome-terminal' && s:term_version < 5200 ||
\ s:term_program ==# 'xterm' && (s:term_version < 278 && s:term_version != 95) ||
\ s:term_program ==# 'lxterminal' && s:term_version < 5200
"old xterm/lxterminal/gnome terminal (e.g. lxterminal in Lubuntu 13.04)
execute "set <xF1>=\eO1;*P"
execute "set <xF2>=\eO1;*Q"
execute "set <xF3>=\eO1;*R"
execute "set <xF4>=\eO1;*S"
execute "set <F17>=\e[E"
endif
"Todo: is this necessary, or does Vim implicitely do this
map <xF1> <F1>
map! <xF1> <F1>
map <xF2> <F2>
map! <xF2> <F2>
map <xF3> <F3>
map! <xF3> <F3>
map <xF4> <F4>
map! <xF4> <F4>
map <xHome> <Home>
map! <xHome> <Home>
map <xEnd> <End>
map! <xEnd> <End>
map <zHome> <Home>
map! <zHome> <Home>
map <zEnd> <End>
map! <zEnd> <End>
"del is set without modifiers support (by default in Vim) => let's change that
execute "set <Del>=\e[3;*~"
"cleanup of Vim's internal duplicate bindings
execute 'set <S-Home>='
execute 'set <S-Left>='
execute 'set <S-Right>='
execute 'set <S-End>='
"newer xterm can do also right winmenu key (has no setting in Vim,
" however something nonexistant on typical keyboard can be used - F13 for example)
execute "set <F13>=\e[29;*~"
"fake key mappings to enable keypad key 5 (Clear) with all modifiers as <F19>
execute "set <F18>=\eO*u"
execute "set <F19>=\e[1;*E"
map <F17> <F19>
map! <F17> <F19>
map <S-F18> <S-F19>
map! <S-F18> <S-F19>
map <C-S-F18> <C-S-F19>
map! <C-S-F18> <C-S-F19>
map <M-S-F18> <M-S-F19>
map! <M-S-F18> <M-S-F19>
map <M-C-S-F18> <M-C-S-F19>
map! <M-C-S-F18> <M-C-S-F19>
elseif &term =~# 'rxvt'
set t_Co=256 "override terminfo setting to enable 256 colors
"rxvt (basic Fn are well covered in default Vim mappings)
" first two are fixed in rxvt - S-F1 == F11 and S-F2 == F12
execute "set <S-F3>=\e[25;*~"
execute "set <S-F4>=\e[26;*~"
execute "set <S-F5>=\e[28;*~"
execute "set <S-F6>=\e[29;*~"
execute "set <S-F7>=\e[31;*~"
execute "set <S-F8>=\e[32;*~"
execute "set <S-F9>=\e[33;*~"
execute "set <S-F10>=\e[34;*~"
execute "set <S-F11>=\e[23;*$"
execute "set <S-F12>=\e[24;*$"
"right windows menu key is equal to S-F6 (but not shift version)
execute "set <S-F13>=\e[29;*$"
execute "set <F19>=\eOu"
execute "set <kHome>=\eOw"
execute "set <kEnd>=\eOq"
execute "set <kInsert>=\eOp"
execute "set <xLeft>=\eOt"
execute "set <xUp>=\eOx"
execute "set <xRight>=\eOv"
execute "set <xDown>=\eOr"
execute "set <S-Insert>=\e[2$"
execute "set <S-Del>=\e[3$"
execute "set <S-Home>=\e[7$"
execute "set <S-End>=\e[8$"
"execute "set <S-PageUp>=\e[5$"
"execute "set <S-PageDown>=\e[6$"
"execute "set <C-Insert>=\e[2^"
"execute "set <C-Del>=\e[3^"
execute "set <C-Home>=\e[7^"
execute "set <C-End>=\e[8^"
"execute "set <C-PageUp>=\e[5^"
"execute "set <C-PageDown>=\e[6^"
execute "set <S-Up>=\e[a"
execute "set <S-Down>=\e[b"
execute "set <S-Left>=\e[d"
execute "set <S-Right>=\e[c"
"execute "set <C-Up>=\eOa"
"execute "set <C-Down>=\eOb"
execute "set <C-Left>=\eOd"
execute "set <C-Right>=\eOc"
"execute "set <A-Up>=\e\e[A"
"execute "set <A-Down>=\e\e[B"
"execute "set <A-Left>=\e\e[D"
"execute "set <A-Right>=\e\e[C"
endif
"common mappings
"enabling ctrl+space mapping (otherwise C-Space does nothing)
map <C-@> <C-Space>
map! <C-@> <C-Space>
"ctrl+backspace mapping (otherwise C-BS does nothing)
map <C-H> <C-BS>
map! <C-H> <C-BS>
"supported formating options for terminal are:
" *bold* *underline* *undercurl*
" *reverse*/*inverse* *italic* *standout*
"bold should work by default (see your terminal emulator setting for picking drawing bold as a color/bold as a font or both)
"works seamlessly from inside screen
"let &t_md = "\e[1m"
"let &t_me = "\e[m"
"underline should work by default
"works seamlessly from inside screen
"let &t_us = "\e[4m"
"let &t_ue = "\e[m"
"strikethrough (needs terminal support - KiTTY/PuTTY terminals cannot do strikethrough):
if v:version > 800 || (v:version == 800 && has('patch1038'))
if s:in_screen || &t_Ts ==# ''
let &t_Ts = s:ScreenEscape("\e[9m")
let &t_Te = s:ScreenEscape("\e[29m")
endif
endif
"reverse/inverse should work by default
"works seamlessly from inside screen
"let &t_mr = "\e[7m"
"italic (italics is already enabled in wombat256 colorscheme) needs escaping from within screen
" Vim will use &t_mr (reverse/inverse) or even &t_md (bold, if reverse is null) if sitm is not defined in the
" terminfo (searched based on &term variable), check using `infocmp | grep sitm`
if s:in_screen || &t_ZH ==# '' || &t_ZH ==# &t_mr || &t_ZH ==# &t_md
let &t_ZH = s:ScreenEscape("\e[3m")
let &t_ZR = s:ScreenEscape("\e[23m")
endif
"standout should work by default
"works seamlessly from inside screen
"let &t_so = "\e[7m"
"let &t_se = "\e[27m"
""" delete wait time after ESC key is pushed in insert mode
""let &t_SI .= "\e[?7727h"
""let &t_EI .= "\e[?7727l"
""inoremap <special> <Esc>O[ <Esc>
"Todo: check somehow, whether terminal is capable of cursor shape changes
"" changing cursor shape (works in xterm and from screen inside of xterm)
"if $STY != ''
" let &t_SI .= "\eP\e[5 q\e\\"
" let &t_EI .= "\eP\e[2 q\e\\"
"else
" let &t_SI .= "\e[5 q"
" let &t_EI .= "\e[2 q"
"endif
"
"Todo: cursor colors
"silent !echo -ne "\033]12;red\007"
"silent !echo -ne "\033]12;gray\007"
" Undercurl support (this does not really have terminfo spec so it cannot be learned based on &term)
" Supported in gnome-terminal/VTE derivatives (since VTE 52.00) and kitty (GPU terminal)
if v:version > 704 || (v:version == 704 && has('patch911'))
if s:term_program ==# 'gnome-terminal' && s:term_version >= 5200
let &t_Cs = s:ScreenEscape("\e[4:3m")
let &t_Ce = s:ScreenEscape("\e[4:0m")
set timeout timeoutlen=1000 ttimeoutlen=100
endif
endif
if has('termguicolors')
" 24-bit color support
" TODO(akocis): check older terminals and disable where needed
" set termguicolors
endif
if &t_ZH !=# ''
" some colorschemes look at this environment variable to decide whether to use italics or not
let $TERM_ITALICS='true'
let g:nord_italic_comments=1
endif
endif
endif
let g:color_scheme = ''
if has('gui_running')
if g:OS_name ==# 'windows'
"colorscheme zenburn
let g:molokai_original = 1
let g:color_scheme = 'molokai'
let g:airline_theme = 'molokai'
else
"colorscheme desert
if &t_Co == 256
let g:color_scheme = 'wombat256mod'
else
let g:color_scheme = 'wombat'
endif
let g:airline_theme = 'wombat'
endif
else
"no GUI - console mode
if g:OS_name ==# 'windows'
"8-color terminal in windows only, zellner looks OK
let g:color_scheme = 'zellner'
let g:airline_theme = 'dark'
else
if &t_Co == 256
let g:color_scheme = 'wombat256mod'
else
let g:color_scheme = 'wombat'
endif
let g:airline_theme = 'wombat'
endif
endif
set background=dark
"hi clear
filetype plugin indent on
"Todo: enable Eclim (by uncomenting following packadd and not defining disabled variable)
let g:EclimDisabled = 'defined'
"packadd! vim-eclim
if v:version < 704 || (v:version == 704 && !has('patch1578'))
let g:loaded_youcompleteme = 1 "too old Vim => disable YouCompleteMe
let g:loaded_numbers = 1
endif
if has('python3')
let g:ycm_server_python_interpreter = 'python3.6'
else
let g:ycm_server_python_interpreter = $HOME . '/toolchains/python2712/bin/python'
endif
" Use LSP clients (ALE and LanguageServer-neovim)
let g:use_lsp = 1
" Choose between clangd language server and the older libclang for C++ semantic parsing
" (requires libclang and/or clangd to be compiled into ycm)
let g:ycm_use_clangd = 1
" Let clangd fully control code completion (if set to 0)
let g:ycm_clangd_uses_ycmd_caching = 0
" " Use installed clangd, not YCM-bundled clangd which doesn't get updates.
" let g:ycm_clangd_binary_path = exepath("clangd")
let g:ycm_clangd_binary_path = $HOME . '/toolchains/llvm/bin/clangd'
" Extra args passed to clangd
" let g:ycm_clangd_args = []
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
"Do not ask when starting vim
let g:ycm_confirm_extra_conf = 0
function! g:YCM_tagfiles()
" full tags are too big for YCM
if $CSCOPE_FILES_DIR !=# ''
return [$CSCOPE_FILES_DIR . '/ycm.tags']
else
let s:fallback_ycm_tags = $HOME . '/tmp/ycm.tags'
if filereadable(s:fallback_ycm_tags)
return [s:fallback_ycm_tags]
else
return []
endif
endif
endfunction
let g:ycm_collect_identifiers_from_tags_files = 1
let g:ycm_add_preview_to_completeopt = 0
let g:ycm_key_invoke_completion = '<C-Space>'
let g:ycm_key_detailed_diagnostics = '<Leader><Leader>?'
let g:ycm_cache_omnifunc = 1 "takes simply too much memory in big projects (1GB of sources)
let g:ycm_always_populate_location_list = 1
let g:ycm_disable_for_files_larger_than_kb = 5000
if v:version >= 704
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
let g:ycm_filetype_blacklist = {
\ 'tagbar' : 1,
\ 'qf' : 1,
\ 'notes' : 1,
\ 'markdown' : 1,
\ 'unite' : 1,
\ 'text' : 1,
\ 'vimwiki' : 1,
\ 'pandoc' : 1,
\ 'infolog' : 1,
\ 'cfg' : 1,
\ 'mail' : 1,
\ 'tags' : 1,
\}
" disable semantic completion for these types
" (to prevent YCM writting python exception to its errlog file)
let g:ycm_filetype_specific_completion_to_disable = {
\ 'gitcommit': 1,
\ 'vim' : 1,
\}
endif
function! g:VimWarningMsg(text)
echohl WarningMsg
echomsg a:text
echohl None
endfunction
function! g:WinVarExists(winnr, variable_name)
try
let l:value = getwinvar(a:winnr, a:variable_name)
if type(l:value) != type('')
return 1
endif
if l:value !=# ''
return 1
endif
catch
endtry
return 0
endfunction
function! g:BalloonFormatTextLines(lines) abort
if type(a:lines) !=# type([])
let input_lines = [a:lines]
else
let input_lines = a:lines
endif
" split lines with embedded \n characters
let l:lines = []
for l:line in l:input_lines
let l:split_lines = split(l:line, '\n')
for l:split_line in l:split_lines
call add(l:lines, l:split_line)
endfor
endfor
return l:lines
endfunction
function! g:BalloonYcmHoverExpr() abort
let l:cmds = youcompleteme#GetDefinedSubcommands()
if index( l:cmds, 'GetHover' ) >= 0
let l:ycm_hover = {
\ 'command': 'GetHover',
\ 'syntax': 'markdown',
\ }
elseif index( l:cmds, 'GetDoc' ) >= 0
let l:ycm_hover = {
\ 'command': 'GetDoc',
\ 'syntax': '',
\ }
elseif index( l:cmds, 'GetType' ) >= 0
let l:ycm_hover = {
\ 'command': 'GetType',
\ 'syntax': &syntax,
\ }
else
return ['']
endif
" Todo: consider async
" call youcompleteme#GetCommandResponseAsync(
" \ function( 's:ShowHoverResult' ),
" \ 'GetType' )
" try
let l:hover_text = youcompleteme#GetCommandResponse(l:ycm_hover.command)
return g:BalloonFormatTextLines(l:hover_text)
" catch
" return ''
" endtry
endfunction
function! g:BalloonCocHoverExpr() abort
if !CocHasProvider('hover')
return ['']
endif
let l:hover_text = CocAction('getHover')
return g:BalloonFormatTextLines(l:hover_text)
endfunction
let s:balloon_text = []
let s:balloon_popup_winid = 0
let s:balloon_winid = 0
function! g:BalloonHoverExpr() abort
" for inspiration look at: ale#balloon#MessageForPos, (v:beval_bufnr, v:beval_lnum, v:beval_col)
let l:hover = ''
" use COC hover if available
if exists('*CocAction')
let l:hover = 'coc'
endif
if l:hover ==# ''
" support my custom lazy loading of YCM
if !exists('*youcompleteme#GetDefinedSubcommands') && exists(':YcmCompleter')
execute ':YcmCompleter LoadYouCompleteMe'
endif
if !exists('*youcompleteme#GetDefinedSubcommands')
return ''
endif
let l:hover = 'ycm'
endif
" no hover command available
if l:hover ==# ''
return ''
endif
let l:mouse_pos = [v:beval_bufnr, v:beval_lnum, v:beval_col]
let l:mouse_winnr = v:beval_winnr + 1 " why is the v:beval_winnr 0-based ?
let l:mouse_winid = win_getid(l:mouse_winnr)
let l:mouse_bufnr = winbufnr(l:mouse_winnr)
let l:orig_pos = getpos('.')
let l:orig_winnr = winnr()
let l:orig_winid = win_getid(l:orig_winnr)
if l:mouse_winnr != l:orig_winnr && !g:WinVarExists(l:mouse_winnr, 'mouse_scrolloff')
" store existing scroll offset
let l:mouse_scrolloff = getwinvar(l:mouse_winnr, '&l:scrolloff')
call setwinvar(l:mouse_winnr, 'mouse_scrolloff', l:mouse_scrolloff)
" force scroll offset to be 0 to prevent viewport jumps on mouse hover
call setwinvar(l:mouse_winnr, '&scrolloff', 0)
augroup reset_scrolloff
execute "autocmd! CursorMoved <buffer=" . l:mouse_bufnr . ">"
execute "autocmd CursorMoved <buffer=" . l:mouse_bufnr . ">"
\ " | if exists('w:mouse_scrolloff')"
\ " | let &l:scrolloff = w:mouse_scrolloff"
\ " | unlet w:mouse_scrolloff"
\ " | endif"
\ " | autocmd! reset_scrolloff CursorMoved <buffer=" . l:mouse_bufnr . ">"
augroup END
endif
if !win_gotoid(l:mouse_winid)
call g:VimWarningMsg('Unable to set cursor position to ' . l:mouse_pos . ' (winid: ' . l:mouse_winid . ')')
return ''
endif
let l:result = setpos('.', l:mouse_pos)
if l:result != 0
call g:VimWarningMsg('Unable to set cursor position to ' . l:mouse_pos . ' (winid: ' . l:mouse_winid . ')')
if !win_gotoid(l:orig_winid)
call g:VimWarningMsg('Unable to revert back to original winid ' . l:orig_winid)
endif
return ''
endif
try
" let l:currentoff = &l:scrolloff
" let l:currentpos = getpos('.')
" echomsg 'CUR ' . string(l:currentpos) . ' WIN ' . string(v:beval_winnr) . ' SO ' . l:currentoff
if l:hover ==# 'coc'
let s:balloon_text = g:BalloonCocHoverExpr()
elseif l:hover ==# 'ycm'
let s:balloon_text = g:BalloonYcmHoverExpr()
endif
if v:version > 801 || (v:version == 801 && has('patch1645'))
if s:balloon_popup_winid && popup_getpos(s:balloon_popup_winid) != {}
" previous popup window still shows
if v:beval_text == join(s:balloon_text, '\n')
" Still the same text, keep the existing popup
return ''
endif
call popup_close(s:balloon_popup_winid)
let s:balloon_popup_winid = 0
endif
" Vim 8.2 popup instead of balloon
if s:balloon_text ==# [] || s:balloon_text ==# ['']
return ''
endif
let s:balloon_popup_winid = popup_beval(s:balloon_text, {'mousemoved': 'word', 'highlight': 'StatusLine'})
return ''
else
" simple balloon
return s:balloon_text
endif
finally
if !win_gotoid(l:orig_winid)
call g:VimWarningMsg('Unable to revert back to original winid ' . l:orig_winid)
endif
let l:result = setpos('.', l:orig_pos)
if l:result != 0
call g:VimWarningMsg('Unable to reset cursor position back to ' . l:orig_pos . ' (winid: ' . l:orig_winid . ')')
endif
endtry
endfunction
" setup ballon expressions in Vim to use the YcmHover to retrieve doc/type/... from the LSP server
" neovim does not support balloons
if !has('balloon_eval') && !has('balloon_eval_term')
let g:ycm_auto_hover='CursorHold'
else
let g:ycm_auto_hover=''
if has('balloon_eval')
set ballooneval
endif
if has('balloon_eval_term')
set balloonevalterm
endif
set balloonexpr=g:BalloonHoverExpr()
endif
" Todo: remove these two global fuctions they are now obsolete, the plugin was changed to vim-select-multi
" these two must be global (needed for vim-multiple-cursors plugin)
function! g:Multiple_cursors_before()
if exists('*youcompleteme#DisableCursorMovedAutocommands')
call youcompleteme#DisableCursorMovedAutocommands()
endif
let b:ale_dont_show_cursor_detail = 1
let b:ale_dont_run = 0
" disable signature help
if exists('g:LanguageClient_signatureHelpOnTextChangedI')
let b:old_LanguageClient_signatureHelpOnTextChangedI=g:LanguageClient_signatureHelpOnTextChangedI
let g:LanguageClient_signatureHelpOnTextChangedI=0
endif
endfunction
function! g:Multiple_cursors_after()
if exists('*youcompleteme#EnableCursorMovedAutocommands')
call youcompleteme#EnableCursorMovedAutocommands()
endif
unlet! b:ale_dont_show_cursor_detail
if exists('b:ale_dont_run')
if b:ale_dont_run > 0
unlet! b:ale_dont_run
" Todo: run lint only if buffer was changed (see b:changedtick)
ALELint
else
unlet! b:ale_dont_run
endif
endif
" re-enable signature help
if exists('b:old_LanguageClient_signatureHelpOnTextChangedI')
let g:LanguageClient_signatureHelpOnTextChangedI=b:old_LanguageClient_signatureHelpOnTextChangedI
unlet! b:old_LanguageClient_signatureHelpOnTextChangedI
endif
endfunction
if has('autocmd')
" autocmd! User visual_multi_start call g:Multiple_cursors_before()
" autocmd! User visual_multi_exit call g:Multiple_cursors_after()
endif
let g:home_base_path=$HOME
let g:home_vim_folder = substitute(g:home_base_path, '[\/]$', '', '') . g:OS_dir_separator . '.vim'
" open files with the cursor at the last remembered position and also move change position to the end
" commit filetype buffers are ignored
" quickfix windows are ignored also (needed for ALE async lopen with linter errors during select-mode anomaly)
" ignore E663: At end of changelist
" ignore E664: changelist is empty
" ignore E19: Mark has invalid line number
function! g:JumpToLastPosition()
if &filetype =~# 'commit' || &filetype =~# 'qf'
return
endif
try
keepjumps execute 'normal! 999g,'
" if we have old changes and last of them is valid, then temporarily override g; with jump to latest change + unmap g;
" this should help with first g; after buffer load to not go to the second last change
nnoremap <silent> g; :<C-U>execute 'normal! g`.'<Bar>nunmap g;<CR>
catch /:E663:\|:E664:\|:E19:/
endtry
try
" if line("'\"") > 0 && line("'\"") <= line("$")
execute 'normal! g`"'
" endif
catch /:E19:\|:E20:/
endtry
endfunction
if has('autocmd')
autocmd! BufReadPost * call g:JumpToLastPosition()
endif
set helplang=en
set langmenu=en
"set ttybuiltin "this is default
" set notbi
"set ttymouse xterm2 "VIM autodetect from TERM env variable name (=~xterm => xterm2)
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set nobackup " DON'T keep a backup file
set history=400 " keep 400 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set tabstop=4
set number " line numbers
if exists('+relativenumber')
" overriden by insert/normal mode changes via numbers plugin
set relativenumber " relative line numbers
endif
if has('patch-8.1.1564')
" set signcolumn=number
set signcolumn=auto
endif
set cindent
set autoindent
if has('mouse')
set mouse=a " use mouse in xterm to scroll
endif
set scrolloff=5 " 5 lines before and after the current line when scrolling - overriden later
set ignorecase " ignore case
set smartcase " but don't ignore it, when search string contains uppercase letters
set hidden " allow switching buffers, which have unsaved changes
set shiftwidth=4 " 4 characters for indenting
set showmatch " showmatch: Show the matching bracket for the last ')'?
set nowrap " don't wrap by default
syn on
set confirm
set hlsearch
set nostartofline
"set shiftround
set splitright
set splitbelow
"set autoread
"set display+=uhex
set display+=lastline
set formatoptions=tcq
if v:version > 703 || (v:version == 703 && has('patch552'))
set formatoptions+=j
endif
set nrformats=hex
if v:version > 704 || (v:version == 704 && has('patch1027'))
set nrformats+=bin
endif
set complete=.,w,b,u,t,i,kspell
if has('wildmenu')
set wildmenu
endif
"set wildmode=longest:full,list:full
set wildmode=full
" set side scrolling
set sidescrolloff=8
set sidescroll=1
" always show status line (irregardless of number of shown windows)
set laststatus=2
" turn off visual paren/bracket matching (Vim official plugin - ~/apps/share/vim/vim80/plugin/matchparen.vim)
"let g:loaded_matchparen=1
" turn off vimball plugin (Vim official plugin - ~/apps/share/vim/vim80/plugin/vimballPlugin.vim)
let g:loaded_vimballPlugin=1
"convenience mappings
nnoremap Q <nop>
"if has("user_commands")
" command! -bang -nargs=? -complete=file E e<bang> <args>
" command! -bang Wa wa<bang>
"endif
function! g:CommandModeAbbreviation(abbreviation, command, also_visual)
if a:also_visual
" TODO(akocis): check if end of first word and comma has been entered (will cover more visual range cases)
let l:cmd = 'cabbrev ' . a:abbreviation . " <c-r>=(getcmdtype()==':' &&"
\ . " (getcmdpos()==1 \\|\\| getcmdline()[0:4]==#\"'<,'>\") ? '" . a:command . "' : '" . a:abbreviation . "')" . '<CR>'
execute l:cmd
else
execute 'cabbrev ' . a:abbreviation . " <c-r>=(getcmdtype()==':' &&"
\ . " getcmdpos()==1 ? '" . a:command . "' : '" . a:abbreviation . "')" . '<CR>'
endif
endfunction
" add abbreviations for common holding shift for too long typos for standart Vim commands
call g:CommandModeAbbreviation('E', 'e', 0)
call g:CommandModeAbbreviation('W', 'w', 0)
call g:CommandModeAbbreviation('Wq', 'wq', 0)
call g:CommandModeAbbreviation('WQ', 'wq', 0)
call g:CommandModeAbbreviation('Wa', 'wa', 0)
call g:CommandModeAbbreviation('WA', 'wa', 0)
call g:CommandModeAbbreviation('Q', 'q', 0)
call g:CommandModeAbbreviation('Qa', 'qa', 0)
call g:CommandModeAbbreviation('QA', 'qa', 0)
call g:CommandModeAbbreviation('X', 'x', 0)
call g:CommandModeAbbreviation('Xa', 'xa', 0)
call g:CommandModeAbbreviation('XA', 'xa', 0)
"no splash screen
set shortmess+=I
"visual block extension beyong line endings ($ still selects up to respective line end)
set virtualedit=block
if v:version >= 700
set tabpagemax=25
endif
" improved search and replace (cgn operations)
" replaces
nnoremap c* *Ncgn
nnoremap c# #NcgN
" appends
nnoremap c>* *Ncgn<C-r>"
nnoremap c># #NcgN<C-r>"
" prepends
if v:version < 801 || (v:version == 801 && !has('patch1055'))
" workaround for <C-g>U and <S-Left> bug in versions < 8.1.1055
if v:version > 704 || (v:version == 704 && has('patch849'))
" older versions than 7.4.849 cannot do the workaround based on <C-g>U in insert mode
nnoremap <expr> c<* '*Ncgn<C-r>"'.repeat('<C-g>U<Left>',strlen(@"))
nnoremap <expr> c<# '*NcgN<C-r>"'.repeat('<C-g>U<Left>',strlen(@"))
endif
else
nnoremap c<* *Ncgn<C-r>"<C-g>U<S-Left>
nnoremap c<# #NcgN<C-r>"<C-g>U<S-Left>
endif
"function! Align()
" '<,'>!column -t|sed 's# \(\S\)# \1#g'
" normal gv=
"endfunction
"
"xnoremap <silent> gQ :<C-u>silent call Align()<CR>
"needs to be after syn on (syntax on)