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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
|
" Personal vimrc config file.
" Last Changed: 2019-01-27
" Author: Federico Igne <>
" License: This file is placed in the public domain.
" {{{1 TODO
" [ ] Change `errorformat` for Stack (Haskell compilation via `stack
" build`)
"
" [ ] Different highlight for currently selected match (have a look at
" the code in the comments:
" https://www.reddit.com/r/vim/comments/ap9we4/vimsearchhi_highlight_the_current_search_result/
"
" [ ] Play with omnicomplete options
" http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
"
" [ ] Integrate Omnicompletion for Haskell project. You should be able
" to integrate it with tags.
" http://vim.wikia.com/wiki/Omni_completion
"
" [ ] Integrate linting for Haskell project. Have a look at
" Interesting gist: https://gist.github.com/romainl/ce55ce6fdc1659c5fbc0f4224fd6ad29
" HLint for haskell: https://hackage.haskell.org/package/hlint
"
" [ ] Have a look at these autoclosing mappings...might be interesting.
" https://medium.com/vim-drops/custom-autoclose-mappings-1ff90f45c6f5
" {{{1 GENERAL SETTINGS
" Don't open Vim in vi-compatibility mode.
" Note: this is implicit when a user .vimrc file is detected.
" set nocompatible
" Set encoding to utf8.
if has('multi_byte')
set encoding=utf8
endif
" Enable modeline capabilities
set modeline
" Set file format to `unix' (set newline encoding to <NL>).
set fileformat=unix
" May use `dos' file format if <CR><NL> is detected as newline
" encoding.
set fileformats=unix,dos
" Automatically update a file whenever it is detected to have been
" changed outside of Vim.
" NOTE: you need something like
" https://github.com/tmux-plugins/vim-tmux-focus-events
" in order for autoread to work in terminal Vim.
set autoread
" Automatically save changes when switching buffers (and some other
" commands). Use `autowriteall` if you want the hardcore version.
set autowrite
" A buffer becomes hidden when it is abandoned.
set hidden
" Do not redraw the screen while executing macros or other (not explicitly
" typed) commands. This speeds up the iteration of macros and avoids
" screen flickering/lag.
set lazyredraw
" If in `&updatetime` milliseconds nothing is typed the swap file will
" be written to disk. Also used for the `CursorHold` autocommand event.
set updatetime=2000
" Reduce the time Vim will try to recognize commands consisting of
" a sequence of keys. In particular `timeoutlen` is the timeout for
" mappings, `ttimeoutlen` is the timeout for key codes (like <Esc>).
set timeoutlen=2000 ttimeoutlen=100
" Remove beep or visual effect on errors.
set noerrorbells
set novisualbell t_vb=
" {{{1 COLORS/INTERFACE
" Cursor shape:
" * set cursor to a steady block in normal mode;
" * set cursor to a blinking underline in insert mode.
" Possible values:
" 0 -> blinking block.
" 1 -> blinking block (default).
" 2 -> steady block.
" 3 -> blinking underline.
" 4 -> steady underline.
" 5 -> blinking bar (xterm).
" 6 -> steady bar (xterm).
let &t_EI = "\<Esc>[2 q"
let &t_SI = "\<Esc>[3 q"
" Resets cursor to terminal default
augroup stCursor
autocmd!
autocmd VimLeave * silent !echo -ne "\e[6 q"
augroup END
" Leave n lines above/below cursor when scrolling.
" If set to a very large value the cursor line will always be in the
" middle of the window (except at the start or end of the file).
set scrolloff=999
" Leave n chars on the left/right of the cursor when scrolling.
" If set to a very large value the cursor will always be in the
" middle of the window (except when close to the beginning of the line).
set sidescrolloff=20
" Remove numbers. `Hybrid' number mode (show relative numbers with
" current line on cursor position) can be toggles with `<leader>in`
set nonumber norelativenumber
" Show typed command on the right side of the status bar.
if has('cmdline_info')
set showcmd
endif
" Do not show current mode in status bar. Basically remove the
" "-- INSERT --" status string, which is redundant when using a
" statusline plugin.
set noshowmode
" Use true colors or fall back to 256 colors.
if has('termguicolors')
" Use 'guifg' and 'guibg' attributes in the terminal (true color).
set termguicolors
" Necessary escape codes
" https://www.reddit.com/r/vim/comments/5416d0/true_colors_in_vim_under_tmux/
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
else
set t_Co=256
endif
" Any modification to the highlights groups needs to be done here,
" before setting the colorsheme. This is because most colorschemes clear
" the highlight groups before setting them... this includes groups like
" User1-9. Setting this hook, it's possible to set custom colors
" everytime a colorscheme is reloaded.
augroup CustomColors
autocmd!
" Statusline
autocmd ColorScheme * highlight clear StatusLine
autocmd ColorScheme * highlight clear StatusLineNC
autocmd ColorScheme * highlight clear StatusLineTerm
autocmd ColorScheme * highlight clear StatusLineTermNC
autocmd ColorScheme * highlight StatusLine ctermfg=248 ctermbg=239 guifg=#bdae93 guibg=#504945
autocmd ColorScheme * highlight StatusLineNC ctermbg=237 ctermfg=246 guibg=#3c3836 guifg=#a89984
autocmd ColorScheme * highlight StatusLineTerm ctermfg=248 ctermbg=239 guifg=#bdae93 guibg=#504945
autocmd ColorScheme * highlight StatusLineTermNC ctermfg=08 ctermbg=237 guifg=#665c54 guibg=#3c3836
autocmd ColorScheme * highlight User1 cterm=bold gui=bold ctermfg=248 ctermbg=239 guifg=#bdae93 guibg=#504945
autocmd ColorScheme * highlight User2 cterm=italic gui=italic ctermfg=248 ctermbg=239 guifg=#bdae93 guibg=#504945
autocmd ColorScheme * highlight User3 cterm=bold gui=bold ctermfg=237 ctermbg=248 guifg=#3c3836 guibg=#bdae93
" Search matches
autocmd ColorScheme * highlight clear IncSearch
autocmd ColorScheme * highlight IncSearch ctermfg=00 ctermbg=03 guifg=#282828 guibg=#fabd2f
autocmd ColorScheme * highlight Search cterm=underline ctermbg=00 ctermfg=03 guibg=#282828 guifg=#fabd2f
" Guides
autocmd ColorScheme * highlight ColorColumn ctermbg=237 guibg=#3c3836
autocmd ColorScheme * highlight CursorLine cterm=NONE ctermbg=237 gui=NONE guibg=#3c3836
" Italics comments
" NOTE: that the terminal must support italics for this option to work
autocmd ColorScheme gruvbox highlight Comment cterm=italic
" Visual
autocmd ColorScheme * highlight clear Visual
autocmd ColorScheme * highlight Visual ctermbg=239 guibg=#504945
" Errors
" Default highlight for errors is `reverse`d which looks terrible.
autocmd ColorScheme gruvbox highlight clear Error
autocmd ColorScheme gruvbox highlight clear ErrorMsg
autocmd ColorScheme gruvbox highlight Error cterm=bold term=bold ctermbg=00 ctermfg=01 guibg=#282828 guifg=#fb4934
autocmd ColorScheme gruvbox highlight link Errormsg Error
" LSP signs and highlights.
autocmd ColorScheme gruvbox highlight LspErrorText cterm=bold gui=bold ctermbg=237 ctermfg=01 guibg=#3c3836 guifg=#cc241d
autocmd ColorScheme gruvbox highlight link LspErrorHighlight Error
autocmd ColorScheme gruvbox highlight LspWarningText cterm=bold gui=bold ctermbg=237 ctermfg=03 guibg=#3c3836 guifg=#d79921
autocmd ColorScheme gruvbox highlight LspWarningHighlight cterm=bold gui=bold ctermbg=00 ctermfg=03 guibg=#282828 guifg=#d79921
autocmd ColorScheme gruvbox highlight LspInformationText cterm=bold gui=bold ctermbg=237 ctermfg=08 guibg=#3c3836 guifg=#928374
autocmd ColorScheme gruvbox highlight LspInformationHighlight cterm=bold gui=bold ctermbg=00 ctermfg=07 guibg=#282828 guifg=#a89984
autocmd ColorScheme gruvbox highlight link LspHintText LspInformationText
autocmd ColorScheme gruvbox highlight link LspHintHighlight LspInformationHighlight
" Spelling
autocmd ColorScheme * highlight clear SpellBad
autocmd ColorScheme * highlight clear SpellCap
autocmd ColorScheme * highlight clear SpellLocal
autocmd ColorScheme * highlight clear SpellRare
autocmd ColorScheme * highlight SpellBad cterm=underline gui=underline ctermbg=00 ctermfg=01 guibg=#282828 guifg=#cc241d
autocmd ColorScheme * highlight SpellCap cterm=underline gui=underline ctermbg=00 ctermfg=03 guibg=#282828 guifg=#d79921
autocmd ColorScheme * highlight SpellLocal cterm=underline gui=underline ctermbg=00 ctermfg=04 guibg=#282828 guifg=#458588
autocmd ColorScheme * highlight link SpellRare SpellLocal
" Allows alpha values for terminalbackground
"autocmd ColorScheme * highlight Normal ctermbg=NONE
augroup END
" Also you need to teach Vim the terminal escape sequences for
" italics (insert '^[' with <CTRL-v><Esc> in Insert mode)
set t_ZH=[3m
set t_ZR=[23m
" Set colorscheme to gruvbox dark
set background=dark
colorscheme gruvbox
" Display whitespaces with some flavour
set list
" Remove eol default symbol
set listchars=
" Highlight eol (maybe consider moving this on specific filetypes that
" use soft wrapping, to avoid too much noise)
set listchars+=eol:¬
" Make tabs a bit more visible
set listchars+=tab:├─
" Highlight trailing spaces
set listchars+=trail:·
" Last/first character when the current line is longer that the window
" width
set listchars+=extends:»,precedes:«
" {{{1 STATUSLINE
if has('statusline')
" Always show the statusline.
set laststatus=2
" Custom mode flags.
let g:modeFlag={
\ 'n' : 'N',
\ 'no' : 'N·Operator Pending',
\ 'v' : 'V',
\ 'V' : 'V·Line',
\ '' : 'V·Block',
\ 's' : 'S',
\ 'S' : 'S·Line',
\ '' : 'S·Block',
\ 'i' : 'I',
\ 'ic' : 'I·Compl',
\ 'ix' : 'I·XCompl',
\ 'R' : 'R',
\ 'Rc' : 'R·Compl',
\ 'Rv' : 'R·Virtual',
\ 'Rx' : 'R·XCompl',
\ 'c' : 'C',
\ 'cv' : 'E·Vim ',
\ 'ce' : 'E',
\ 'r' : 'Prompt',
\ 'rm' : 'More',
\ 'r?' : 'Confirm',
\ '!' : 'Shell',
\ 't' : 'T'
\}
" Custom flag by name (overrides the mode flag).
let g:nameFlag={
\ '[Grammarous]' : 'Grammar'
\}
" Custom filetype flags (overrides the mode flag).
let g:filetypeFlag={
\ 'help' : 'Help',
\ 'qf' : 'QFix',
\ 'netrw' : 'Netrw',
\ 'fugitive' : 'Gstatus',
\ 'tagbar' : 'TagBar',
\ 'gitcommit' : 'Gcommit'
\}
" Special flags (overrides previous flags).
" Currently support:
" 'preview': displayed for a preview window.
let g:specialFlag={
\ 'preview' : 'Preview'
\}
" Some elements will be hidden if the window width falls below
" `g:fullstatusline` (namely relative path, git statistics, some
" file flags).
let g:fullstatusline=81
" Resets statusline
set statusline=
" Overrides hl-User3 if buffer is modified
set statusline+=%{dyamon#statusline#setcolor()}
" Mode flag.
set statusline+=%3*\ %{dyamon#statusline#modeflag()}\
" Start truncate from here
set statusline+=%<
" Relative filename.
set statusline+=%*\ %{dyamon#statusline#fileprefix()}%1*%t
" Left/right separator
set statusline+=%=
" Git info (if Fugitive and GitGutter are available)
set statusline+=\ %*%{dyamon#statusline#gitinfo()}
set statusline+=[
" Various flags and metadata. In order:
" * modified/modifiable flag
set statusline+=%M
" * readonly flag
set statusline+=%R
" * session flag
set statusline+=%{dyamon#statusline#session()}
" * filetype
set statusline+=%{dyamon#statusline#filetype()}
" * file encoding
set statusline+=%{dyamon#statusline#fileenc()}
set statusline+=]\
" <current line>/<total lines>
set statusline+=%3*\ %3l/%L
" <current column>/<total columns>
set statusline+=:%2c/%2{len(getline('.'))}
" <page percent>
set statusline+=\ [%P] " language server indicator
set statusline+=%{dyamon#statusline#lsp()}
endif
" {{{1 SEARCH/COMPLETION
" Set highlighting for search results. Also search results are
" dynamically highlighted.
if has('extra_search')
set hlsearch incsearch
endif
" Case-insensitive when searching; case-sensitive only if search string
" includes a capital letter.
set ignorecase
set smartcase
" Don't echo search wrap messages.
set shortmess+=s
" Basically enables a fuzzy-finder in command mode. Completion via <Tab>
" in command mode search in the whole subtree of the pwd.
set path+=**
if has("wildmenu")
" Turn on wildmenu (a nice multi-option menu).
set wildmenu
" Hitting <Tab> will first complete the longest common prefix; hit
" <Tab> again for a complete list of possible completions (cicle through
" them with <Tab>).
set wildmode=longest:full,full
" File patterns ignored during <Tab> completion.
set wildignore+=*.o,*~
" Java/Scala compilation files
set wildignore+=*.class
endif
" Options for Insert mode completion:
" + menuone: display popup menu when there is only one match;
" + longest only insert the longest common text of the matches;
" + preview: show extra information about the currently selected
" completion in the preview window.
set completeopt=longest,menuone,preview
" {{{1 SPELL CHECKING
if has("syntax")
" Use double method to compute suggestions (takes into account both
" syntax errors and words with a similar sound - useful if English
" is not your first language).
set spellsuggest=double,15
set spelllang=en_gb
endif
" {{{1 WINDOWS
if has('windows')
" When using `:[v]split' (or any command including it) the buffer is
" opened below/right.
set splitbelow splitright
endif
" {{{1 EDITING
" Turn off soft wrap
set nowrap
" Set hard wrap to 72 columns. Control what is affected by this option
" with `formatoptions`.
set textwidth=72
" DEFAULT: formatoptions=tcq
" t Auto-wrap text using textwidth
" c Auto-wrap comments using textwidth, insert the current comment
" leader automatically.
" q Allow formatting of comments with "gq".
" j Where it makes sense, remove a comment leader when joining
" lines.
" l Long lines are not broken in insert mode: When a line was longer
" than 'textwidth' when the insert command started, Vim does not
" automatically format it.
set formatoptions+=jl
" Here is assumed most of the time I'm editing code so I want auto-wrap
" turned on for comments but not for code. If editing prose, use a
" ftplugin with `setlocal formatoptions+=t`
set formatoptions-=t
" Do not insert two spaces after a `.`, `?` and `!` with a join command
set nojoinspaces
" Turn tabs into spaces but still keep some advantages of tabs
set expandtab smarttab
" Set number of spaces a tab counts for, and the number of spaces used
" per (auto)indent step
set tabstop=4
set shiftwidth=0 " fallback to `tabstop`
" Maintain indentation from previous line. Also activate some smart
" C-like auto-indenting features. For more advanced indentation use
" `indentexpr`.
set autoindent
if has("smartindent")
set smartindent
endif
" Show matching bracket (briefly jumping for 0.n seconds)
set showmatch matchtime=2
" Add new matching bracket <,>.
" Required by mortimer.vim plugin
set matchpairs+=<:>
" Allow backspacing over <eol> in insert mode (eol), start of insert
" (start), autoindentation (indent).
set bs=start,eol,indent
" Removes <BS> and <Space> from the default `whichwrap` list, preventing
" them from moving to the next/previous line when on the first/last
" character of a line.
" Motivation:
" * <Space>: is the leader key;
" * <BS>: why would you use backspace?
set whichwrap=
" Fold related options.
if has('folding')
" Default folding method is explicit with markers {{{,}}}.
set foldmethod=marker
" Override default `foldtext` with something like:
" »··[42ℓ]··TITLE···················································
set fillchars+=fold:·
set foldtext=CustomFoldText()
function! PadNumber(n, pad_to) abort
let l:padding = ''
let l:pad_to = a:pad_to
while (l:pad_to > 0)
if (a:n < pow(10,l:pad_to))
let l:padding .= ' '
endif
let l:pad_to -= 1
endwhile
return l:padding . a:n
endfunction
function! CustomFoldText() abort
let l:middot='··'
let l:start='»'
let l:italicsl='ℓ'
let l:lines='[' . PadNumber(v:foldend - v:foldstart + 1, 2) . l:italicsl . ']'
let l:prefix=substitute(&commentstring,'%s',' ','')
let l:first=substitute(substitute(substitute(getline(v:foldstart), '\v *', '', ''),'{{{\d','','g'),l:prefix,'','')
let l:dashes=substitute(v:folddashes, '-', l:middot, 'g')
return l:start . l:middot . l:lines . l:dashes . l:middot . l:first
endfunction
endif
if has('virtualedit')
" Allow visual-block selection to exceed text boundaries
set virtualedit=block
endif
" {{{1 POLLUTION
" Backup files (defaults: 'backup' off, 'writebackup' on if available)
if $USER ==# 'root'
" This is done to avoid backups for files that might contain
" sensible information.
set nobackup nowritebackup
elseif has('writebackup')
" Backup file is created *while* writing a file, and deleted
" afterwards. This gives you a backup when something goes wrong
" during a write operation.
set nobackup writebackup
else
" Keep a backup for each file.
set backup
endif
" Have a look at the help for an explanation on the definition of
" `backupdir` and `directory`
set backupdir=~/.local/share/vim/backup//,.
" Swap files ('swapfile' on)
if $USER ==# 'root'
" This is done to avoid swap files that might contain sensible
" information.
set noswapfile
else
" Create swapfiles for any buffer (default).
set swapfile
endif
set directory=~/.local/share/vim/swap//,.
" Undo files ('undofile' off)
if has('persistent_undo') && $USER !=# 'root'
" Persist undo tree in a file and restore it when reading a file.
" Avoiding this for `root` user to prevent sensible information to
" appear in undo files.
set undodir=~/.local/share/vim/undo//,.
set undofile
endif
if has('viminfo')
if $USER ==# 'root'
" `viminfo` is reset for `root` user to avoid storing sensible
" information.
set viminfo=
else
" Save marks for at most 100 files (include {jump,change}list).
set viminfo='100
" Don't save search history
set viminfo+=/0
" Save 100 lines of command history
set viminfo+=:100
" Save at most 500 lines per register.
set viminfo+=<200
" Don't save anything about the input-line history
set viminfo+=@0
" Save file marks (A-Z and 0-9).
set viminfo+=f1
" Do not highlight last search pattern when loading the viminfo
" file.
set viminfo+=h
if isdirectory($HOME . '/.local/share/vim')
set viminfofile=~/.local/share/vim/viminfo
else
set viminfofile=~/.viminfo
endif
endif
endif
" Session files
" Stored in $VIM_SESSIONS=~/.local/share/vim/sessions
" NOTE: these options are provided here just in case TPope's
" `vim-obsession` plugin is not available (`-=` is idempotent anyway)
if has('mksession')
" Don't save global options and mappings in session files (`vimrc`
" file is sourced anyway right?)
set sessionoptions-=options
" Don't save empty windows
set sessionoptions-=blank
endif
" {{{1 AUTOCMDS
augroup focus
autocmd!
" Focused window has guides and a statusbar
autocmd BufEnter,FocusGained,VimEnter,WinEnter,BufWinEnter * call dyamon#guides#on()
autocmd BufEnter,FocusGained,VimEnter,WinEnter,BufWinEnter * call dyamon#statusline#focus()
" Unfocused windows do not have guides and the statusbar is blurred
autocmd WinLeave,FocusLost * call dyamon#guides#off()
autocmd WinLeave,FocusLost * call dyamon#statusline#blur()
" Exceptions
" TODO here 0/1 as true/false are all messed up!
autocmd Filetype help let b:guides=1
autocmd Filetype netrw let b:guides=1
autocmd Filetype qf let b:guides=1
autocmd Filetype gitcommit let b:guides=1
autocmd Filetype tagbar let b:guides=1
autocmd Filetype tagbar let b:disable_statusline=1
augroup END
augroup filetypes
autocmd!
autocmd BufRead,BufNewFile *.tex set filetype=tex
autocmd BufRead,BufNewFile *.ms set filetype=groff
autocmd BufRead,BufNewFile *.man set filetype=groff
augroup END
augroup mutt
autocmd!
autocmd BufRead,BufNewFile $TMPDIR/mutt* :Goyo 75%
augroup END
" {{{1 PLUGINS
" List of installed plugins, along with their custom configuration.
"
" Plugins are managed via Git Submodules; have a look at this for more
" details:
"
" https://gist.github.com/manasthakur/d4dc9a610884c60d944a4dd97f0b3560
"
" Add a new submodule/plugin:
"
" git submodule add --name <name> <repo> <path>
"
" Update all submodules/plugins:
"
" git submodule foreach git pull origin master
"
" NOTE: remember to generate help tags for the newly installed plugins.
" The easiest way is using:
"
" :helptags ALL
"
" also bound to `<leader>hg` (Help tags Generate)
" {{{2 FZF
" https://github.com/junegunn/fzf.vim
" {{{2 GOYO
" https://github.com/junegunn/goyo.vim ~/.vim/bundle/goyo.vim
" Fixed height to 80% fo the window.
let g:goyo_height="80%"
" Custom autocmds to hide the statusline, interact with Tmux, and change
" some colors.
augroup GoyoOptions
autocmd!
autocmd User GoyoEnter nested call dyamon#goyo#enter()
autocmd User GoyoLeave nested call dyamon#goyo#leave()
augroup END
" {{{2 MATCHIT
" Matching extends the capabilities of `%`. It's an optional plugin
" shipped with Vim.
" {{{2 NETRW
" Hides dotfiles by default when opening the file explorer.
" NB: toggle dotfiles visibility with `gh'.
" NB: when editing a dotfile this option is disabled by default.
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
" Display filesystem tree-style
let g:netrw_liststyle=3
" Turn off netrw banner.
let g:netrw_banner=0
" Directory to store bookmark and history file.
let g:netrw_home="~/.local/share/vim"
" Show preview window in a vertical split.
"let g:netrw_preview=1
" Customize behaviour of preview window.
" NB: help page is wrong when it comes to define all combinations; the
" correct config is
" g:netrw_preview g:netrw_alto result
" 1 0 :botright
" 1 1 :topleft
"let g:netrw_alto=0
"let g:netrw_altv=1
" {{{2 TAGBAR
" https://github.com/majutsushi/tagbar
" Open tagbar on the left
let g:tagbar_left = 1
" Default width of the tagbar window
let g:tagbar_width = 40
" When zooming (`x`) use the width of the longest currently visible tag.
let g:tagbar_zoomwidth = 0
" Move to the Tagbar window when opened and close it when jumping to a
" tag (implies `g:tagbar_autofocus` set)
let g:tagbar_autoclose = 1
" Sort by position in the source file.
let g:tagbar_sort = 0
" Use a case-insensitive comparison when sorting tags
let g:tagbar_case_insensitive = 1
" Folds with a level higher than this number will be closed.
let g:tagbar_foldlevel = 2
" Custom icons for tagbar folds
let g:tagbar_iconchars = ['▸', ' ']
" Location of the preview window (below the current window)
let g:tagbar_previewwin_pos = "belowright"
" Custom statusbar
let g:tagbar_status_func = 'dyamon#statusline#tagbar'
" {{{3 Additional language support
" {{{4 HASKELL
" Requires: Hasktags
let g:tagbar_type_haskell = {
\ 'ctagsbin' : 'hasktags',
\ 'ctagsargs' : '-x -c -o-',
\ 'kinds' : [
\ 'm:modules:0:1',
\ 'd:data: 0:1',
\ 'd_gadt: data gadt:0:1',
\ 't:type names:0:1',
\ 'nt:new types:0:1',
\ 'c:classes:0:1',
\ 'cons:constructors:1:1',
\ 'c_gadt:constructor gadt:1:1',
\ 'c_a:constructor accessors:1:1',
\ 'ft:function types:1:1',
\ 'fi:function implementations:0:1',
\ 'o:others:0:1'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 'm' : 'module',
\ 'c' : 'class',
\ 'd' : 'data',
\ 't' : 'type'
\ },
\ 'scope2kind' : {
\ 'module' : 'm',
\ 'class' : 'c',
\ 'data' : 'd',
\ 'type' : 't'
\ }
\ }
" {{{4 SCALA
" https://github.com/majutsushi/tagbar/wiki#scala
" {{{4 MARKDOWN
" https://github.com/majutsushi/tagbar/wiki#markdown
" {{{4 BIB
" https://github.com/majutsushi/tagbar/wiki#bib
" {{{2 UNODTREE
" https://github.com/mbbill/undotree
" Set the undotree window layout.
"
" +------------------+----------+
" | | |
" | | |
" | | undotree |
" | | |
" | | |
" +------------------+----------+
" | |
" | diff |
" | |
" +-----------------------------+
"
let g:undotree_WindowLayout=4
" Set the undotree window width.
let g:undotree_SplitWidth = 25
" Set the diff window height.
let g:undotree_DiffpanelHeight = 30
" Undotree window will get focus after being opened.
let g:undotree_SetFocusWhenToggle = 1
" Set the tree node shape.
let g:undotree_TreeNodeShape = '×'
" Use short (relative) timestamps.
let g:undotree_ShortIndicators = 1
" {{{2 VIM-BBYE
" https://github.com/moll/vim-bbye
" {{{2 VIM-COMMENTARY
" https://github.com/tpope/vim-commentary
" {{{2 VIM-FUGITIVE
" https://github.com/tpope/vim-fugitive
" {{{2 VIM-GITGUTTER
" https://github.com/airblade/vim-gitgutter
" Plugin on at startup (toggle with `<leader>gg`).
let g:gitgutter_enabled = 0
" No ANSI escape or color codes on `grep` invocation.
let g:gitgutter_grep = 'grep --color=never'
" Custom signs.
let g:gitgutter_sign_added = '▐'
let g:gitgutter_sign_modified = '▐'
let g:gitgutter_sign_removed = '▐'
let g:gitgutter_sign_modified_removed = '▐'
let g:gitgutter_sign_removed_first_line = '▐'
" Disable default mappings.
let g:gitgutter_map_keys = 0
" {{{2 VIM-OBSESSION
" https://github.com/tpope/vim-obsession
" {{{2 VIM-RACKET
" https://github.com/wlangstroth/vim-racket
" {{{2 VIM-REPEAT
" https://github.com/tpope/vim-repeat
" {{{2 VIM-SLIME
" https://github.com/jpalardy/vim-slime
" Set TMux as default target
let g:slime_target = "tmux"
" Set default TMux pane target
let g:slime_default_config = {"socket_name": "default", "target_pane": "{bottom-right}"}
" Set bridge file between VIM and TMux
let g:slime_paste_file = tempname()
" Disable default mappings
let g:slime_no_mappings = 1
" {{{2 VIM-SURROUND
" https://github.com/tpope/vim-surround
" {{{2 VIM-TMUX-FOCUS-EVENT
" https://github.com/tmux-plugins/vim-tmux-focus-events
" {{{2 VIM-TMUX-NAVIGATOR
" https://github.com/christoomey/vim-tmux-navigator
" Disable tmux navigator when zooming the Vim pane
let g:tmux_navigator_disable_when_zoomed = 1
" {{{2 VIM-VINEGAR
" https://github.com/tpope/vim-vinegar
" {{{2 VIM-TABLE-MODE
" https://github.com/dhruvasagar/vim-table-mode
" Define the table corner character
let g:table_mode_corner = '+'
" Define the character to be used for the extreme corners of the table border. >
let g:table_mode_corner_corner = '+'
" Define the table header border fill character
let g:table_mode_fillchar = '-'
" Define the table mode mapping prefix that will be prefixed for all other
" table mode mappings
let g:table_mode_map_prefix = '<LocalLeader>t'
" Define the mapping for toggling the table mode: >
let g:table_mode_toggle_map = 'm'
" Disable mappings
"let g:table_mode_disable_mappings = 1
" Disable mappings for tableize
"let g:table_mode_disable_tableize_mappings = 1
" Disable table mode syntax definitions
"let g:table_mode_syntax = 0
" Set the mapping to move up a cell vertically
let g:table_mode_motion_up_map = '{t'
" Set the mapping to move down a cell vertically
let g:table_mode_motion_down_map = '}t'
" Set the mapping to move to the left cell. >
let g:table_mode_motion_left_map = '[t'
" Set the mapping to move to the right cell. >
let g:table_mode_motion_right_map = ']t'
" {{{2 VIM-LSP
" https://github.com/prabirshrestha/vim-lsp
" Display diagnostics as a floating window
let g:lsp_diagnostics_float_cursor = 1
" Disable floating preview of documentation in completion menu (it
" ignores the `preview` option in `completeopt`.
let g:lsp_documentation_float = 0
" Align text on top when peeking on window
let g:lsp_peek_alignment = "top"
" Give priority to other gutters (e.g., GitGutter)
let g:lsp_signs_priority = 9
" Set custom diagnostic signs
"let g:lsp_signs_error = {'text': '•'}
"let g:lsp_signs_warning = {'text': '•'}
"let g:lsp_signs_information = {'text': '•'}
"let g:lsp_signs_hit = {'text': '•'}
let g:lsp_signs_error = {'text': '>>'}
let g:lsp_signs_warning = {'text': '>>'}
let g:lsp_signs_information = {'text': '>>'}
let g:lsp_signs_hit = {'text': '>>'}
" Closes the preview/floating window on second tap
let g:lsp_preview_doubletap = [function('lsp#ui#vim#output#closepreview')]
" Log file (uncomment when debugging)
"let g:lsp_log_file = expand('$TMPDIR/vim-lsp.log')
" Rust Language Server registration
if executable('rls')
autocmd User lsp_setup call lsp#register_server({
\ 'name': 'rls',
\ 'cmd': {server_info->['rls']},
\ 'workspace_config': {'rust': {'clippy_preference': 'on'}},
\ 'allowlist': ['rust'],
\ })
endif
" Scala Meta Language Server registration
" Take a look here
"
" https://scalameta.org/metals/docs/editors/vim.html#using-an-alternative-lsp-client
"
" for details on how to install MetaLS
"
" Import build with the following command:
"
" :call lsp#send_request('metals', { 'method': 'workspace/executeCommand', 'params': { 'command': 'build-import' }})
"
" Formatting on save needs some additional configuration. MetaLS uses
" `scalafmt` to format code. Have a look here
"
" https://scalameta.org/metals/docs/editors/new-editor.html#textdocumentformatting
"
" for details of what MetaLS does when receiving a
" `textDocument/formatting` message.
"
" To configure it manually you need to create a `.scalafmt.conf` file
" (in the project root by default, but customizable with the
" `metals.scalafmtConfigPath` option) and with the following content:
"
" ```
" version="<version>"
" ```
" with <version> being the ScalaFMT to use for the project (latest
" version can be found at https://github.com/scalameta/scalafmt).
"
if executable('metals-vim')
au User lsp_setup call lsp#register_server({
\ 'name': 'metals',
\ 'cmd': {server_info->['metals-vim']},
\ 'initialization_options': { 'rootPatterns': 'build.sbt' },
\ 'allowlist': [ 'scala', 'sbt' ],
\ })
endif
function! s:on_lsp_buffer_enabled() abort
" Enable autocompletion (Omnifunc vs asyncomplete.vim
"setlocal omnifunc=lsp#complete
"let b:asyncomplete_enable = 1
" Enable docs on preview window. For more details look at
" https://github.com/prabirshrestha/asyncomplete.vim#preview-window
setlocal completeopt=menuone,noinsert,noselect,preview
" Show gutters only when needed
setlocal signcolumn=number
" Integrate tag functionality with vim-lsp
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
" Mappings
nmap <buffer> <leader>nc <plug>(lsp-next-diagnostic)
nmap <buffer> <leader>pc <plug>(lsp-previous-diagnostic)
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gD <plug>(lsp-peek-definition)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> K <plug>(lsp-hover)
"nmap <buffer> gi <plug>(lsp-implementation)
"nmap <buffer> gt <plug>(lsp-type-definition)
"nmap <buffer> <leader>rn <plug>(lsp-rename)
"nmap <buffer> [g <Plug>(lsp-previous-diagnostic)
"nmap <buffer> ]g <Plug>(lsp-next-diagnostic)
" Format buffer on save
"augroup lsp_enabled_common
" autocmd!
autocmd BufWritePre <buffer> silent LspDocumentFormatSync
"augroup END
"command LspMetalsBuildImport call lsp#send_request('metals', { 'method': 'workspace/executeCommand', 'params': { 'command': 'build-import' }})
endfunction
augroup lsp_install
autocmd!
" Call `s:on_lsp_buffer_enabled()` only for languages that has the
" server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" {{{2 ASYNCOMPLETE.VIM
" https://github.com/prabirshrestha/asyncomplete.vim
" Disable asynccomplete by default (re-enabled when using LSP)
"let g:asyncomplete_enable_for_all = 0
" Do not override `completeopt`
let g:asyncomplete_auto_completeopt = 0
" Add some delay on completion popup
let g:asyncomplete_popup_delay = 500
" Log file (uncomment when debugging)
"let g:asyncomplete_log_file = expand('$TMPDIR/vim-asyncomplete.log')
" {{{2 ASYNCOMPLETE-LSP.VIM
" https://github.com/prabirshrestha/asyncomplete-lsp.vim
" {{{2 VIM-GRAMMAROUS
" https://github.com/rhysd/vim-grammarous
" Manually downloaded Language Tools from
" https://languagetool.org/download/LanguageTool-stable.zip
let g:grammarous#jar_dir = expand('$HOME/programs/LanguageTool-5.3')
" Seems to slow things down a lot and give more false positive in TeX
let g:grammarous#use_vim_spelllang = 0
" Don't perform spell check (toggled by hooks instead)
let g:grammarous#enable_spell_check = 0
" Change colorscheme and toggle Vim spellcheck functionality.
let g:grammarous#hooks = #{on_check: 'dyamon#spell#on', on_reset: 'dyamon#spell#off'}
" {{{2 TO TRY
" Vim: statically built version of Vim.
" https://github.com/fr0xk/vim
" FastFold: some fixes for fold updates.
" https://github.com/Konfekt/FastFold
" Vimtex: full-featured Latex support for Vim (also integrates with
" Zathura). Not compatible with Polyglot (which includes
" LaTeX-Box).
" https://github.com/lervag/vimtex
"
" Consider not using a plugin at all:
" + Compilation via `:make` with
" set makeprg=latexmk\ -pdf\ ...
" + Zathura automatically updates its view;
" + Clean up all regeneratable files on Vim closing:
" autocmd VimLeave *.tex !latexmk -c
" + `g/\v\\(chapter|(sub)?section)/#<CR>:` map this to see the document
" structure and quickly jump to through the document;
" + you can borrow some mappings/folding/completion/error parsing
" configurations from Vimtex.
" MuComplete: omnicomplete wrapper (might be a good alternative to
" full-featured autocompletion engines)
" https://github.com/lifepillar/vim-mucomplete
" Wordy: writing checker (not grammar checker).
" https://github.com/reedes/vim-wordy
" Polyglot: mega-pack of syntax/indent/autoload/compiler/ftplugin for
" various languages.
" https://github.com/sheerun/vim-polyglot
" Pencil: might provide a better soft wrap feature than vanilla?
" https://github.com/reedes/vim-pencil
" Remark: write presentations in markdown and use JavaScript to display
" them on your browser (supports presentation mode). Can be used
" offline.
" https://www.reddit.com/r/vim/comments/9bw6cp/turn_markdown_into_selfcontained_html_slideshows/
" https://github.com/gnab/remark
" https://github.com/idbrii/vim-remarkjs
" https://en.wikipedia.org/wiki/Takahashi_method
" Qfx: quickfix gutter
" https://gitlab.com/hauleth/qfx.vim
" Boxdraw: draw boxes in visual mode (quite advanced).
" https://github.com/gyim/vim-boxdraw
" Cool: enable `hlsearch` when searching, disable it when you are not.
" https://github.com/romainl/vim-cool/blob/master/plugin/cool.vim
" Dadbod: use Vim as a DBMS IDE
" https://github.com/tpope/vim-dadbod
" https://medium.com/@sammerry/vim-mysql-442b26dd013c
" MatchUp: drop-in replacement end extention for matchit.vim
" https://github.com/andymass/vim-matchup/
" HighlightedYank: briefly highlight the highlighted text on
" TextYankPost. Note that NeoVim has not a Lua function that does the
" same [here](https://github.com/neovim/neovim/pull/12279), so maybe it
" is worth waiting for Vim to implement it too.
" https://github.com/machakann/vim-highlightedyank
" VimQF: is a growing collection of settings, commands and mappings put
" together to make working with the location list/window and the
" quickfix list/window smoother.
" https://github.com/romainl/vim-qf
" {{{3 ALIGNING
" Tabular: Easily align text.
" https://github.com/godlygeek/tabular
" EasyAlign: Easily align text (action bound to `ga`)
" https://github.com/junegunn/vim-easy-align
" {{{3 TEXTOBJS
" IndentObject: a text-object based on the indentation level.
" https://github.com/michaeljsmith/vim-indent-object
" TextobjFunction: a text-object for {C,Java,VimScript} functions. Can
" be extended to include other languages.
" https://github.com/kana/vim-textobj-function
" Targets: collection of (immersive) text-objects
" https://github.com/wellle/targets.vim
" TextobjUser: declarative way of defining text-objects
" https://github.com/kana/vim-textobj-user
" {{{1 DEBUG
" Automatically create .gitignore based on given keywords
" https://www.toptal.com/developers/gitignore/api/linux,vim,rust
command! -nargs=1 GetGitignore execute "!curl https://www.toptal.com/developers/gitignore/api/linux,macos,vim,visualstudiocode," . <args> . " > .gitignore"
let g:rust_fold = 1
let g:rustfmt_command = 'rustfmt'
" https://vimways.org/2019/personal-notetaking-in-vim/
" A neat trick is <bang>0 in function arguments: this turns either to 0
" without a bang or 1 with
command! -bang -nargs=+ Zettel call Zettel(<bang>0, <f-args>)
func! Zettel(bang, ...)
" change directory
exec "cd " . expand('$NOTES')
" build the file name
let l:timestamp = strftime("%Y%m%d%H%M")
let l:fname = l:timestamp . '.md'
if a:bang
exec "normal a[" . l:timestamp . "](" . l:fname . ")"
endif
" edit the new file
exec "e " . l:fname
" Fill in the title
exec "normal :1,5s/^title:.*$/title: " . l:timestamp . " - " . join(a:000) . "/\<cr>"
endfunc
" {{{1 PLUGIN/RUNTIMEPATH MANAGER
" Source `.local.vim` file in the current working directory. Create this
" file if you want to have some project-specific vim configuration.
silent! source .local.vim
" Plugins code will be evaluated.
" If you want something to be evaluated after this point use the `after`
" folder. See `:scriptnames` for a list of all scripts, in evaluation
" order. Launch Vim with `vim --startuptime vim.log` for profiling info.
if &loadplugins
if has('packages')
" If Vim8 plugin/runtimepath manager is active.
packadd vim-openscad
packadd! gruvbox
packadd! fzf.vim
packadd! goyo.vim
packadd! matchit
packadd! mortimer.vim
packadd! tagbar
packadd! undotree
packadd! vim-bbye
packadd! vim-commentary
packadd! vim-fugitive
packadd! vim-gitgutter
packadd! vim-obsession
packadd! vim-racket
packadd! vim-repeat
packadd! vim-slime
packadd! vim-surround
packadd! vim-tmux-focus-events
packadd! vim-tmux-navigator
packadd! vim-vinegar
packadd! vim-lsp
packadd! vimprobably
packadd! asyncomplete.vim
packadd! asyncomplete-lsp.vim
else
" Fall back to TPope's Pathogen plugin manager.
source $HOME/.vim/pack/bundle/opt/vim-pathogen/autoload/pathogen.vim
call pathogen#infect('pack/bundle/opt/{}')
endif
endif
" Must come *after* the `:packadd!` calls above otherwise the contents of
" package "ftdetect" directories won't be evaluated.
" Activate filetype support, and allow filetype specific plugin and
" indent files.
filetype plugin indent on
" Enable syntax highlight by default.
syntax enable
" {{{1 END
" Ignore anything after this point
finish
|