/
vimrc
1062 lines (956 loc) · 42 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
" .vimrc
" Author: John O'Shea <john.m.oshea@gmail.com>
" Source: <https://github.com/johnoshea/dotfiles>
" Leader keys ------------------------------------------------------------- {{{
let g:mapleader="\<Space>"
let g:maplocalleader=','
" }}}
" Plugins ----------------------------------------------------------------- {{{
call plug#begin('~/.vim/bundle')
" Mac-specific things ---------------------------------------------------- {{{
if has('macunix')
" Version-dependent plugins ------------------------------------------- {{{
if v:version >= 704
" Plugin: ultisnips ----------------------------------------------- {{{
Plug 'https://github.com/SirVer/ultisnips'
let g:UltiSnipsSnippetDirectories= ['UltiSnips', 'my_snippets']
let g:UltiSnipsSnippetsDir= '~/.vim/my_snippets/'
let g:UltiSnipsListSnippets = '<c-g>l'
let g:ultisnips_python_quoting_style = 'sphinx'
let g:UltiSnipsExpandTrigger='<c-g><c-g>'
let g:UltiSnipsJumpForwardTrigger='<c-g>n'
let g:UltiSnipsJumpBackwardTrigger='<c-g>p'
" }}}
" Ultisnips snippets are now stored in honza/vim-snippets
Plug 'https://github.com/honza/vim-snippets'
endif
" }}}
" Navigation
" Plugin: FZF --------------------------------------------------------- {{{
Plug '/usr/local/opt/fzf' | Plug 'https://github.com/junegunn/fzf.vim'
let $FZF_DEFAULT_COMMAND = 'fd --type f --hidden --follow --exclude .git --ignore-file ~/.gitignore'
nnoremap <silent> <Leader><Leader> :Files<CR>
nnoremap <silent> <Leader><CR> :Buffers<CR>
nnoremap <silent> <Leader>` :Marks<CR>
nnoremap <silent> <Leader>hi :History<CR>
nnoremap <silent> <Leader>mp :Maps<CR>
nnoremap <silent> <Leader>sn :Snippets<CR>
nnoremap <silent> <Leader>cm :Commands<CR>
nnoremap <silent> <Leader>r :Rg<CR>
nnoremap <silent> <Leader>gg :GGrep<CR>
nnoremap <silent> <Leader>gf :GFiles<CR>
nnoremap <silent> <Leader>C :Commits<CR>
nnoremap <silent> <Leader>tg :Tags<CR>
" Insert mode completion
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
inoremap <expr> <c-x><c-k> fzf#vim#complete#word({'left': '15%'})
" cd to Notes dir (useful for Notational Velocity/Nebulous Notes)
nnoremap <leader>n :lcd ~/Documents/3\ Current/Notes<cr>:Files<cr>
" Command for git grep
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
command! -bang -nargs=* GGrep
\ call fzf#vim#grep(
\ 'git grep --line-number '.shellescape(<q-args>), 0,
\ { 'dir': systemlist('git rev-parse --show-toplevel')[0] }, <bang>0)
" Augmenting Rg command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], [preview window], [toggle keys...]])
" * For syntax-highlighting, Ruby and any of the following tools are required:
" - Bat: https://github.com/sharkdp/bat
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
" - CodeRay: http://coderay.rubychan.de/
" - Rouge: https://github.com/jneen/rouge
"
" :Rg - Start fzf with hidden preview window that can be enabled with "?" key
" :Rg! - Start fzf in fullscreen and display the preview window above
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" Git files command with preview window
command! -bang -nargs=? -complete=dir GFiles
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" }}}
" Plugin: slimux ------------------------------------------------------ {{{
Plug 'https://github.com/grusky/slimux'
nnoremap <Leader>sc :SlimuxREPLConfigure<CR>
nnoremap <Leader>se :SlimuxREPLSendLine<CR>
vnoremap <Leader>se :SlimuxREPLSendSelection<CR>
nnoremap <Leader>sp :SlimuxShellPrompt<CR>
nnoremap <Leader>sa :SlimuxShellLast<CR>
nnoremap <Leader>sk :SlimuxSendKeysPrompt<CR>
nnoremap <Leader>sl :SlimuxSendKeysLast<CR>
" }}}
" - allow window nav to work across non-vim tmux panes (needs tmux config too)
Plug 'https://github.com/christoomey/vim-tmux-navigator'
" " vim-tmux-focus-events
Plug 'https://github.com/tmux-plugins/vim-tmux-focus-events'
nnoremap <leader>z :call system("tmux resize-pane -Z")<CR>
" Plugin: YouCompleteMe ----------------------------------------------- {{{
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status ==# 'installed' || a:info.force
!./install.py
endif
endfunction
Plug 'https://github.com/Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_add_preview_to_completeopt = 'popup'
let g:ycm_confirm_extra_conf = 0
nnoremap <silent> <buffer> <leader>d :YcmCompleter GoToDefinitionElseDeclaration<CR>
nnoremap <silent> <buffer> <leader>yg :YcmCompleter GoTo<CR>
nnoremap <silent> <buffer> <leader>yr :YcmCompleter GoToReferences<CR>
nnoremap <silent> <buffer> <leader>yd :YcmCompleter GetDoc<CR>
" }}}
" Create nicely-formatted code images from the selection
Plug 'https://github.com/segeljakt/vim-silicon'
endif
" }}}
" Navigation/filesystem --------------------------------------------------- {{{
" Plugin: vim-sneak ------------------------------------------------------- {{{
Plug 'https://github.com/justinmk/vim-sneak'
nmap f <Plug>SneakForward
xmap f <Plug>VSneakForward
nmap F <Plug>SneakBackward
xmap F <Plug>VSneakBackward
let g:sneak#streak = 1
" }}}
" Plugin: vim-obsession --------------------------------------------------- {{{
Plug 'https://github.com/tpope/vim-obsession'
nnoremap <leader>o :Obsession<cr>
nnoremap <leader>O :Obsession!<cr>
" }}}
" vim-eunuch
" :Remove, :Move, :Rename, :Chmod, :Mkdir, :Wall, :SudoWrite, :SudoEdit
Plug 'https://github.com/tpope/vim-eunuch'
" Matching
Plug 'https://github.com/andymass/vim-matchup/'
" DidYouMean - avoid opening up new empty files if multiple completions
Plug 'https://github.com/EinfachToll/DidYouMean'
" Create directories and files at the same time
Plug 'https://github.com/vim-scripts/easydir.vim'
Plug 'https://github.com/justinmk/vim-dirvish'
" Plugin: remote-viewer --------------------------------------------------- {{{
" Allows 'Dirvish ssh://user@hostname/path'
Plug 'https://github.com/bounceme/remote-viewer'
nnoremap <leader>ss :Dirvish ssh://
" }}}
" Shows git status in Dirvish windows
Plug 'https://github.com/kristijanhusak/vim-dirvish-git'
" }}}
" Editing ----------------------------------------------------------------- {{{
" Plugin: undotree -------------------------------------------------------- {{{
Plug 'https://github.com/simnalamburt/vim-mundo', {'on': 'MundoToggle'}
nnoremap <leader>u :MundoToggle<CR>
" }}}
" Plugin: vim-easy-align -------------------------------------------------- {{{
" <number> or '*' for count, followed by character to align on
Plug 'https://github.com/junegunn/vim-easy-align'
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" }}}
" Editorconfig ------------------------------------------------------------ {{{
Plug 'https://github.com/editorconfig/editorconfig-vim'
let g:EditorConfig_exclude_patterns = ['fugitive://.*']
" }}}
Plug 'https://github.com/tpope/vim-repeat'
Plug 'https://github.com/tpope/vim-unimpaired'
Plug 'https://github.com/tpope/vim-abolish'
" Plugin: vim-sandwich ---------------------------------------------------- {{{
Plug 'https://github.com/machakann/vim-sandwich'
runtime macros/sandwich/keymap/surround.vim
" }}}
" Auto-update folds only as needed
Plug 'https://github.com/Konfekt/FastFold'
" Handles bracketed-paste-mode in vim (aka. automatic `:set paste`)
Plug 'https://github.com/ConradIrwin/vim-bracketed-paste'
" }}}
" Code editing ------------------------------------------------------------ {{{
" Plugin: ale ------------------------------------------------------------- {{{
Plug 'https://github.com/dense-analysis/ale'
" Specific to file types and are here for reference
let g:ale_linters = {
\ 'css' : ['csslint'],
\ 'dockerfile' : ['hadolint'],
\ 'go' : ['gopls'],
\ 'html' : ['htmlhint', 'tidy'],
\ 'javascript' : ['eslint'],
\ 'json' : ['jsonlint'],
\ 'markdown' : ['mdl'],
\ 'python' : ['pylint', 'flake8', 'mypy'],
\ 'scss' : ['sasslint'],
\ 'sh' : ['shellcheck', 'shell'],
\ 'tf' : ['tflint'],
\ 'vim' : ['vint'],
\ 'yaml' : ['yamllint'],
\ }
let g:ale_lint_on_text_changed = 'never'
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
let g:ale_echo_msg_format = '%linter%> %code: %%s'
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'python': ['black', 'isort'],
\ 'javascript': ['prettier','eslint']
\}
let g:ale_fix_on_save = 1
let g:ale_python_flake8_options = '--max-line-length=88' " match 'black' formatter
let g:ale_python_mypy_options = '--follow-imports=silent'
" }}}
" Plugin: vim-prettier ---------------------------------------------------- {{{
" post install (yarn install | npm install) then load plugin only for editing supported files
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'yaml', 'html'] }
" use <leader>f to autoformat code
nnoremap <leader>f :PrettierAsync<cr>
" }}}
" Plugin: vim-test -------------------------------------------------------- {{{
Plug 'https://github.com/janko-m/vim-test'
nmap <silent> <leader>tn <esc>:w<CR>:TestNearest<CR>
nmap <silent> <leader>tf <esc>:w<CR>:TestFile<CR>
nmap <silent> <leader>ts <esc>:w<CR>:TestSuite<CR>
nmap <silent> <leader>tl <esc>:w<CR>:TestLast<CR>
let g:test#strategy = 'dispatch'
" }}}
" Plugin: tcomment -------------------------------------------------------- {{{
Plug 'https://github.com/tomtom/tcomment_vim'
" Prevent tcomment from making a zillion mappings (we just want the operator).
let g:tcomment_mapleader2=''
let g:tcomment_mapleader_comment_anyway=''
let g:tcomment_textobject_inlinecomment=''
" }}}
" Plugin: Pear-tree ------------------------------------------------------- {{{
Plug 'https://github.com/tmsvg/pear-tree'
" If enabled, smart pair functions timeout after 60ms:
let g:pear_tree_timeout = 60
" }}}
" }}}
" Git --------------------------------------------------------------------- {{{
" Plugin: Fugitive -------------------------------------------------------- {{{
Plug 'https://github.com/tpope/vim-fugitive'
augroup fugitive
autocmd!
" Auto-clean fugitive buffers.
autocmd BufReadPost fugitive://* set bufhidden=delete
nnoremap <leader>gs :Git<CR>
nnoremap <leader>ga :Gwrite<CR>
nnoremap <leader>gc :Gcommit %<CR>
nnoremap <leader>gd :Gvdiffsplit<CR>
nnoremap <leader>gl :Gclog<CR>
nnoremap <leader>gb :Git-blame<CR>
nnoremap <leader>gf :Git-fetch<CR>
nnoremap <leader>gps :Git push<CR>
nnoremap <leader>gpl :Git pull<CR>
augroup END
" }}}
" Enable GitHub features in fugitive
Plug 'https://github.com/tpope/vim-rhubarb'
Plug 'https://github.com/mhinz/vim-signify'
let g:signify_vcs_list = [ 'git' ]
" Plugin: vim-twiggy ------------------------------------------------------ {{{
Plug 'https://github.com/sodapopcan/vim-twiggy'
nnoremap <leader>tw :Twiggy<cr>
nnoremap <leader>TW :Twiggy<space>
" }}}
" Plugin: committia.vim --------------------------------------------------- {{{
Plug 'https://github.com/rhysd/committia.vim'
let g:committia_open_only_vim_starting = 1
" }}}
" }}}
" Display ----------------------------------------------------------------- {{{
" Plugin: vim-crystalline ------------------------------------------------- {{{
Plug 'https://github.com/rbong/vim-crystalline'
function! StatusLine(current, width) abort
let l:s = ''
if a:current
let l:s .= crystalline#mode() . crystalline#right_mode_sep('')
else
let l:s .= '%#CrystallineInactive#'
endif
let l:s .= ' %f%h%w%m%r '
let l:s .= ObsessionStatus() . ' '
if a:current
let l:s .= crystalline#right_sep('', 'Fill') . ' ⎇ %{fugitive#head()}'
endif
let l:s .= '%='
if a:current
let l:s .= crystalline#left_sep('', 'Fill') . ' %{&paste ?"PASTE ":""}%{&spell?"SPELL ":""}%{&ft} '
let l:s .= crystalline#left_mode_sep('')
if a:width > 80
let l:s .= ' 0x%B %c:%l/%L [%{&enc} %{&ff}] '
else
let l:s .= ' '
endif
endif
return l:s
endfunction
let g:crystalline_enable_sep = 1
let g:crystalline_statusline_fn = 'StatusLine'
let g:crystalline_theme = 'default'
" }}}
" Plugin: vim-diminactive ------------------------------------------------- {{{
Plug 'https://github.com/blueyed/vim-diminactive'
let g:diminactive_use_syntax = 1
let g:diminactive_enable_focus = 1
" }}}
" Plugin: listtoggle ------------------------------------------------------ {{{
Plug 'https://github.com/valloric/listtoggle'
let g:lt_location_list_toggle_map = '<leader>l'
let g:lt_quickfix_list_toggle_map = '<leader>q'
" }}}
" Better display of whitespace - adds :StripWhitespace too
Plug 'https://github.com/ntpeters/vim-better-whitespace'
" Plugin: vim-numbertoggle ------------------------------------------------ {{{
Plug 'https://github.com/jeffkreeftmeijer/vim-numbertoggle'
set number relativenumber
nnoremap <silent> <leader>1 :set relativenumber!<cr>
nnoremap <silent> <leader>2 :set nonumber!<cr>:set norelativenumber!<cr>
" }}}
" Plugin: indentLine ------------------------------------------------------ {{{
Plug 'https://github.com/Yggdroot/indentLine'
let g:indentLine_char_list = ['|', '¦', '┆', '┊']
let g:indentLine_fileTypeExclude = ['help']
" }}}
" Easier/better handling of in-file splits
Plug 'https://github.com/wellle/visual-split.vim'
" }}}
" Filetypes/file formats -------------------------------------------------- {{{
" Plugin: pgsql ----------------------------------------------------------- {{{
Plug 'https://github.com/lifepillar/pgsql.vim', {'for': 'sql'}
let g:sql_type_default = 'pgsql'
" }}}
" Python ------------------------------------------------------------------ {{{
Plug 'https://github.com/kalekundert/vim-coiled-snake', {'for': 'python'}
Plug 'https://github.com/Vimjas/vim-python-pep8-indent', {'for': 'python'}
" }}}
" Django ------------------------------------------------------------------ {{{
Plug 'https://github.com/vim-scripts/django.vim', {'for': 'django'}
Plug 'https://github.com/tweekmonster/django-plus.vim', {'for': 'django'}
" }}}
" Javascript -------------------------------------------------------------- {{{
Plug 'https://github.com/pangloss/vim-javascript', {'for': 'javascript'}
Plug 'https://github.com/othree/javascript-libraries-syntax.vim', {'for': 'javascript'}
" }}}
" Markdown ---------------------------------------------------------------- {{{
Plug 'https://github.com/godlygeek/tabular'
Plug 'https://github.com/plasticboy/vim-markdown'
let g:vim_markdown_conceal = 0
let g:vim_markdown_conceal_code_blocks = 0
" let g:vim_markdown_fenced_languages = ['csharp=cs']
" Plugin: vim-table-mode -------------------------------------------------- {{{
Plug 'https://github.com/dhruvasagar/vim-table-mode'
let g:table_mode_corner='|'
" }}}
" }}}
" Add CSS3 syntax highlighting
Plug 'https://github.com/hail2u/vim-css3-syntax', {'for': ['css', 'scss']}
" CSS OmniComplete
Plug 'https://github.com/othree/csscomplete.vim', {'for': ['css', 'scss']}
" Better JSON
Plug 'https://github.com/tpope/vim-jdaddy', {'for': ['javascript', 'json']}
" CSV support
Plug 'https://github.com/chrisbra/csv.vim', {'for': ['csv', 'tsv', 'psv']}
" HTML
Plug 'https://github.com/mattn/emmet-vim', {'for': 'html'}
" Terraform --------------------------------------------------------------- {{{
Plug 'https://github.com/juliosueiras/vim-terraform-completion', {'for': 'terraform'}
Plug 'https://github.com/hashivim/vim-terraform', {'for': 'terraform'}
let g:terraform_align = 1
let g:terraform_fmt_on_save = 1
" }}}
" Tmux.conf syntax
Plug 'https://github.com/tmux-plugins/vim-tmux', {'for': 'tmux'}
" Nginx
Plug 'https://github.com/chr4/nginx.vim', {'for': 'nginx'}
" TOML
Plug 'https://github.com/cespare/vim-toml', {'for': 'toml'}
" Jinja2
Plug 'https://github.com/Glench/Vim-Jinja2-Syntax', {'for': 'jinja2'}
" Plugin: vimwiki --------------------------------------------------------- {{{
Plug 'https://github.com/vimwiki/vimwiki'
let WIKI_BASE_DIR = '~/vimwiki'
let wiki_1 = {}
let wiki_1.path = WIKI_BASE_DIR . '/vimwiki/'
let wiki_1.path_html = WIKI_BASE_DIR . '/vimwiki_html/'
let wiki_1.nested_syntaxes = {'python': 'python', 'sh': 'sh'}
let wiki_1.ext = '.md'
let wiki_1.folding = 'syntax'
let wiki_1.syntax = 'markdown'
let wiki_1.ext2syntax = {'.md': 'markdown', '.markdown': 'markdown'}
let g:vimwiki_list = [wiki_1]
let g:vimwiki_markdown_ext_link = 1 " add .md to links, for other markdown processors
let g:vimwiki_global_ext = 0 " turn off temporary wikis
" }}}
" }}}
" Colorschemes ------------------------------------------------------------ {{{
" Gruvbox
Plug 'https://github.com/gruvbox-community/gruvbox'
let g:gruvbox_italic=1
let g:gruvbox_invert_signs=1
let g:gruvbox_invert_indent_guides=1
let g:gruvbox_contrast_dark='hard'
" Paperwhite, for light terminal sessions
Plug 'https://github.com/NLKNguyen/papercolor-theme'
" Srcery
Plug 'https://github.com/srcery-colors/srcery-vim'
let g:srcery_italic = 1
let g:srcery_inverse_matches = 0
let g:srcery_inverse_match_paren = 0
" }}}
" Text objects ------------------------------------------------------------ {{{
" Use 'ia'/'aa' for arguments,
" or i/a followed by any of , . ; : + - = ~ _ * # / | \ & $
Plug 'https://github.com/wellle/targets.vim'
" Add af/if for functions, ac/ic for classes, ]m, ]M, [m, [M for moving
Plug 'https://github.com/jeetsukumaran/vim-pythonsense'
" Add [-, [+, [=, ]-, ]+, ]= "move by indent" maps
Plug 'https://github.com/jeetsukumaran/vim-indentwise'
" Add al/il for lines
Plug 'https://github.com/kana/vim-textobj-line'
" Needed for vim-textobj-underscore
Plug 'https://github.com/kana/vim-textobj-user'
" Add a_/i_ for underscores
Plug 'https://github.com/lucapette/vim-textobj-underscore'
" - provides 'i' indent object (e.g. 'vai')
Plug 'https://github.com/michaeljsmith/vim-indent-object'
" }}}
" Search ------------------------------------------------------------------ {{{
Plug 'https://github.com/markonm/traces.vim'
" Plugin: vim-asterisk ---------------------------------------------------- {{{
Plug 'https://github.com/haya14busa/vim-asterisk'
Plug 'https://github.com/qxxxb/vim-searchhi'
map * <Plug>(asterisk-z*)<Plug>(is-nohl-1)<Plug>(searchhi-update)
map g* <Plug>(asterisk-gz*)<Plug>(is-nohl-1)<Plug>(searchhi-update)
map # <Plug>(asterisk-z#)<Plug>(is-nohl-1)<Plug>(searchhi-update)
map g# <Plug>(asterisk-gz#)<Plug>(is-nohl-1)<Plug>(searchhi-update)
let g:asterisk#keeppos = 1
" }}}
" Plugin: vim-agriculture ------------------------------------------------- {{{
Plug 'https://github.com/jesseleite/vim-agriculture'
nmap <Leader>/ <Plug>RgRawSearch
vmap <Leader>/ <Plug>RgRawVisualSelection
nmap <Leader>* <Plug>RgRawWordUnderCursor
" }}}
" }}}
" Async ------------------------------------------------------------------- {{{
" Add dispatch back in, so that Fugitive can use it
Plug 'https://github.com/tpope/vim-dispatch'
" }}}
" Miscellaneous ----------------------------------------------------------- {{{
" Plugin: Notational FZF -------------------------------------------------- {{{
Plug 'https://github.com/Alok/notational-fzf-vim'
let g:nv_search_paths = ['~/3\ Current/Notes']
let g:nv_use_short_pathnames = 1
nnoremap <c-n> <ESC>:NV<CR>
" }}}
" }}}
call plug#end()
" }}}
" Useful variables -------------------------------------------------------- {{{
let g:isMac = has('macunix')
let g:isUnix = has('unix') && ! has('macunix')
let g:isWindows = has('win32')
" }}}
" Basic settings ---------------------------------------------------------- {{{
""" " Miscellaneous settings
set encoding=utf-8 " UTF-8 everywhere
set termencoding=utf-8 " UTF-8 everywhere
scriptencoding utf-8 " UTF-8 everywhere
set t_RV= ttymouse=xterm2 " Fix a 'Vim inserts spurious 'c' when editing via ssh' problem
set clipboard=unnamedplus,unnamed,exclude:cons\|linux " Use the system clipboard for copy/paste
set ttyfast " Tell Vim we're using a fast connection - smoother redraws
set backspace=indent,eol,start " Backspace over everything in insert mode
set writebackup " Use a backup file just for the purposes of saving
set backupcopy=yes " using 'auto'/'no' may cause file-watching programs to not see changes
set history=10000 " Keep 10000 lines of command line history
set undolevels=10000 " Keep lots of undo
set ruler " Show the cursor position all the time
set showcmd " Display incomplete commands
set display=lastline,uhex " Show unprintables as hex and show as much of last line as possible
set redrawtime=3000 " Wait up to 3s to syntax-hightlight large files
set lazyredraw " Set lazy redraw, to speed up macros and the like
set sessionoptions+=winpos,resize " Save window positions and sizes as well
set hidden " Allow movement to another buffer w/o saving the current one
set showmatch " Show matching bracket
set matchtime=3 " (for only 0.3s)
set confirm " Get confirmation before we do anything stupid
set whichwrap+=<,>,[,],h,l " <left> and <right> move over line endings
set browsedir=current " Open up the file-browser in the current directory
set nobomb " Don't write a Byte Order Mark
set matchpairs+=<:> " Match angle-brackets as well by default
set linebreak " Break lines at a sensible place
set noerrorbells " Error bells are annoying
set title " Set descriptive window/terminal title
set report=0 " Report any lines changed
set printoptions=paper:A4 " (even though almost all prints go to PDF anyway)
set splitright " When splitting vertically, split to the right
set splitbelow " When splitting horizontally, split below
set scrolloff=5 " Don't go right to the edge of the window when scrolling
set sidescroll=1 " scroll one character at a time to reveal more text as needed
set sidescrolloff=5 " Lines visible to the left/right of cursor when scrolling
set laststatus=2 " Always show a status line
set nomodeline " Disallow modelines (for security reasons)
set autowrite " Write file before some commands
set wildmenu " Enable wildmenu for completion
set wildmode=longest:full,full " Complete the next full match
set synmaxcol=300 " Don't syntax-colour long lines (too slow otherwise)
set virtualedit=all " Allow the cursor to move to 'invalid' places
set complete=.,w,b,t " Complete current buffer, other windows, other buffers and tags
set cmdheight=2 " Avoid 'Press Enter' messages
set fillchars=diff:⣿,vert:│ " Have different vertical splits for diffs
set switchbuf=useopen " Jump to first open window containing buffer (if possible)
set diffopt=filler,iwhiteall " show filler lines and ignore whitespace
set diffopt+=hiddenoff " don't use diff mode for a buffer when it becomes hidden
set diffopt+=vertical " show diffs vertically
if v:version > 810 || v:version == 810 && has('patch360')
set diffopt+=indent-heuristic " add alternative diff options
" set diffopt+=algorithm:patience " off by default as it's slower
endif
set breakindent " indent wrapped lines
set noshowmode " vim-crystalline shows this for us
set spellfile=~/.vim/custom-dictionary.utf-8.add
set autoread " Auto-reload files modified outside of vim
set nrformats=hex " Ignore octal/binary for incrementing/decrementing numbers
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" Mouse
set mouse=a " Enable the mouse for all modes
set mousehide " Hide mouse while typing
set mousemodel=popup " Use popup menu for right mouse button
set formatoptions+=c " Auto-wrap comments
set formatoptions+=n " Recognize numbered lists
set formatoptions+=o " Insert comment leader after 'o' or 'O'
set formatoptions+=q " Allow formatting of comments with 'gq'
set formatoptions+=r " Insert comment leader after <Enter>
set formatoptions-=t " break comment-lines at &textwidth, but not code
" Delete comment character when joining commented lines
if v:version > 703 || v:version == 703 && has('patch541')
set formatoptions+=j " remove extra comment leaders when joining lines
set nojoinspaces " only add a single space when joining lines
endif
set shortmess=a " Shortcut for various status line options
set shortmess+=T " Truncate messages in the middle if too long
set shortmess+=I " Disable intro message
set shortmess+=t " Truncate file at start if too long
set shortmess+=O " Message for reading file overwrites previous
set viminfo='1000 " Keep marks for N files
set viminfo+=<1000 " Keep N lines for each register
set viminfo+=h " Don't restore hlsearch on startup
set completeopt+=menu " use popup menu to show completions
set completeopt+=menuone " use popup menu even if only one completion match
set completeopt+=preview " show the preview window
set completeopt+=noselect " don't select any menu item by default
set completeopt+=noinsert " don't insert until I make a selection
" }}}
" Clipboard --------------------------------------------------------------- {{{
set clipboard=unnamed
" }}}
" Colors/GUI -------------------------------------------------------------- {{{
if has('gui_running')
set background=dark
colorscheme srcery
set guioptions=egm
set lines=60
set columns=180
set guifont=SF\ Mono\ Powerline:h12
set fuoptions=maxvert,maxhorz
else
if &t_Co >= 256
" force true color on within tmux
let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
if $ITERM_PROFILE ==# 'Light'
colorscheme PaperColor
set background=light
else
colorscheme srcery
set background=dark
endif
else
colorscheme darkblue
endif
" restore screen after quitting
if has('terminfo')
let &t_Sf='\ESC[3%p1%dm'
let &t_Sb='\ESC[4%p1%dm'
else
let &t_Sf='\ESC[3%dm'
let &t_Sb='\ESC[4%dm'
endif
" Prevent Vim from clobbering the scrollback buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
" don't clear background color
set t_ut=
endif
" Switch syntax highlighting on, when the terminal has colors
if &t_Co > 2 || has('gui_running')
syntax enable
syntax sync maxlines=200
syntax sync minlines=50
endif
if exists('+colorcolumn')
set colorcolumn=80
else
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/
endif
" }}}
" Tabs -------------------------------------------------------------------- {{{
" For an explanation of the 'tabs vs spaces' used below, see
" <http://www.jwz.org/doc/tabs-vs-spaces.html>
set shiftwidth=4 " # spaces for autoindent steps
set shiftround " Always round to a multiple of 'shiftwidth'
set tabstop=4 " Tabs = 4 spaces, but 'expandtab' *must* be set
set softtabstop=4 " # spaces that a tab counts for
set expandtab " Turn all tabs to spaces on save
set smarttab " Use 'shiftwidth' spaces instead of tabs
set autoindent " Copy indent from current line when starting a new one
filetype plugin indent on
" }}}
" Searching --------------------------------------------------------------- {{{
set ignorecase " Ignore case when searching
set infercase " Make completions smarter about cases
set smartcase " Override 'ignorecase' when needed
set incsearch " Show search matches as you type
set hlsearch " Try seach highlights again
augroup nohighlight
autocmd!
autocmd VimEnter * nohls
augroup END
nnoremap ,, :nohls<CR>
" Use tab and shift-tab to move between matches while in search ('/') mode
cnoremap <expr> <tab> getcmdtype() =~ '[?/]' ? '<c-g>' : feedkeys('<tab>', 'int')[1]
cnoremap <expr> <s-tab> getcmdtype() =~ '[?/]' ? '<c-t>' : feedkeys('<s-tab>', 'int')[1]
" }}}
" Command window ---------------------------------------------------------- {{{
" Typos
command! -bang E e<bang>
command! -bang Q q<bang>
command! -bang W w<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Wq wq<bang>
command! -bang WQ wq<bang>
command! -bang Wn wn<bang>
command! -bang WN wn<bang>
command! -bang Xa xa<bang>
command! -bang XA xa<bang>
augroup command_window
autocmd!
" have <Ctrl-C> leave cmdline-window
autocmd CmdwinEnter * nnoremap <buffer> <C-c> :q\|echo ""<cr>
autocmd CmdwinEnter * inoremap <buffer> <C-c> <esc>:q\|echo ""<cr>
" start command line window in insert mode and no line numbers
autocmd CmdwinEnter * startinsert
autocmd CmdwinEnter * set nonumber
augroup END
" }}}
" Help -------------------------------------------------------------------- {{{
" Open help in a vertical split instead of the default horizontal split
" http://vim.wikia.com/wiki/Replace_a_builtin_command_using_cabbrev
cabbrev h <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'vert h' : 'h')<cr>
cabbrev help <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'vert h' : 'help')<cr>
" Disable "F1 for help"
nnoremap <F1> <nop>
" }}}
" Folding ----------------------------------------------------------------- {{{
set foldenable " Enable folds
set foldnestmax=1 " Only go 1 levels deep
set foldlevel=99 " By default, show them all though
" The following open closed folds
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
set foldcolumn=1 " Show the foldcolumn
" Make zO recursively open whatever top level fold we're in, no matter where the
" cursor happens to be.
nnoremap zO zCzO
function! MyFoldText() abort " {{{
let s:line = getline(v:foldstart)
let s:nucolwidth = &foldcolumn + &number * &numberwidth
let s:windowwidth = winwidth(0) - s:nucolwidth - 3
let s:foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let s:onetab = strpart(' ', 0, &tabstop)
let s:line = substitute(s:line, '\t', s:onetab, 'g')
let s:line = strpart(s:line, 0, s:windowwidth - 2 -len(s:foldedlinecount))
let s:fillcharcount = s:windowwidth - len(s:line) - len(s:foldedlinecount)
return s:line . '…' . repeat(' ',s:fillcharcount) . s:foldedlinecount . '…' . ' '
endfunction " }}}
set foldtext=MyFoldText()
" }}}
" File loading ------------------------------------------------------------ {{{
augroup vimStartup
autocmd!
" 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) and for a commit message (it's
" likely a different one than last time).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
\ | exe "normal! g`\""
\ | endif
augroup END
" Fileformats
set fileformats=unix,dos,mac
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/bin/*,*/pkg/*
set wildignore+=*.pdf,*.zip,*.so " binaries
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX nonsense
set wildignore+=migrations " Django migrations
set wildignore+=*.pyc,*.pyo " Python byte code
" }}}
" Undo -------------------------------------------------------------------- {{{
" Trailing double slashes on directory names below cause Vim to save the
" full path to each file, but with slashes escaped - means we can have
" backup/undo files with the same names in multiple directories and keep
" them distinct
if exists('+undofile')
if !isdirectory(expand('~/.vim/tmp/undo'))
!mkdir -p ~/.vim/tmp/undo
endif
set backupdir^=~/.vim/tmp// " Backups are written to ~/.vim/tmp/ if possible
set directory^=~/.vim/tmp// " Swapfiles are also written to ~/.vim/tmp too
set undodir^=~/.vim/tmp/undo//,/tmp//
set writebackup " protect against crash-during-write
set nobackup " but do not persist backup after successful write
set backupcopy=auto " use rename-and-write-new method whenever safe
set undofile
set noswapfile
set updatetime=500 " Write swap files after 0.5 seconds of inactivity.
" Drop an undo breakpoint so I can recover from insert-mode ctrl-w's
inoremap <c-w> <c-g>u<c-w>
"Meaningful backup name, ex: filename@2015-04-05.14:59
augroup named_backups
autocmd!
autocmd BufWritePre * let &bex = '@' . strftime("%F.%H:%M")
augroup END
endif
" }}}
" Display options --------------------------------------------------------- {{{
" Use better looking listchars if they are supported
if has('multi_byte')
set listchars=tab:»\ ,extends:›,precedes:‹,trail:·,nbsp:‗,eol:$
let &showbreak = nr2char(8618).' ' " Show ↪ at the beginning of wrapped lines
else
set listchars=tab:>\ ,extends:>,precedes:<,trail:-,nbsp:%,eol:$
endif
" Pop-up menu colors
highlight Pmenu guibg=yellow guifg=black
highlight PmenuSel guibg=white guifg=black
" Resize splits when the window is resized
augroup resized
autocmd!
au VimResized * exe "normal! \<c-w>="
augroup END
if &diff
"I'm only interested in diff colours
syntax off
endif
" https://github.com/khuedoan/dotfiles/blob/97d5d7bb4f00374a19beb50eaa75a83a7d570b06/.vimrc#L48
" Change cursor shape in different modes (see :help cursor-shape)
let &t_EI = "\033[2 q" " NORMAL █
let &t_SI = "\033[5 q" " INSERT |
" }}}
" Mappings ---------------------------------------------------------------- {{{
" Swap the behaviour of j/k with gj/gk - i.e. j/k always move by screenlines
nnoremap k gk
nnoremap j gj
nnoremap gk k
nnoremap gj j
" Miscellaneous
" <leader>cd cd to the directory of the current buffer
nnoremap <leader>cd :lcd %:h<CR>
" Moves the character under the cursor to the end of the line.
nnoremap zl :let @z=@"<cr>x$p:let @"=@z<cr>
" Quickly select text you just pasted
noremap gV `[v`]
" Move to paragraph lines, not the spaces between them
nnoremap <expr> { len(getline(line('.')-1)) > 0 ? '{+' : '{-'
nnoremap <expr> } len(getline(line('.')+1)) > 0 ? '}-' : '}+'
" Use <tab> to move between windows
nnoremap <Tab> <C-w>w
nnoremap <S-Tab> <C-w>W
" Paste the first copy repeatedly using <localleader>p
xnoremap <leader>p "0p
nnoremap <leader>p "0p
" Don't select the end of line with '$' - I almost always cursor left when
" doing this
nmap $ g_
" Increment/decrement the selection as an ordered list
vnoremap + g<C-a>gv
vnoremap - g<C-x>gv
" Try [twf](https://github.com/wvanlint/twf)
function! Twf()
let temp = tempname()
execute 'silent ! twf ' . @% . ' > ' . temp
redraw!
try
let out = filereadable(temp) ? readfile(temp) : []
finally
silent! call delete(temp)
endtry
if !empty(out)
execute 'edit! ' . out[0]
endif
endfunction
nnoremap <silent> <leader>tv :call Twf()<CR>
" Try using Q as @q
nnoremap Q @q
" Try adding an 'edit register' mapping - type 'cq' followed by the register
" to edit
nnoremap <expr> cq call({r-> ":\<c-u>let @".r." = \<c-r>\<c-r>=string(getreg('".r."'))\<cr>\<c-f>\<left>" }, [nr2char(getchar())])
" Try gs as a shortcut to start a global search and replace
nnoremap gs :%s/
" Get out of diff
nnoremap <silent> <c-w><c-o> :diffoff!<bar>only<cr>
nnoremap <silent> <c-w>o :diffoff!<bar>only<cr>
" Formatting -------------------------------------------------------------- {{{
" gq wrapper that:
" - tries its best at keeping the cursor in place
" - tries to handle formatter errors
function! Format(type, ...)
normal! gggqG
if v:shell_error > 0
silent undo
redraw
echomsg 'formatprg "' . &formatprg . '" exited with status ' . v:shell_error
endif
call winrestview(w:gqview)
unlet w:gqview
endfunction
nmap <silent> gq :let w:gqview = winsaveview()<CR>:set opfunc=Format<CR>g@<CR>
" }}}
" Compiling --------------------------------------------------------------- {{{
nnoremap <leader>cc :w<CR>:copen 6<CR><C-w>p:make<CR>
nnoremap <leader>co :copen 6<CR>
nnoremap <leader>cl :cclose<CR>
" }}}
" Saving ------------------------------------------------------------------ {{{
" Save normal buffers on <CR> - use `:update` to only save when modified -
" also turn off search highlighting
nnoremap <silent><expr> <CR> empty(&buftype) ? ":nohls<CR> \| :update\<CR>" : ":nohls<CR>\<CR>"
" }}}
" Buffers ----------------------------------------------------------------- {{{
set wildcharm=<tab>
" }}}
" Windows ----------------------------------------------------------------- {{{
" Tmux-like split panes navigation
noremap <C-W>\| :vsplit<CR><C-W>l
noremap <C-W>- :split<CR><C-W>j
noremap <C-W><C-W> <C-W>w
" }}}
" Lines ------------------------------------------------------------------- {{{
" Keep the cursor in place while joining lines using 'J'
nnoremap J mzJ`z
" Join lines in insert mode
inoremap <C-j> <C-o>J
" }}}
" }}}
" Arrow keys -------------------------------------------------------------- {{{
function SetArrowKeys()
" Repurpose arrow keys to move lines
" Arrow key remapping:
" Up/Dn = move line up/dn
" Left/Right = indent/unindent
" Normal mode
nnoremap <silent> <buffer> <Left> <<
nnoremap <silent> <buffer> <Right> >>
nnoremap <silent> <buffer> <Up> :<C-u>silent move-2<CR>:silent! ==<CR>
nnoremap <silent> <buffer> <Down> :<C-u>silent move+<CR>:silent! ==<CR>
" Visual mode
vnoremap <silent> <buffer> <Left> <gv
vnoremap <silent> <buffer> <Right> >gv
vnoremap <silent> <buffer> <Up> :move-2<CR>gv=gv
vnoremap <silent> <buffer> <Down> :move'>+<CR>gv=gv
" Insert mode
inoremap <silent> <buffer> <Left> <C-D>
inoremap <silent> <buffer> <Right> <C-T>
endfunction
augroup arrowkeys
autocmd!
autocmd BufNewFile,Bufread * call SetArrowKeys()
augroup END
" }}}
" Vim editing ------------------------------------------------------------- {{{
nnoremap <leader>v :e $MYVIMRC<cr>:lcd ~/src/dotfiles<cr>
nnoremap <leader>V :vsplit $MYVIMRC<cr>:lcd ~/src/dotfiles<cr>
augroup VimFiles
autocmd!
autocmd FileType vim setlocal foldmethod=marker
augroup end
" automatically source the .vimrc file if I change it
" the bang (!) forces it to overwrite this command rather than stack it
augroup autosourcevimrc
autocmd!