-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
1215 lines (982 loc) · 43.8 KB
/
vimrc
File metadata and controls
1215 lines (982 loc) · 43.8 KB
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: foldlevel=0
" _
" __ _(_)_ __ ___ _ __ ___
" \ \ / / | '_ ` _ \| '__/ __|
" \ V /| | | | | | | | | (__
" \_/ |_|_| |_| |_|_| \___|
"
" Jeremy Brubaker's .vimrc. Some stuff in here was shame-
" lessly ripped from places I completely forget about.
"
" https://github.com/jbrubake/dotfiles/blob/master/vimrc
" Folding cheet sheet (because I always forget)
" zR open all folds
" zM close all folds
" za toggle fold at cursor position
" zj move down to start of next fold
" zk move up to end of previous fold
" Initialization {{{1
" ==============
" Open .vimrc
nmap <silent> ev :next $MYVIMRC<CR>
" Source .vimrc when saving changes
augroup vimrc | autocmd!
autocmd vimrc BufWritePost $MYVIMRC nested source $MYVIMRC
augroup end
if has ('clientserver') && empty(v:servername) && exists('*remote_startserver')
call remote_startserver('VIM')
endif
" Remap Leader here because it may be used *before* the mapping section
" Better than ',' which is used for backwards character searching
let mapleader = ' '
let maplocalleader = ' '
" Plugins {{{1
"============
" Optional packages {{{2
packadd! matchit " Enhanced % matching
packadd! cfilter " Filter quickfix or location lists
" Commands to manipulate minpac {{{2
"
" *AndQuit commands are intended to be used at the command line
command! PackUpdate call plugins#PackInit() | call minpac#update()
command! PackUpdateAndQuit call plugins#PackInit() | call minpac#update("", {"do":"quitall"})
command! PackClean call plugins#PackInit() | call minpac#clean()
command! PackCleanAndQuit call plugins#PackInit() | call minpac#clean() | quitall
command! PackStatus call plugins#PackInit() | call minpac#status()
" Plugin Configuration {{{2
"
" Plugins should use this augroup
augroup plugins | autocmd! | augroup end
" Conditionally load git related plugins {{{3
"
" List of plugins to load
let s:git_plugins = []
function LoadGit()
silent! !git rev-parse --is-inside-work-tree
if ! v:shell_error " v:shell_error truth is backwards from vim truth
for s:p in s:git_plugins
execute 'packadd ' . s:p
endfor
if !empty(get(g:, 'fugitive_gitlab_domains', "")) " Set in private config
packadd fugitive-gitlab
endif
if !empty(get(g:, 'fugitive_gitea_domains', "")) " Set in private config
packadd fugitive-gitea
endif
endif
endfunction
autocmd plugins VimEnter,DirChanged * call LoadGit()
" a.vim: Swap header and source files plugurl:vim-scripts/a.vim " {{{3
" :A : Switch between header and source files
" :AS: Split and switch
" :AV: Vertical split and switch
" ~/.vim/after/plugin/unmap.vim: remove annoying insert-mode mappings
" ansible-vim: Syntax highlighting Ansible's common filetypes plugurl:pearofducks/ansible-vim " {{{3
let g:ansible_attribute_highlight = 'ab' " highlight all key=value pairs
let g:ansible_name_highlight = 'b' " highlight 'name:'
let g:ansible_extra_keywords_highlight = 1 " highlight extra keywords
" Highlight groups using specified group (:help E669)
let g:ansible_normal_keywords_highlight = 'Statement'
let g:ansible_loop_keywords_highlight = 'Statement'
let g:ansible_extra_keywords_highlight_group = 'Delimiter'
" See custom color settings below to customize 'name_highlight'
" Properly highlight HCL Jinja templates
let g:ansible_template_syntaxes = {
\ '*.hcl.j2': 'hcl',
\ '*.sh.j2': 'sh',
\ '*.tf.j2': 'hcl',
\ '*.tfvars.j2': 'hcl',
\ '*.xml.j2': 'xml',
\ '*.yml.j2': 'yaml',
\ '*.yaml.j2': 'yaml',
\ }
autocmd plugins BufRead,BufNewFile playbooks/*.yaml set filetype=yaml.ansible
autocmd plugins BufRead,BufNewFile playbooks/*.yml set filetype=yaml.ansible
" CCTree: Vim CCTree plugin plugurl:hari-rangarajan/CCTree type:opt " {{{3
" See Mappings & Commands -> Cscope for mappings
function LoadCCTree()
if filereadable($CSCOPE_DB)
let s:db = $CSCOPE_DB
elseif filereadable("cscope.out")
let s:db = 'cscope.out'
else
return 0
endif
packadd! CCTree
set cscopetag " use cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetagorder=0 " search cscope then ctags
set cscopequickfix=s-,c-,d-,i-,t-,e-,a- " Open all results in quickfix
execute 'CCTreeLoadDB ' . s:db
endfunction
if has("cscope")
autocmd plugins VimEnter,DirChanged * call LoadCCTree()
endif
" cisco.vim: Vim syntax for cisco configuration files plugurl:momota/cisco.vim " {{{3
" No configuration needed
" Colorizer: Color hex codes and color names plugurl:chrisbra/Colorizer type:opt " {{{3
" Turn off color:
" :ColorClear
" Toggle color:
" :ColorToggle
" Automatically colorize these filetypes
let g:colorizer_auto_filetype = 'css,html,markdown,xdefaults'
let g:colorizer_disable_bufleave = 0 " Only highlight above files
" Highlight X11 colornames in Xresources and such
let g:colorizer_x11_names = 1
execute 'autocmd plugins Filetype ' . g:colorizer_auto_filetype . ' packadd Colorizer | ColorToggle'
" embed-syntax: Simplifies applying different syntax highlighting to regions of a file plugurl:jbrubake/embed-syntax " {{{3
" No configuration needed
" flex-bison-syntax: Flex & Bison syntax highlighting for vim plugurl:calincru/flex-bison-syntax " {{{3
" No configuration needed
" fugitive-gitea: Plugin for :Gbrowse to work with GITea server plugurl:borissov/fugitive-gitea type:opt " {{{3
" Loaded by LoadGit()
" fugitive-gitlab.vim: A vim extension to fugitive.vim for GitLab support plugurl:shumphrey/fugitive-gitlab.vim type:opt " {{{3
" Loaded by LoadGit()
" fzf: Fuzzy finder plugurl:junegunn/fzf type:opt " {{{3
if executable('fzf') | silent packadd! fzf | endif
" fzf-checkout.vim: Manage branches and tags with fzf plugurl:stsewd/fzf-checkout.vim type:opt " {{{3
if executable('fzf') | let s:git_plugins += ['fzf-checkout.vim'] | endif
" fzf.vim: fzf vim plugin plugurl:junegunn/fzf.vim type:opt " {{{3
if executable('fzf') | silent packadd! fzf.vim | endif
" :Files [PATH] " Files ($FZF_DEFAULT_COMMAND)
" :GFiles [OPTS] " Git files (git ls-files)
" :GFiles? " Git files (git status)
" :Buffers " Vim buffers
" :Rg [PATTERN] " Search using ripgrep
" :Lines [QUERY] " Lines in all buffers
" :BLines [QUERY] " Lines in current buffer
" :Tags [QUERY] " Tags in current project (ctags -R)
" :BTags [QUERY] " Tags in current buffer
" :Marks " Marks
" :Snippets " Snippets (UltiSnips)
" :Commits " Git commits (vim-fugitive)
" indentLine: Display the indentation levels with thin vertical lines plugurl:wickles/indentLine " {{{3
let g:indentLine_char = '│'
let g:indentLine_bufTypeExclude = ['help', 'terminal', 'markdown']
"let g:indentLine_bufNameExclude = ['tagbar?']
" Hide indents on cursor line
let g:indentLine_concealcursor = ''
" Use this if JSON quotes are hidden
" let g:vim_json_syntax_conceal = 0
" jump-to-ansible-role: Load the main task file for role under the cursor plugurl:jbrubake/jump-to-ansible-role " {{{3
autocmd plugins FileType yaml.ansible nnoremap <localleader>gr <Cmd>call JumpToAnsibleRole()<CR>
autocmd plugins FileType yaml.ansible vnoremap <localleader>gr <Cmd>call JumpToAnsibleRole()<CR>
" paredit: Structured Editing of Lisp S-expressions plugurl:kovisoft/paredit " {{{3
" No configuration needed
" pseudo-syntax: Syntax highlighting for various forms of pseudocode for vim plugurl:joelbeedle/pseudo-syntax " {{{3
" readline.vim: Readline emulation for command-line mode plugurl:ryvnf/readline.vim " {{{3
" NOTE: These bindings are in the readline.vim documentation
" but not actually created
"
" Alt-Ctrl-H : Cut to start of previous word
" Ctrl-X Ctrl-H : Cut to beginning of line
cmap <Esc><C-H> <Esc><BS>
cmap <C-X><C-H> <C-U>
" Replacements for overridden maps:
"
" Alt+= / Alt+? (c_CTRL-D) : Display all names that match pattern in front of cursor
" Alt+* (c_CTRL-A) : Insert all names that match pattern in front of cursor
" Ctrl-X Ctrl-E (c_CTRL-F) : Open command-line window
" scss-syntax.vim: Sassy CSS for vim plugurl:cakebaker/scss-syntax.vim " {{{3
" No configuration needed
" SyntaxAttr.vim: Show syntax highlighting attributes of character under cursor plugurl:inkarkat/SyntaxAttr.vim " {{{3
nnoremap -a :call SyntaxAttr#SyntaxAttr()<CR>
" tabular: Smart alignment of tables plugurl:godlygeek/tabular " {{{3
" :Tabularize /<delimiter>/<format>
"
" <format> : (l)eft, (r)ight, (center)
" Each can be followed by a number indicating padding
"
" Example:
" x = 12;
" num = 13;
" var2 = 1;
"
" :Tabularize /=/l0r1
"
" x = 12;
" num = 13;
" var2= 1;
"
" Example:
" osh/Sh6: V6 sh ports (http://v6shell.org)
" sent: Console "powerpoint" (http://tools.suckless.org/sent)
" pixie: Color picker (http://nattyware.com/pixie.php)
"
" Align on *first* character only:
" :Tabularize /^[^:]*\zs:
"
" osh/Sh6 : V6 sh ports (http://v6shell.org)
" sent : Console "powerpoint" (http://tools.suckless.org/sent)
" pixie : Color picker (http://nattyware.com/pixie.php)
"
" :AddTabularPattern <name> <pattern> allows you to save patterns
"
"
" Custom mappings:
" ----------------
" <Leader>t= : = (with space)
" <Leader>t: : : (with space)
" <Leader>t:: : : (no space before)
" <Leader>t, : , (with space)
" <Leader>t| : | (with space)
"
nmap <Leader>t= <Cmd>Tabularize /=<cr>
vmap <Leader>t= <Cmd>Tabularize /=<cr>
nmap <Leader>t: <Cmd>Tabularize /:<cr>
vmap <Leader>t: <Cmd>Tabularize /:<cr>
nmap <Leader>t:: <Cmd>Tabularize /:\zs<cr>
vmap <Leader>t:: <Cmd>Tabularize /:\zs<cr>
nmap <Leader>t, <Cmd>Tabularize /,<cr>
vmap <Leader>t, <Cmd>Tabularize /,<cr>
nmap <Leader>t<Bar> <Cmd>Tabularize /<Bar><cr>
vmap <Leader>t<Bar> <Cmd>Tabularize /<Bar><cr>
" tagalong.vim: Change an HTML(ish) tag and update the matching one plugurl:AndrewRadev/tagalong.vim " {{{3
" Plugin is active for these filetypes
let g:tagalong_additional_filetypes = ['xml', 'html', 'php']
" tagbar: Source code browser using ctags plugurl:preservim/tagbar type:opt " {{{3
function LoadTagbar()
if ! filereadable('tags') && empty(glob('*.md')) == 1
return 0
endif
packadd tagbar
" ctags commands
" --------------
" CTRL-] : Jump to tag underneath cursor
" CTRL-o : Jump back in the tag stack
" :ts <tag> : Search for <tag>
" :tn : Go to next definition of last tag
" :tp : Go to previous definition of last tag
" :ts : List all definitions of last tag
"
" Default settings
" ----------------
" let g:tagbar_left = 1
" let g:tagbar_width = 40
" let g:tagbar_autoclose = 0
" <F9> : toggle TagBar
noremap <silent> <F9> <Cmd>TagbarToggle<cr>
" Add support for Makefiles (requires adding
" --regex-make=/^([^# \t:]*):/\1/t,target/
" to ~/.ctags)
let g:tagbar_type_make = {'kinds':
\ ['m:macros',
\ 't:targets']}
" Add support for Markdown
let g:tagbar_type_markdown = {
\ 'ctagstype' : 'markdown',
\ 'ctagsbin' : 'markdown2ctags',
\ 'ctagsargs' : '-f - --sort=yes --sro=»',
\ 'kinds' : ['s:sections', 'i:images'],
\ 'sro' : '»',
\ 'kind2scope' : {'s' : 'section',},
\ 'sort' : 0}
endfunction
if executable('ctags')
autocmd plugins VimEnter,DirChanged * call LoadTagbar()
endif
" todo.txt-vim: Vim plugin for Todo.txt plugurl:freitass/todo.txt-vim " {{{3
"
" <LocalLeader>s : Sort by priority
" <LocalLeader>s+ : Sort on +Projects
" <LocalLeader>s@ : Sort on @Contexts
" <LocalLeader>sd : Sort on due dates
" <LocalLeader>sc : Sort by context, then priority
" <LocalLeader>scp : Sort by context, project, then priority
" <LocalLeader>sp : Sort by project, then priority
" <LocalLeader>spc : Sort by project, context, then priority
" <LocalLeader>-sd : Sort by due date. Entries with due date are at the beginning
"
" <LocalLeader>j : Lower priority
" <LocalLeader>k : Increase priority
" <LocalLeader>a : Add priority (A)
" <LocalLeader>b : Add priority (B)
" <LocalLeader>c : Add priority (C)
"
" <LocalLeader>d : Insert current date
" date<tab> : (Insert mode) insert current date
" due: : (Insert mode) insert due: <date>
" DUE: : (Insert mode) insert DUE: <date>
"
" <LocalLeader>x : Toggle done
" <LocalLeader>C : Toggle cancelled
" <LocalLeader>X : Mark all completed
" <LocalLeader>D : Move completed tasks to done file
" No configuration needed
" ugbi: UserGettingBored Improved Vim Plugin plugurl:mikesmithgh/ugbi type:opt " {{{3
command -nargs=0 UgbiEnable packadd ugbi | :UgbiEnable
" vim-closetag: Easily close HTML/XML tags plugurl:alvan/vim-closetag " {{{3
" Current content:
" <table|
" Press >:
" <table>|</table>
" Press > again:
" <table>
" |
" </table>
" Plugin is active for these filetypes
let g:closetag_filetypes = 'sgml, xml, html, xhtml, phtml, php'
" vim-commentary: Commenting keymaps plugurl:tpope/vim-commentary " {{{3
" No configuration needed
" gc{motion} : Toggle commenting over {motion}
" gcc : Toggle commenting of [count] lines
" {Visual}gc : Toggle commenting of highlighted lines
" gcu : Uncomment current and adjacent lines
" vim-easy-align: A Vim alignment plugin plugurl:junegunn/vim-easy-align " {{{3
" No configuration needed
" vim-fugitive: Git in Vim plugurl:tpope/vim-fugitive type:opt " {{{3
let s:git_plugins += ['vim-fugitive']
" vim-fugitive-blame-ext: extend vim-fugitive to show commit message on statusline in :Gblame plugurl:tommcdo/vim-fugitive-blame-ext type:opt " {{{3
let s:git_plugins += ['vim-fugitive-blame-ext']
" vim-gist: Edit github.com gists with vim plugurl:mattn/vim-gist type:opt " {{{3
command -nargs=? Gist packadd webapi-vim | packadd vim-gist | :Gist <args>
let g:gist_post_private = 1 " Private gists by default
" :Gist -P to create public Gist
" vim-gitgutter: Use the sign column to show git chanages plugurl:airblade/vim-gitgutter type:opt " {{{3
let s:git_plugins += ['vim-gitgutter']
" The default updatetime of 4000ms is not good for async update
set updatetime=100
" Use fontawesome icons as signs
" NOTE: requires a 'nerd font'
let g:gitgutter_sign_added = ''
let g:gitgutter_sign_modified = ''
let g:gitgutter_sign_removed = ''
let g:gitgutter_sign_removed_first_line = ''
let g:gitgutter_sign_modified_removed = ''
" vim-ini-fold: folding for ini-like files plugurl:matze/vim-ini-fold " {{{3
" No configuration needed
" vim-markdown: Markdown vim mode plugurl:preservim/vim-markdown " {{{3
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_folding_style_pythonic = 1
let g:vim_markdown_folding_level = 1
let g:vim_markdown_override_foldtext = 0
let g:vim_markdown_follow_anchor = 1
let g:vim_markdown_conceal_code_blocks = 0
" vim-redact-pass.git: Do not write passwords into vim files when using pass(1) plugurl:https://dev.sanctum.geek.nz/code/vim-redact-pass.git rev:master " {{{3
" No configuration needed
" vim-repeat: Enable repeating supported plugin maps with "." plugurl:tpope/vim-repeat " {{{3
" No configuration needed
" vim-rhubarb: GitHub extension for fugitive.vim plugurl:tpope/vim-rhubarb type:opt " {{{3
let s:git_plugins += ['vim-rhubarb']
" C-X C-O: omni-complete GitHub issues or project collaborator usernames in commits
" Do not show issue preview window when omni-completing
autocmd plugins FileType gitcommit setlocal completeopt-=preview
" vim-slint: Support for the slint language plugurl:slint-ui/vim-slint " {{{3
" No configuration needed
" vim-surround: Modify surrounding characters plugurl:tpope/vim-surround " {{{3
" ds<t> : delete <t>
" cs<t><r> : change <t> to <r>
" csw<t> : surround current word with <t>
" ysiw<t> : surround current word with <t>
" yss<t> : surround current line with <t>
" ys<motion><t> : surround <motion> with <t>
" VS<t> : surround selection with <t> on separate lines
" Special characters for <t> and <r>
" ( { [ < : trim/insert spaces
" ) } ] > : DO NOT trim/insert spaces
" " ' ` : quote pairs (current line only)
" t : HTML tag
" w, W : word, WORD (<t> only)
" s : sentence (<t> only)
" p : paragraph (<t> only)
"
" Using 't' for <r>
" Vim will prompt for the tag to insert. Any attributes given
" will be stripped from the closing tag.
" No configuration needed
" vim-sxhkdrc: Vim syntax for sxhkd's configuration files plugurl:baskerville/vim-sxhkdrc " {{{3
" No configuration needed
" vim-terraform: basic vim/terraform integration plugurl:hashivim/vim-terraform " {{{3
" No configuration needed
" vim-textobj-sentence: Improving native sentence text object and motion plugurl:preservim/vim-textobj-sentence " {{{3
" No configuration needed
" vim-textobj-user: Create your own text objects (required by vim-textobj-sentence) plugurl:kana/vim-textobj-user " {{{3
" No configuration needed
" vim-tmux: Vim plugin for .tmux.conf plugurl:tmux-plugins/vim-tmux " {{{3
" No configuration needed
" vim-tmux-pilot: Unified navigation of splits and tabs in nvim and tmux plugurl:urbainvaes/vim-tmux-pilot type:opt " {{{3
" Use Alt+[hjkl] to navigate windows
if has ('unix') " 'set convert-meta off' in .inputrc makes Alt not the Meta key
let g:pilot_key_h='h'
let g:pilot_key_j='j'
let g:pilot_key_k='k'
let g:pilot_key_l='l'
let g:pilot_key_p='\'
else
let g:pilot_key_h='<a-h>'
let g:pilot_key_j='<a-j>'
let g:pilot_key_k='<a-k>'
let g:pilot_key_l='<a-l>'
let g:pilot_key_p='<a-\>'
endif
if $TMUX != "" | packadd! vim-tmux-pilot | endif
" vim-tridactyl: Syntax plugin for Tridactyl configuration files plugurl:tridactyl/vim-tridactyl " {{{3
" No configuration needed
" vimtex: vim LaTeX plugin plugurl:lervag/vimtex type:opt " {{{3
let g:vimtex_view_method = 'zathura'
let g:tex_flavor = 'latex' " See <vim-tex>/ftdetect/tex.vim
let g:vimtex_compiler_latexmk = {
\ 'options' : [
\ '-shell-escape',
\ '-verbose',
\ '-file-line-error',
\ '-synctex=1',
\ '-interaction=nonstopmode',
\ ],
\}
autocmd plugins FileType tex,bib packadd vimtex | call vimtex#init()
" vlime: A Common Lisp dev environment for Vim plugurl:vlime/vlime " {{{3
let g:vlime_cl_impl = "sbcl"
function! VlimeBuildServerCommandFor_clisp(vlime_loader, vlime_eval)
return ["clisp", "--load", expand($XDG_DATA_HOME) . "/quicklisp/setup.lisp",
\ "--load", a:vlime_loader,
\ "--eval", a:vlime_eval]
endfunction
" webapi-vim: Needed for vim-gist plugurl:mattn/webapi-vim type:opt " {{{3
" No configuration needed
" YankRing.vim: Maintains a history of previous yanks, changes and deletes plugurl:vim-scripts/YankRing.vim " {{{3
let g:yankring_history_dir =
\ ($XDG_CACHE_HOME != '') ? $XDG_CACHE_HOME : '~/.cache'
" Basics {{{1
" ======
filetype plugin indent on " Load filetype plugins and indent settings
set omnifunc=syntaxcomplete#Complete " Complete on syntax (CTL-X CTL-O to complete)
set encoding=utf8 " Use Unicode
set noexrc " Do not source .exrc
set autowrite " Write file when changing to a new file
set wildmenu " Show wildmenu
set wildmode=longest:full,full " Tab complete longest part, then show wildmenu
set backspace=indent,eol,start " What BS can delete
set backupdir=~/.vim/backup " Where to put backup files
set directory=~/.vim/tmp " Where to put swap files
set mouse=a " Use mouse everywhere
set mousehide " Hide mouse while typing
set incsearch " Incremental search
set nolist " Do not show listchars
set listchars=
set listchars+=extends:>,precedes:< " Show long line continuation chars
set listchars+=tab:»\ " Show real tabs
set listchars+=trail:. " Show trailing spaces and higlight them
set listchars+=eol:¬ " Show end of line
set listchars+=nbsp:+ " Show non-breaking space
set visualbell " Blink instead of beep
set relativenumber " Show relative line number
set number " Show line number of current line
set numberwidth=4 " Allows line numbers up to 999
set report=0 " Always report when a : command changes something
set shortmess=aOstT " Keep messages short
set scrolloff=99 " Basically keep cursor centered on the screen vertically
set sidescrolloff=10 " Keep 10 lines at right/left
set sidescroll=1 " Horizontal scroll one column at a time
set showtabline=0 " Never show tabline
set hidden " Allow hidden buffers
set tags-=./tags " Remove ./tags and ./tags; from 'tags'
set tags-=./tags; " and prepend ./tags; in order to search
set tags^=./tags; " up the tree for the tags file
set complete-=i " *Do not* search included files when completing
set history=1000 " Save more command history
set fillchars=vert:\|,fold:―
set updatecount=10 " Write swapfile every 10 keystrokes
set undofile " Persistent undo tree
set undodir=~/.vim/undo " Put undo files here
call mkdir(&undodir, "p", 0o700)
set path^=$DOTFILES " Search for files in $DOTFILES
" Use cursorline only in active window
" TODO: cursorline is off when vim is first opened
augroup cursorline | autocmd!
autocmd WinEnter,FocusGained * setlocal cursorline
autocmd WinLeave,FocusLost * setlocal nocursorline
augroup end
" ttymouse is not properly set if TERM=tmux*
" and then I can't use the mouse to resize splits
if &term =~ "tmux" | set ttymouse=sgr | endif
" Set buffer to use detected tabbing style
"
" Ignore buffers that don't work with autotab
if executable('autotab')
let autotab_blacklist = ['fugitive']
augroup autotab | autocmd!
autocmd BufReadPost *
\ if bufname('%:p') != "" && index(autotab_blacklist, &ft) < 0 |
\ execute system("autotab -l <" . bufname('%:p')) |
\ endif
augroup end
endif
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
" (happens when dropping a file on gvim), for a commit or rebase message
" (likely a different one than last time), and when using xxd(1) to filter
" and edit binary files (it transforms input files back and forth, causing
" them to have dual nature, so to speak)
"
" From $VIMRUNTIME/defaults.vim (Vim 9.1.825, Fedora 39)
augroup last_position | autocmd!
autocmd BufReadPost *
\ let line = line("'\"")
\ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
\ && index(['xxd', 'gitrebase'], &filetype) == -1
\ | execute "normal! g`\""
\ | endif
augroup end
" Absolute & Hybrid line numbers by buffer status {{{2
"
" https://jeffkreeftmeijer.com/vim-number/
augroup numbertoggle | autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &number && mode() != 'i' | set relativenumber | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &number | set norelativenumber | endif
augroup end
" Automatically open quickfix window {{{2
augroup quickfix | autocmd!
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup end
" Searching {{{2
if executable('rg') | set grepprg=rg\ --vimgrep | endif
" grep/lgrep without polluting the terminal or opening the first match
"
" Respects &grepprg
"
" https://gist.github.com/romainl/56f0c28ef953ffc157f36cc495947ab3
function! Grep(...)
return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
endfunction
command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep'
cnoreabbrev <expr> lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep'
" Text Formatting/Layout {{{1
"===========================
set formatoptions+=rqlnj " j: delete comment leader when joining lines
" l: do not break long lines in insert mode
" n: support numbered lists (:help formatlistpat)
" q: reformat comments with 'gq'
" r: insert comment leader on <Enter>
set ignorecase " Case insensitive by default
set smartcase " but case sensitive if search string is multi-case
set nowrap " Long lines do not wrap
set shiftround " Indent at multiples of shiftwidth
set expandtab " Expand tabs to spaces
set tabstop=4 " Real tabs are 4 spaces
set softtabstop=4 " A tab is 4 spaces for a tab or backspace
set shiftwidth=4 " Indent and <</>> is 4 spaces
set textwidth=80 " Lines wrap at column 80
set autoindent " Automatically indent based on previous line
set smartindent " Automatic indenting is intelligent
" Statusline {{{1
" ==========
function! Statusline() abort
let s = ' '
let s .= '%-2c' " Column
let s .= ' '
let s .= '%f' " Relative path to file in buffer
let s .= '%m' " Modified flag
let s .= '%r' " Readonly flag
let s .= ' '
let s .= '[%Y]' " Filetype
let s .= '%=' " Divide left and right halves
let s .= '%l:%L' " Line:Lines
let s .= ' '
let s .= '[UNICODE 0x%B]' " Unicode codepoint
return s
endfunction
set laststatus=2 " Always show status line
set statusline=%!Statusline()
" Terminal window status line
augroup termwindow | autocmd!
autocmd TerminalWinOpen * setlocal statusline=%t
augroup end
" Folding {{{1
"============
set foldenable " Turn on folding
set foldmethod=marker " Fold on the marker
set foldopen=block,hor,mark,percent,quickfix,tag " What movements open folds
" Right justify folded line count
"
" dhruvasagar (dhruvasagar.com/2013/03/28/vim-better-foldtext)
function! NeatFoldText()
let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
let lines_count = v:foldend - v:foldstart + 1
let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
let foldchar = matchstr(&fillchars, 'fold:\zs.')
let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
let foldtextend = lines_count_text . repeat(foldchar, 8)
let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
endfunction
set foldtext=NeatFoldText()
" Mappings & Commands {{{1
"========================
" Help {{{2
" map: normal, visual, select, operator-pending
" nmap: normal
" vmap: visual and select
" omap: operator-pending
" xmap: visual
" smap: select
" map!: insert and command-line
" imap: insert
" cmap: command line
" lmap: insert, command line, language-arg
"
" *nore*: non-recursive mapping
"
" <silent> : don't echo mapping on command line
" <expr> : mapping inserts result of {rhs}
" <buffer> : buffer local mapping
" Window Management: {{{2
" ==================
" See vim-tmux-pilot configuration
" Resize windows with C-[ARROWS] {{{3
"
" C-[Up|Down]: Grow|Shrink vertically
" C-[Left|Right]: Grow|Shrink horizontaally
nnoremap <C-Down> <C-w>-
nnoremap <C-Up> <C-w>+
nnoremap <C-Left> <C-w><
nnoremap <C-Right> <C-w>>
" Maximize/Minimize window with CTRL-W m {{{3
"
" pmalek (github.com/pmalek/toggle-maximize.vim)
let t:maximizeCurrentWindow = 0
function! ToggleMaximizeCurrentWindow()
if t:maximizeCurrentWindow == 0
:vertical resize
:resize
let t:maximizeCurrentWindow = 1
else
:exe "normal \<C-W>="
let t:maximizeCurrentWindow = 0
endif
endfunction
nnoremap <silent> <C-W>m <Cmd>call ToggleMaximizeCurrentWindow() <cr>
" Buffer Management {{{2
"
nnoremap <silent> <Up> :bprevious<CR>
nnoremap <silent> <Down> :bnext<CR>
" Terminal Mode {{{2
"
" <leader><Esc>: Enter normal mode
tnoremap <leader><Esc> <C-\><C-n>
" Searching & Search/Replace {{{2
"
" Metacharacters do not need escaped (very magic, :help \v)
nnoremap / /\v
vnoremap / /\v
" Search for character under cursor
nnoremap <leader>* xhp/<C-R>-<Return>
" Start a global search & replace
nnoremap S :%s//g<Left><Left>
" Populate a global search & replace with previous search
nnoremap <expr> M ':%s/' . @/ . '//g<Left><Left>'
" <leader>c: toggle colorcolumn {{{2
"
" Kevin Kuchta (www.vimbits.com/bits/317)
function! g:ToggleColorColumn()
if &colorcolumn == ''
setlocal colorcolumn=80
else
setlocal colorcolumn&
endif
endfunction
nnoremap <silent> <leader>c <Cmd>call g:ToggleColorColumn()<cr>
" <leader>l: toggle listchars {{{2
nnoremap <silent> <leader>l <Cmd>set list!<cr>
" <leader>s: split line {{{2
"
" https://gist.github.com/romainl/3b8cdc6c3748a363da07b1a625cfc666
function! BreakHere()
s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6
call histdel("/", -1)
endfunction
nnoremap <leader>s <Cmd>call BreakHere()<CR>
" <localleader><F7> toggle spellcheck {{{2
nnoremap <localleader><F7> <Cmd>setlocal spell!<CR>
" <C-L>: clear search highlighting {{{2
"
" This allows n and N to resume the previous search while 'let @/ = ""' does not
noremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" fN: set foldlevel=N {{{2
noremap <leader>f0 <Cmd>set foldlevel=0<cr>
noremap <leader>f1 <Cmd>set foldlevel=1<cr>
noremap <leader>f2 <Cmd>set foldlevel=2<cr>
noremap <leader>f3 <Cmd>set foldlevel=3<cr>
noremap <leader>f4 <Cmd>set foldlevel=4<cr>
noremap <leader>f5 <Cmd>set foldlevel=5<cr>
noremap <leader>f6 <Cmd>set foldlevel=6<cr>
noremap <leader>f7 <Cmd>set foldlevel=7<cr>
noremap <leader>f8 <Cmd>set foldlevel=8<cr>
noremap <leader>f9 <Cmd>set foldlevel=9<cr>
" [<Space> / ]<Space>: add [n] blank lines before/after line {{{2
"
" https://superuser.com/a/607168
nnoremap <silent> [<Space> <Cmd>put!=repeat(nr2char(10),v:count)<Bar>execute "']+1"<CR>
nnoremap <silent> ]<Space> <Cmd>put =repeat(nr2char(10),v:count)<Bar>execute "'[-1"<CR>
" [e / ]e: exchange current line with previous/next {{{2
nnoremap [e kddp
nnoremap ]e jddkP
" <Tab>: Map Tab to % {{{2
nmap <tab> %
vmap <tab> %
" Y: yank to end (consistent with C and D) {{{2
nnoremap Y y$
" <localleader>Y: copy to system clipboard {{{2
vnoremap <localleader>Y "+Y
" :w!!: write file when I forget to sudo {{{2
cnoremap w!! w !sudo tee % >/dev/null
" <leader>u[c]: underline current line with [c] {{{2
nnoremap <leader>u yypVr
" zl / zh: horizontal left/right scrolling {{{2
nnoremap zl zL
nnoremap zh zH
" DiffOrig: diff of buffer and file {{{2
" Redo the stock DiffOrig to suppress the '1 line less' message
command! DiffOrig vert new | set bt=nofile | r ++edit #
\ | silent! 0d_ | diffthis | wincmd p | diffthis
" <F2>: toggle relative/absoute line numbers {{{2
nnoremap <F2> <Cmd>set norelativenumber!<CR>
" C-u: convert current word to uppercase {{{2
inoremap <C-u> <esc>gUiwea
" vim-fugitive & vim-gitgutter: {{{2
"
nnoremap <leader>gg <Cmd>Git<CR>
nnoremap <leader>gB <Cmd>GBrowse<CR>
vnoremap <leader>gB <Cmd>GBrowse<CR>
" Open git diff split
nnoremap <leader>gd <Cmd>Gdiffsplit<CR>
" Mappings to jump between hunks (fugitive & gitgutter)
" [c, ]c: previous, next hunk (default binding)
" fzf.vim, fzf-checkout.vim: {{{2
"
noremap <leader>b <Cmd>Buffers<CR>
nnoremap <leader>gc <Cmd>Commits<CR>
nnoremap <leader>gb <Cmd>GBranches<CR>
nnoremap <leader>f <Cmd>Files<CR>
" Cscope: {{{2
" Based on https://raw.githubusercontent.com/chazy/cscope_maps/master/plugin/cscope_maps.vim
if has("cscope")
" CCTree mappings:
" ----------------
" CTRL-\ > : Get forward call tree
" CTRL-\ < : Get reverse call tree
" CTRL-\ w : Toogle call tree window
" CTRL-\ = : Increase depth
" CTRL-\ - : Decrease depth
" CTRL-p : Preview symbol
" Note: Folding commands work on call tree window
" Cscope mappings:
" ----------------
" CTRL-\ : Open result in current window
" CTRL-] : Open result in horizontal split
" CTRL-] CTRL+] : Open result in vertical split
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
"
" All of the maps involving the <cfile> macro use '^<cfile>$': this is so
" that searches over '#include <time.h>" return only references to
" 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
" files that contain 'time.h' as part of their name).
nmap <C-\>s <Cmd>cscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g <Cmd>cscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c <Cmd>cscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t <Cmd>cscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e <Cmd>cscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f <Cmd>cscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i <Cmd>cscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d <Cmd>cscope find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>s <Cmd>scscope find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>g <Cmd>scscope find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>c <Cmd>scscope find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>t <Cmd>scscope find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>e <Cmd>scscope find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-]>f <Cmd>scscope find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-]>i <Cmd>scscope find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-]>d <Cmd>scscope find d <C-R>=expand("<cword>")<CR><CR>