-
Notifications
You must be signed in to change notification settings - Fork 10
/
vimrc
8193 lines (6988 loc) · 272 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
" vim:tw=80:ts=4:sts=4:sw=4:et:ai
" =============================================================
" Early Setup
" =============================================================
if has('nvim') && !exists('g:python3_host_prog')
" Ensure Neovim Python provider is setup before any use of Python.
for s:pynvim_python in [
\ expand('~/venvs/pynvim/bin/python'),
\ expand('~/venvs/pynvim/Scripts/python.exe'),
\ '/opt/pynvim/bin/python'
\ ]
if executable(s:pynvim_python)
let g:python3_host_prog = s:pynvim_python
break
endif
endfor
endif
" Enable vi-incompatible Vim extensions (redundant since .vimrc exists).
set nocompatible
" Use utf-8 encoding for all content.
set encoding=utf-8
" 'fileencodings' contains a list of possible encodings to try when reading
" a file. When 'encoding' is a unicode value (such as utf-8), the
" value of fileencodings defaults to ucs-bom,utf-8,default,latin1.
" ucs-bom Treat as unicode-encoded file if and only if BOM is present
" utf-8 Use utf-8 encoding
" default Value from environment LANG
" latin1 8-bit encoding typical of DOS
" Setting this value explicitly, though to the default value.
set fileencodings=ucs-bom,utf-8,default,latin1
" Turn off syntax highlighting and filetype support in case a system vimrc
" has enabled them. We'll turn them back on after necessary configuration
" has been done.
syntax off
filetype plugin indent off
filetype off
" Leaving 'fileencoding' unset, as it defaults to the value of 'encoding'.
" May set 'fileencoding' before writing a file to force a new encoding.
" May also set 'bomb' to force use of a BOM (Byte Order Mark).
" set fileencoding=
" `v:true` and `v:false` were added in Vim-7.4.1271, 2016-02-06.
if exists('v:true')
let g:local_true = v:true
let g:local_false = v:false
else
let g:local_true = 1
let g:local_false = 0
endif
" Set environment variable to directory containing this vimrc. Expect absolute
" directory $HOME/.vim on Unix or %USERPROFILE%\vimfiles on Windows.
let $VIMFILES = expand("<sfile>:p:h")
function! DetectPlatform()
if has("gui_win32")
return "win32"
endif
" Assume we're on a Unix box.
let name = substitute(system("uname"), '^\_s*\(.\{-}\)\_s*$', '\1', '')
return tolower(name)
endfunction
function! DetectVmware(platform)
if a:platform == "linux"
if filereadable("/sys/class/dmi/id/sys_vendor")
for line in readfile("/sys/class/dmi/id/sys_vendor", '', 10)
if line =~ '\cvmware'
return 1
endif
endfor
endif
elseif a:platform == "freebsd"
if executable("kldstat")
let output = system("kldstat")
if output =~ "vmxnet"
return 1
endif
endif
endif
return 0
endfunction
let g:Platform = DetectPlatform()
let g:InVmware = DetectVmware(g:Platform)
function! AdjustBaseFontSize(size)
if g:Platform != "darwin"
return a:size
endif
" Mac's idea of a point on screen is not the same as everyone else's.
" It appears that most operating systems either expect the screen to be 96
" DPI, or will query the monitor. Mac, on the other hand, assumes that the
" monitor is 72 DPI.
return ((a:size * 96) + 35) / 72
endfunction
" -------------------------------------------------------------
" List manipulation
" -------------------------------------------------------------
function! Flatten(nestedLists)
let flattened = []
let i = 0
while i < len(a:nestedLists)
if type(a:nestedLists[i]) == type([])
let flattened += Flatten(a:nestedLists[i])
else
let flattened += [a:nestedLists[i]]
endif
let i += 1
endwhile
return flattened
endfunction
function! ListContains(list, valueToFind)
for item in a:list
if item == a:valueToFind
return 1
endif
endfor
return 0
endfunction
" Pop leftmost element from list; if list is empty, return defaultValue instead.
function! ListPop(list, defaultValue)
let value = a:defaultValue
if len(a:list) > 0
let value = a:list[0]
unlet a:list[0]
endif
return value
endfunction
" -------------------------------------------------------------
" Utility functions
" -------------------------------------------------------------
" Make sure to include the proper scope on varName (e.g., an unprefixed
" variable will not be considered global).
function! GetVar(varName, defaultValue)
if exists(a:varName)
return eval(a:varName)
endif
return a:defaultValue
endfunction
function! DictGet(dict, key, defaultValue)
if has_key(a:dict, a:key)
return a:dict[a:key]
endif
return a:defaultValue
endfunction
function! DictUnlet(dict, key)
if has_key(a:dict, a:key)
unlet a:dict[a:key]
endif
endfunction
" Verify len(varArgs) <= maxNumArgs, then return a modifiable copy of varArgs.
function! VarArgs(maxNumArgs, varArgs)
let args = copy(a:varArgs)
if len(args) > a:maxNumArgs
throw "Too many arguments supplied (>" . a:maxNumArgs . ")"
endif
return args
endfunction
" Verify len(varArgs) is 0 or 1; return sole arg or defaultValue if none given.
function! OptArg(varArgs, defaultValue)
return ListPop(VarArgs(1, a:varArgs), a:defaultValue)
endfunction
" Acquire the list of all loaded scripts as absolute paths.
" Paths will use native separators (e.g., /unix/path or \windows\path).
function! ScriptPaths()
redir => lines
silent! scriptnames
redir END
let paths = []
for line in split(lines, '\n')
let path = substitute(line, '^\s*[0-9]\+:\s*\(.*\)', '\1', '')
call add(paths, fnamemodify(path, ':p'))
endfor
return paths
endfunction
" Return absolute ScriptPath that matches given script.
" If an exact match can be found, it will be returned. Otherwise, if exactly
" one absolute path has a:script as a suffix, it will be returned.
" The empty string is returned on failure.
function! GetScript(script)
let paths = ScriptPaths()
let matches = []
for path in paths
if path == a:script
return path
elseif path[-len(a:script):] == a:script
call add(matches, path)
endif
endfor
if len(matches) == 1
return matches[0]
endif
return ''
endfunction
" Lookup the <SID> for a given script. This allows for accessing
" script-local variables.
" Return 0 on failure.
function! GetSID(script)
let path = GetScript(a:script)
if path != ''
return index(ScriptPaths(), path) + 1
endif
return 0
endfunction
" Lookup symbol in s: of given script.
" Uses GetSID(script) to locate the <SID> of the given script; if found,
" creates the script-local name ('<SNR>' . sid . '_' . symbol).
function! GetSymbol(script, symbol)
let sid = GetSID(a:script)
if sid > 0
return '<SNR>' . sid . '_' . a:symbol
endif
return ''
endfunction
" Return [line, col] subset of the output of getpos(expr).
function! GetPos(expr)
return getpos(a:expr)[1:2]
endfunction
" [line, col] points to the start of a character in the buffer.
" [1, 1] indicates the [first line, first character on the line].
" Adjust col to point to the final byte of this character; this will do nothing
" for single-byte characters.
function! AdjustColToCharEnd(line, col)
let end_col = a:col
" Match a single character at end_col.
" Note that end_col might be an oversize value (e.g., 2147483647)
" compared to the number of bytes on the corresponding line. This occurs
" when doing a linewise selection, for example. To keep matchstr() from
" throwing E951 due to an oversized column number, avoid testing the
" text when end_col is too large to need incrementation.
let text = getline(a:line)
if end_col < len(text)
let num_bytes = len(matchstr(text, '\%' . end_col . 'c.'))
if num_bytes > 1
let end_col += num_bytes - 1
endif
endif
return end_col
endfunction
" If start_pos comes after end_pos in the buffer, reverse them.
" Return the pair in their proper order within the buffer.
function! NormalizeStartEndPos(start_pos, end_pos)
let [start_line, start_col] = a:start_pos
let [end_line, end_col] = a:end_pos
if start_line > end_line || (start_line == end_line && start_col > end_col)
return [a:end_pos, a:start_pos]
endif
return [a:start_pos, a:end_pos]
endfunction
" start_pos = [start_line, start_col]
" end_pos = [end_line, end_col]
" end_pos may be earlier in the buffer than start_pos.
" Each col number is a one-based byte index into the corresponding line.
" For example, [1, 1] is the first line, first column.
" If the ending column points to a multi-byte character, the byte index must
" be adjusted to include all of the bytes in that character.
" Ref: https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript
function GetLines(start_pos, end_pos)
let [start_pos, end_pos] = NormalizeStartEndPos(a:start_pos, a:end_pos)
let [start_line, start_col] = start_pos
let [end_line, end_col] = end_pos
" Account for end_col pointing to multi-byte character.
let end_col = AdjustColToCharEnd(end_line, end_col)
let lines = []
let end_final_col = col([end_line, '$'])
let start_line_text = getline(start_line)
if start_line == end_line
if end_col >= end_final_col
call extend(lines, [start_line_text[(start_col - 1):], ""])
else
call add(lines, start_line_text[(start_col - 1):(end_col - 1)])
endif
else
call add(lines, start_line_text[(start_col - 1):])
let end_line_text = getline(end_line)
if (end_line - start_line) > 1
call extend(lines, getline(start_line + 1, end_line - 1))
endif
if end_col < end_final_col
call add(lines, end_line_text[:(end_col - 1)])
else
call extend(lines, [end_line_text, ""])
endif
endif
return lines
endfunction
" start_pos = [start_line, start_col]
" end_pos = [end_line, end_col]
" Joins lines returned from GetLines(start_pos, end_pos) into a single string.
function GetText(start_pos, end_pos)
return join(GetLines(a:start_pos, a:end_pos), "\n")
endfunction
" Get most recently selected visual text.
function GetSelectedText()
return GetText(GetPos("'<"), GetPos("'>"))
endfunction
" -------------------------------------------------------------
" runtimepath manipulation
" -------------------------------------------------------------
" Escape commas and backslashes in path.
function! PathEscape(path)
return escape(a:path, ',\')
endfunction
" Un-escape commas and backslashes in path.
function! PathUnescape(path)
" Very magic.
let rex = '\v'
" Find escaping backslash, capture following backslash or a comma.
let rex .= '\\([\\,])'
return substitute(a:path, rex, '\1', "g")
endfunction
" Join paths into comma-separated path string.
" Backslashes and commas will be escaped in final string.
" Arguments are individual strings or lists of strings.
function! PathJoin(...)
let paths = Flatten(a:000)
let paths = map(paths, 'PathEscape(v:val)')
let path = join(paths, ",")
return path
endfunction
" Split comma-separated path string into a list.
" Honors escaped backslashes and commas.
function! PathSplit(path)
" Split regex: Very magic.
let rex = '\v'
" Begin match after a non-backslash.
let rex .= '\\@<!'
" Match an zero or more pairs of backslashes; each pair
" represents a single escaped backslash.
let rex .= '%(\\\\)*'
" Now set start-of-match and require a comma (which is necessarily not
" escaped).
let rex .= '\zs,'
let paths = split(a:path, rex)
" Unescape individual paths.
let paths = map(paths, 'PathUnescape(v:val)')
return paths
endfunction
function! RtpPrepend(path)
if isdirectory(a:path)
let &runtimepath = PathEscape(a:path) . "," . &runtimepath
let after = a:path . "/after"
if isdirectory(after)
let &runtimepath = &runtimepath . "," . PathEscape(after)
endif
endif
endfunction
" Append path later in &runtimepath than refPath (similarly for path/after).
" - Non-existing paths are not added to &runtimepath.
" - If refPath does not exist, path is inserted at start of &runtimepath.
" - If refPath/after does not exist, path/after is added to end of &runtimepath.
function! RtpAppend(path, refPath)
if isdirectory(a:path)
let rtpParts = PathSplit(&runtimepath)
let i = index(rtpParts, a:refPath)
if i >= 0
call insert(rtpParts, a:path, i + 1)
else
call insert(rtpParts, a:path, 0)
endif
let after = a:path . "/after"
if isdirectory(after)
let i = index(rtpParts, a:refPath . "/after")
if i >= 0
call insert(rtpParts, after, i)
else
call add(rtpParts, after)
endif
endif
let &runtimepath = PathJoin(rtpParts)
endif
endfunction
" If script exists, source it.
function! Source(script)
let expandedPath = expand(a:script)
if filereadable(expandedPath)
execute 'source ' . expandedPath
endif
endfunction
" Inserts directory "path" right after $VIMUSERFILES in &runtimepath. If
" "path/after" exists, it will be inserted just before $VIMUSERFILES/after (or
" appended to the end of &runtimepath if $VIMUSERFILES/after is not in
" &runtimepath).
"
" The goal is to allow inheriting another user's configuration. This will get
" &runtimepath fixed up correctly, but you still need to source the before and
" after scripts within your before and after scripts, respectively.
function! RtpInherit(path)
call RtpAppend(a:path, $VIMUSERFILES)
endfunction
" -------------------------------------------------------------
" Ensure `$VIMFILES` is in 'runtimepath'.
" -------------------------------------------------------------
if index(PathSplit(&runtimepath), $VIMFILES) < 0
call RtpPrepend($VIMFILES)
endif
" -------------------------------------------------------------
" Per-user customization pre-setup
" -------------------------------------------------------------
" NOTE: Several environment variables follow that may be customized.
" See doc/notes.txt in the |notes_customizations| section for details about
" these variables.
"
" Environment variables are used instead of Vim variables to allow
" configuration at the operating-system level outside of Vim.
" VIMUSER defaults to the logged-in user, but may be overridden to allow
" multiple user to share the same overrides (e.g., to let "root" share settings
" with another user).
if $VIMUSER == ""
let $VIMUSER = expand(has('win32') ? '$USERNAME' : '$USER')
endif
" Parent directory of .vim/vimfiles (typically $HOME).
let s:vimParent = fnamemodify($VIMFILES, ':h')
let s:slashdot = has('win32') ? '/_' : '/.'
if $VIMLOCALFILES == ''
let $VIMLOCALFILES = s:vimParent . s:slashdot . 'vimlocal'
if !isdirectory($VIMLOCALFILES)
let $VIMLOCALFILES = expand('$VIMFILES/local')
endif
endif
if $VIMUSERFILES == ''
let $VIMUSERFILES = s:vimParent . s:slashdot . 'vimuser'
if !isdirectory($VIMUSERFILES)
let $VIMUSERFILES = expand('$VIMFILES/user/$VIMUSER')
endif
endif
if $VIMUSERLOCALFILES == ''
let $VIMUSERLOCALFILES = s:vimParent . s:slashdot . 'vimuserlocal'
endif
" To enable, disable, or check the enabled status of a plugin, use the below
" functions:
"
" call vimf#plugin#enable('plugin_name')
" call vimf#plugin#disable('plugin_name')
" if vimf#plugin#enabled('plugin_name')
" " 'plugin_name' is enabled....
" endif
"
" NOTE: Plugin enabling or disabling must be performed very early in your
" vimrc-vars.vim.
"
" Plugin enabling is based on the Pathogen plugin.
" Define an empty g:pathogen_disabled so users can assume it always exists.
if !exists('g:pathogen_disabled')
let g:pathogen_disabled = []
endif
" Disable an experimental plugin for users in general. Do this early (before
" `vimrc-vars.vim`):
" call vimf#plugin#disable('plugin_name')
" Activate pathogen in case a user would need to activate a bundle in
" |VIMRC_VARS| as part of setting up some variable.
runtime bundle/pathogen/autoload/pathogen.vim
" Source |VIMRC_VARS| files (if they exist), lowest-to-highest priority order.
" Note that $VIMUSERFILES won't yet be in the 'runtimepath'.
call Source('$VIMLOCALFILES/vimrc-vars.vim')
call Source('$VIMUSERFILES/vimrc-vars.vim')
call Source('$VIMUSERLOCALFILES/vimrc-vars.vim')
" Prepend override directories in lowest-to-highest priority order, so that
" the highest priority ends up first in 'runtimepath'.
call RtpPrepend($VIMLOCALFILES)
call RtpPrepend($VIMUSERFILES)
call RtpPrepend($VIMUSERLOCALFILES)
" Setup an environment variable for cache-related bits. This follows
" XDG_CACHE_HOME by default, but can be overridden by the user.
if $VIM_CACHE_DIR == ""
if $XDG_CACHE_HOME != ""
let $VIM_CACHE_DIR = expand("$XDG_CACHE_HOME/vim")
else
if has("win32")
let $VIM_CACHE_DIR = expand("$USERPROFILE/.cache/vim")
else
let $VIM_CACHE_DIR = expand("$HOME/.cache/vim")
endif
endif
endif
" -------------------------------------------------------------
" Python path management
" -------------------------------------------------------------
if has('python3')
let g:Python = 'python3'
elseif has('python')
let g:Python = 'python'
else
let g:Python = ''
endif
" Determine best system Python executable.
if !exists('g:PythonExecutable')
if executable('python3') == 1
let g:PythonExecutable = 'python3'
elseif executable('python') == 1
let g:PythonExecutable = 'python'
else
let g:PythonExecutable = ''
endif
endif
" Setup Python's sys.path to include any "python2", "python3", or "pythonx"
" directories found as immediate children of paths in Vim's 'runtimepath'. This
" allows for more easily sharing Python modules.
" Only need to run if Vim is not at least 7.3.1163.
" See :help python-special-path (>=7.3.1163) for more information.
if has('python3') || has('python')
if v:version < 703 || (v:version == 703 && !has('patch1163'))
function! AugmentPythonPath(python, folders)
execute a:python . ' << endpython'
import vim
import os
for p in vim.eval("PathSplit(&runtimepath)"):
for f in vim.eval("a:folders"):
libPath = os.path.join(p, f)
if os.path.isdir(libPath) and libPath not in sys.path:
sys.path.append(libPath)
endpython
endfunction
if has('python3')
call AugmentPythonPath('python3', ['pythonx', 'python3'])
endif
if has('python')
call AugmentPythonPath('python', ['pythonx', 'python2'])
endif
endif
endif
" -------------------------------------------------------------
" Plugin enables
" -------------------------------------------------------------
" These must be handled before pathogen#infect() below.
" To disable one of the specified plugins below, define the corresponding
" g:EnableXxx variables below to be 0 (typically, this would be done in
" the per-user VIMRC_VARS file, as plugin enable/disable adjustments must be
" done early).
" For example, to disable the UltiSnips plugin, use the following:
" let g:EnableUltiSnips = 0
if !exists('g:EnableAle')
let g:EnableAle = !has('nvim')
endif
if !exists('g:EnableSyntastic')
let g:EnableSyntastic = !has('nvim')
endif
if !exists('g:EnableVimLsp')
let g:EnableVimLsp = !has('nvim')
endif
" Determine vim-lsp compatibility.
if has('nvim')
" TODO: Determine what version of Neovim is required for vim-lsp.
else
" vim-lsp requires Vim 8.1.1035 or newer.
if v:version < 801 || (v:version == 801 && !has('patch1035'))
let g:EnableVimLsp = 0
endif
endif
" Gvim bug https://github.com/vim/vim/issues/3417 is fixed in Gvim 8.1.0834.
" Without this patch, Gvim support for timers is buggy, so ALE should not be
" enabled.
if v:version < 801 || (v:version == 801 && !has('patch0834'))
let g:EnableAle = 0
endif
" Prefer Ale to Syntastic.
if g:EnableAle
let g:EnableSyntastic = 0
endif
if !g:EnableSyntastic
call vimf#plugin#disable('syntastic')
" Define :SyntasticReset so other Syntastic wrapper functions will not fail.
command! SyntasticReset let b:syntastic_enabled = 0
endif
if !g:EnableAle
call vimf#plugin#disable('ale')
endif
if !g:EnableVimLsp
call vimf#plugin#disable('vim-lsp')
call vimf#plugin#disable('vim-lsp-ale')
endif
" Don't use Powerline or Airline on 8-color terminals; they don't look good.
if !has("gui_running") && &t_Co == 8
let g:EnableAirline = 0
let g:EnablePowerline = 0
endif
if !exists("g:EnableAirline")
let g:EnableAirline = 1
endif
if !exists("g:EnablePowerline")
let g:EnablePowerline = 0
endif
if g:EnablePowerline
let g:EnableAirline = 0
endif
" Disable Powerline and/or Airline.
if !g:EnablePowerline
call vimf#plugin#disable('powerline')
endif
if !g:EnableAirline
call vimf#plugin#disable('airline')
call vimf#plugin#disable('airline-themes')
endif
if !exists("g:EnableUltiSnips")
" UltiSnips now requires Python3.
let g:EnableUltiSnips = has('python3')
endif
if !exists('g:EnableOmniCppComplete')
let g:EnableOmniCppComplete = !has('nvim')
endif
if !g:EnableOmniCppComplete
call vimf#plugin#disable('omnicppcomplete')
endif
" -------------------------------------------------------------
" Pathogen bundle management
" -------------------------------------------------------------
" Bundle directories:
"
" - `bundle/` is for bundles used by both Vim and Neovim.
" - `nvim-bundle/` is for Neovim-only bundles.
" - `vim-bundle/` is for Vim-only bundles.
" - Bundles in a directory with prefix `pre-` will come earlier in the
" 'runtimepoath' than those without the prefix.
" Infect all bundle directories in order of increasing priority.
if has('nvim')
let s:editor_name = 'nvim'
else
let s:editor_name = 'vim'
endif
let g:vimf_bundle_dirnames = [
\ 'bundle',
\ s:editor_name . '-bundle',
\ 'pre-bundle',
\ 'pre-' . s:editor_name . '-bundle',
\ ]
for s:dirname in g:vimf_bundle_dirnames
call pathogen#infect(s:dirname . '/{}')
endfor
" Enable 24-bit color for terminals that support it.
" To countermand this, put ``set notermguicolors`` in your vimrc-before file.
if $COLORTERM == 'truecolor'
if has("termguicolors")
set termguicolors
endif
if $TERM =~ 'screen\|tmux'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
endif
" -------------------------------------------------------------
" "vimrc-before" overrides
" -------------------------------------------------------------
" Execute in highest-to-lowest priority order, so that high-priority
" gets the first word (and also the last word via vimrc-after).
call Source('$VIMUSERLOCALFILES/vimrc-before.vim')
call Source('$VIMUSERFILES/vimrc-before.vim')
call Source('$VIMLOCALFILES/vimrc-before.vim')
" Determine if Vim's auto-detected 'background' option is trustworthy.
function! BackgroundIsTrustworthy()
if has('gui_running')
" Without a terminal, there is no background context to detect.
return 0
endif
if $COLORFGBG != ''
" COLORFBBG is a good indicator of the terminal background color.
return 1
endif
" In Vim 7.4.757 (2015-06-25), support was added to probe for the terminal's
" background color. This is a feature of xterm that some other terminals
" have added (notably, and sadly, not tmux (yet)). However, there is no
" easy way for us to tell whether the terminal responded to the request for
" background color with this early support. Later, Vim 8.0.1016
" (2017-08-30) brought in the variable v:termrgbresp (mis-spelled) to hold
" the terminal's response to the background color query. The spelling was
" corrected to v:termrbgresp in Vim 8.0.1194 (2017-10-14) (though the
" runtime documentation wasn't corrected until 2017-11-02). If either of
" these variables exists and is non-empty, then Vim successfully learned the
" true background color from the terminal and 'background' is trustworthy.
" Well, bummer. The above paragraph sounds nice, but the reality is that
" v:termrbgresp isn't set yet while the .vimrc is being processed. Other
" than setting a timer and probing for it, there isn't a way to use the
" automatically probed values. The question has come up on the list:
" https://groups.google.com/forum/#!topic/vim_use/zV2sO-m3fD0
" Sounds like there may someday be an autocommand for reporting back
" the background color, but it's not clear how that can help us determine
" which colorscheme to choose since it will come later than we'd like.
"
" TODO: Revisit this if Vim ever gets better support for v:termrbgresp:
" if (exists('v:termrgbresp') && v:termrgbresp != '') ||
" \ (exists('v:termrbgresp') && v:termrbgresp != '')
" return 1
" endif
return 0
endfunction
" =============================================================
" Title
" =============================================================
" Enable setting the title in the titlebar.
set title
" Defer calculation of 'titlestring' until entering Vim, as it depends
" on the value of `v:servername` that won't be set this early.
augroup vimf_title
autocmd!
autocmd VimEnter * call vimf#init#setupTitle()
augroup END
" =============================================================
" Color schemes
" =============================================================
" Setup a color scheme early for better visibility of errors and to nail down
" 'background' (which changes when a new colorscheme is selected).
" If a user sets up a colorscheme in his |VIMRC_BEFORE| script (or early in his
" ~/.vimrc file), the varible g:colors_name will be set and no default
" colorscheme selection will take place. To use no colorscheme at all, set
" g:colors_name to the empty string.
" If the user hasn't chosen a colorscheme, we setup a default. If we can't
" trust the background color detection, we force a dark background.
if !exists("g:colors_name")
if !BackgroundIsTrustworthy()
set background=dark
endif
if &background == "dark"
if !has("gui_running") && &t_Co <= 8
" With only a few colors, it's better to use a simple colorscheme.
colorscheme elflord
else
" Dark scheme maintained by John Szakmeister.
colorscheme szakdark
endif
else
colorscheme nuvola
endif
endif
" Provide a default Powerline colorscheme.
if !exists("g:Powerline_colorscheme")
if &background == "dark"
let g:Powerline_colorscheme = 'szakdark'
else
" At present, we don't have complete support for light backgrounds
" (though 'nuvola' is a start at it).
endif
endif
" Highlight the column just after &textwidth (unless &textwidth is zero).
if exists('+colorcolumn')
set colorcolumn=+1
endif
" =============================================================
" GUI Setup
" =============================================================
if !exists("g:DefaultFontFamilies")
let g:DefaultFontFamilies = []
endif
let g:DefaultFontFamilies += [
\ "Hack",
\ "PragmataPro for Powerline",
\ "PragmataPro",
\ "DejaVu Sans Mono for Powerline",
\ "Droid Sans Mono for Powerline",
\ "Consolas for Powerline",
\ "DejaVu Sans Mono",
\ "Droid Sans Mono",
\ "Consolas",
\]
" Font Families matching the regex patterns below have known-good Unicode
" symbols for use with Powerline.
if !exists("g:GoodUnicodeSymbolFontFamilyPatterns")
let g:GoodUnicodeSymbolFontFamilyPatterns = []
endif
let g:GoodUnicodeSymbolFontFamilyPatterns += [
\ '^PragmataPro\>',
\ '^DejaVu Sans Mono\>',
\ '^Droid Sans Mono\>',
\]
function! FontSupportsPowerlineSymbols(family)
if a:family =~# ' Powerline$' || a:family == 'Hack'
return 1
endif
return 0
endfunction
" Return type of Powerline symbols to use for given font family.
" Value will be one of "fancy", "unicode", or "compatible".
function! PowerlineSymbolsForFontFamily(family)
if FontSupportsPowerlineSymbols(a:family)
return "fancy"
endif
for pattern in g:GoodUnicodeSymbolFontFamilyPatterns
if a:family =~# pattern
return "unicode"
endif
endfor
return "compatible"
endfunction
function! AirlineCustomizeSymbols()
if !exists("g:airline_symbols")
let g:airline_symbols = {}
endif
if exists("g:FontFamily") && FontSupportsPowerlineSymbols(g:FontFamily)
let g:airline_left_sep = "\ue0b0"
let g:airline_left_alt_sep = "\ue0b1"
let g:airline_right_sep = "\ue0b2"
let g:airline_right_alt_sep = "\ue0b3"
let g:airline_symbols.crypt = "\ue0a2"
let g:airline_symbols.whitespace = "\u2739"
let g:airline_symbols.linenr = "\ue0a1"
let g:airline_symbols.maxlinenr = "\u2630"
let g:airline_symbols.branch = "\ue0a0"
else
" let g:airline_left_sep = '»'
" let g:airline_left_sep = '▶'
" let g:airline_left_sep = '│'
" let g:airline_left_sep = ''
" let g:airline_left_sep = '>'
let g:airline_left_sep = ' '
let g:airline_left_alt_sep = '>'
" let g:airline_right_sep = '«'
" let g:airline_right_sep = '◀'
" let g:airline_right_sep = '│'
" let g:airline_right_sep = ''
" let g:airline_right_sep = '<'
let g:airline_right_sep = ' '
let g:airline_right_alt_sep = '<'
let g:airline_symbols.crypt = '🔒'
let g:airline_symbols.whitespace = 'WS:'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.branch = '⚡'
endif
endfunction
command! -bar AirlineCustomizeSymbols call AirlineCustomizeSymbols()
function! SetFont()
if !has("gui_running")
return
endif
if !exists("g:FontFamily")
let g:FontFamily = fontdetect#firstFontFamily(g:DefaultFontFamilies)
endif
if !exists("g:FontSize")
let g:FontSize = AdjustBaseFontSize(14)
endif
if g:FontFamily != "" && g:FontSize > 0
if has("gui_gtk2") || has("gui_gtk3")
let font = g:FontFamily . " " . g:FontSize
else
let font = g:FontFamily . ":h" . g:FontSize
endif
let &guifont = font
let g:Powerline_symbols = PowerlineSymbolsForFontFamily(g:FontFamily)
AirlineCustomizeSymbols
endif
endfunction
command! -bar SetFont call SetFont()
if has("gui_running")
" 'T' flag controls the toolbar (we don't need it).
set guioptions-=T
" 'a' is for Autoselect mode, in which selections will automatically be
" added to the clipboard (on Windows) or the primary selection (on Unix).
" This makes it hard to create a selection and then overwrite it with
" something from the clipboard, so we disable it.
set guioptions-=a
" 'L' causes a left-side scrollbar to automatically appear when a
" vertical split is created. Unfortunately, there is a timing bug of
" some kind in Vim that sometimes prevents 'columns' from being
" properly maintained when the comings and goings of the scrollbar
" change the width of the GUI frame. The right-side scrollbar still
" functions properly for the active window, so there's no need for the
" left-side scrollbar anyway.
set guioptions-=L
" We don't need an always-present left-side scrollbar, either.
set guioptions-=l
" Remove additional GUI features that take up space unnecessarily.
" 'r' - right-hand scrollbar is always present.
set guioptions-=r
" 'R' - right-hand scrollbar is present for vertical splits.
set guioptions-=R
" 'm' - menu bar is present.
set guioptions-=m
SetFont
" Number of lines of text overall.
set lines=40