Robert Cranston authored on 30/11/2022 22:55:45
Showing 1 changed files

... ...
@@ -4,47 +4,45 @@
4 4
 
5 5
 """ Comments
6 6
 
7
-" Comments are written in Vim's help |notation|, see |help-writing|, which can
8
-" be highlighted with
9
-" https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-comment.
7
+" Comments are written in Vim's help |notation|, see |help-writing|. They can
8
+" be highlighted with https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-comment.
10 9
 
11
-" Section headings are not written in |notation|, but are instead indicated
12
-" with multiple comment characters, which can form folds with
13
-" https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-fold.
10
+" Section headings are not written in the help |notation|, but are instead
11
+" indicated with multiple contiguous comment characters. They can form folds
12
+" with https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-fold.
14 13
 
15 14
 """ Compatibility
16 15
 
17 16
 " This vimrc should work with all configurations of Vim. Manually tested with:
18 17
 " - Features: tiny, huge (Debian `apt-get install vim-{tiny,gtk3}`)
19
-" - Encodings/Locales: C, UTF-8 (`LC_ALL=C{,.UFT-8}`)
20
-" - Colors: 1, 2, 8, 16, 256, termguicolors (`--cmd "set t_Co=$colors"`)
18
+" - Locales: C, UTF-8 (`LC_ALL=C{,.UFT-8}`)
19
+" - Colors: 1, 2, 8, 16, 256, termguicolors (`--cmd "set {t_Co=$colors,tgc}"`)
20
+" - UI: TUI, GUI (`{,g}vim`)
21 21
 " - Terminals: GUI, VTE, Linux, tmux with the correct `Ss` `terminal-override`
22
-" - Platforms: Linux
22
+" - Platforms: Unix-like
23 23
 
24 24
 """ Features
25 25
 
26 26
 " |:version| says "tiny" features are always present and are therefore used in
27
-" favor of more advanced features whenever possible. "Tiny" features include:
27
+" favor other features whenever possible. "Tiny" features include:
28 28
 " - |+multi_byte|
29 29
 " - |+mouse|
30 30
 " - |+tag_binary|
31 31
 " - |+user_commands|
32 32
 " - |+autocmd|
33 33
 " - |+localmap|
34
-" Important features that are only present in "normal":
35
-" - |+eval|
36 34
 
37
-" Note that trying to set unsupported options is silently ignored, and so can
38
-" be done without checking for support first (which is good, since that
39
-" requires |+eval|). Everything between |:if| and |:endif| is also silently
40
-" ignored if |+eval| is not available.
35
+" Note that trying to set (run-time, but not compile-time) unsupported options
36
+" is silently ignored, and so can be done without checking for support first
37
+" (which is good, since that requires |+eval|). Everything between |:if| and
38
+" |:endif| is also silently ignored if |+eval| is not available.
41 39
 
42 40
 """ Encoding
43 41
 
44 42
 " |'encoding'| is hard-coded to `utf-8`. However, only characters present in
45 43
 " Code Page 437 should be used in the interface, to ensure font support on most
46 44
 " terminals (in particular, the Linux console). See
47
-" - https://en.wikipedia.org/wiki/Code_page_347
45
+" - https://en.wikipedia.org/wiki/Code_page_437
48 46
 " - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/tty/vt/cp437.uni
49 47
 " - `man showconsolefont`
50 48
 
... ...
@@ -53,19 +51,21 @@
53 51
 " |setglobal| is used where appropriate so that buffer/window-local options are
54 52
 " not overridden when re-sourcing.
55 53
 
56
-" At the time of writing, |augroup| messes up the highlighting of |autocmd|s
57
-" within it, so the `vimrc` group name is added to every |autocmd| instead (the
58
-" addition of the group of course makes the highlighting misinterpret it as the
54
+" A `vimrc` |augroup| is cleared and used for all |autocmd|s. At the time of
55
+" writing, |augroup| messes up the highlighting of |autocmd|s within it, so the
56
+" `vimrc` group name is added to every |autocmd| instead (the addition of the
57
+" group of course makes the highlighting misinterpret it as the
59 58
 " `vimAutoEventList` and the events instead get the erroneous
60
-" `VimAutoCmdSfxList`... file a bug?). This can be checked with `:g/autocmd`.
59
+" `VimAutoCmdSfxList` highlighting... file a bug?). This can be checked with
60
+" `:g/autocmd`.
61 61
 
62 62
 """ Mappings
63 63
 
64 64
 " Don't make any built-in mappings do something completely different! Another
65 65
 " Vimmer should never be surprised by what happens, unless it is pleasantly
66
-" because the functionality is extended in useful and obvious ways. This
67
-" includes mappings from popular plugins, for which the defaults should be kept
68
-" as far as possible.
66
+" surprised because the functionality is extended in useful and obvious ways.
67
+" This includes mappings from popular plugins, for which the defaults should be
68
+" kept as far as possible.
69 69
 
70 70
 " |<Leader>| is hard-coded to <Space> so that mappings work without |+eval|.
71 71
 " Setting |mapleader| to a different value after the mappings have been defined
... ...
@@ -123,7 +123,7 @@ set showbreak=»\ |
123 123
 if has('gui_running')
124 124
   set t_Co=16777216
125 125
 endif
126
-if 16 <= &t_Co && &t_Co <= 256
126
+if 16 <= &t_Co && &t_Co <= 256 && !&termguicolors
127 127
   set t_Co=16
128 128
 endif
129 129
 
... ...
@@ -143,7 +143,7 @@ set mouse=a
143 143
 """ Command-line
144 144
 set wildmenu
145 145
 set wildmode=longest:full,full
146
-set wildignore=_*,.git,.cache,.vagrant,.ansible,.npm,node_modules,pipx,snap
146
+set wildignore=_*,.git,.cache,.vagrant,.ansible,.npm,node_modules,__pycache__,.venv,*.egg-info,pipx,snap
147 147
 if has('patch-8.2.4325')
148 148
   " See http://ftp.vim.org/pub/vim/patches/8.2/8.2.4325.
149 149
   set wildoptions+=pum
... ...
@@ -172,6 +172,7 @@ endif
172 172
 """ Formatting
173 173
 " See |auto-format|, |format-comments|, and |fo-table|.
174 174
 set textwidth=79
175
+set winwidth=80
175 176
 " set colorcolumn=+1
176 177
 set autoindent
177 178
 set nojoinspaces
... ...
@@ -187,24 +188,29 @@ set commentstring=
187 188
 """ Folds
188 189
 set foldlevelstart=999
189 190
 set foldtext=substitute(getline(v:foldstart),'\\t',repeat('\ ',&ts),'g').'\ '
190
-if has('eval')
191
-  set foldtext=unobtrusive_fold#text()
192
-endif
193 191
 
194 192
 """ Spelling
195 193
 set spell
196 194
 set spelllang=en_us
197
-if has('eval')
198
-  " Files downloaded from URL documented in |'thesaurus'|:
199
-  " https://github.com/vim/vim/issues/629#issuecomment-443293282.
200
-  let &thesaurus = split(&runtimepath, ',')[0] . '/thesaurus/en_us.txt'
201
-endif
195
+" `thesaurus/en_us.txt` downloaded from URL documented in |'thesaurus'|:
196
+" https://github.com/vim/vim/issues/629#issuecomment-443293282.
197
+set thesaurus=~/.vim/thesaurus/en_us.txt
202 198
 
203 199
 """ Views
204 200
 set viewoptions-=options
205 201
 set viewoptions+=slash
206 202
 set viewoptions+=unix
207 203
 
204
+""" Files
205
+set swapfile
206
+set writebackup
207
+set undofile
208
+set directory=~/.cache/vim/swap//
209
+set backupdir=~/.cache/vim/backup//
210
+set undodir=~/.cache/vim/undo//
211
+set viewdir=~/.cache/vim/view//
212
+set viminfofile=~/.cache/vim/viminfo
213
+
208 214
 "" Mappings
209 215
 
210 216
 """ Escape
... ...
@@ -224,13 +230,13 @@ tnoremap <C-K> <C-W>k
224 230
 tnoremap <C-L> <C-W>l
225 231
 
226 232
 """ Buffers
227
-nnoremap <Space>bb :ls<CR>:b<Space>
228
-nnoremap <Space>bs :ls<CR>:sb<Space>
229
-nnoremap <Space>bv :ls<CR>:vertical sb<Space>
233
+nnoremap <Space><Space>bb :ls<CR>:b<Space>
234
+nnoremap <Space><Space>bs :ls<CR>:sb<Space>
235
+nnoremap <Space><Space>bv :ls<CR>:vertical sb<Space>
230 236
 
231 237
 """ `$MYVIMRC`
232
-nnoremap <silent> <Space>ve :edit   $MYVIMRC<CR>
233
-nnoremap <silent> <Space>vs :source $MYVIMRC<CR>
238
+nnoremap <silent> <Space><Space>ve :edit   $MYVIMRC<CR>
239
+nnoremap <silent> <Space><Space>vs :source $MYVIMRC<CR>
234 240
 
235 241
 """ Help
236 242
 nnoremap <silent> gK  :helpgrep \<<C-R><C-W>\><CR>
... ...
@@ -239,29 +245,30 @@ xnoremap <silent> gK y:helpgrep <C-R>"<CR>
239 245
 """ Run
240 246
 
241 247
 " File.
242
-nnoremap <silent> <Space>% :!%:p:S<CR>
243
-nnoremap <silent> <Space># :!#:p:S<CR>
248
+nnoremap <silent> <Space><Space>% :!%:p:S<CR>
249
+nnoremap <silent> <Space><Space># :!#:p:S<CR>
244 250
 
245 251
 " Command.
246
-nnoremap <Space>! :new \| .!
252
+nnoremap <Space><Space>! :new \| .!
247 253
 
248 254
 """ Make
249 255
 " TODO: |dispatch| provides default mappings, try to emulate them?
250
-nnoremap <Space>m% :!make %:r:S<CR>
251
-nnoremap <Space>m# :!make #:r:S<CR>
252
-nnoremap <Space>mm :!make<CR>
253
-nnoremap <Space>ma :!make all<CR>
254
-nnoremap <Space>mt :!make test<CR>
255
-nnoremap <Space>md :!make debug<CR>
256
+" TODO: Should these be <silent> as well?
257
+nnoremap <Space><Space>m% :!make %:r:S<CR>
258
+nnoremap <Space><Space>m# :!make #:r:S<CR>
259
+nnoremap <Space><Space>mm :!make<CR>
260
+nnoremap <Space><Space>ma :!make all<CR>
261
+nnoremap <Space><Space>mt :!make test<CR>
262
+nnoremap <Space><Space>md :!make debug<CR>
256 263
 if has('quickfix')
257
-  nnoremap <Space>m% :silent make! %:r:S \| redraw!<CR>
258
-  nnoremap <Space>m# :silent make! #:r:S \| redraw!<CR>
259
-  nnoremap <Space>mm :silent make!       \| redraw!<CR>
260
-  nnoremap <Space>ma :silent make! all   \| redraw!<CR>
261
-  nnoremap <Space>mt :silent make! test  \| redraw!<CR>
264
+  nnoremap <Space><Space>m% :silent make! %:r:S \| redraw!<CR>
265
+  nnoremap <Space><Space>m# :silent make! #:r:S \| redraw!<CR>
266
+  nnoremap <Space><Space>mm :silent make!       \| redraw!<CR>
267
+  nnoremap <Space><Space>ma :silent make! all   \| redraw!<CR>
268
+  nnoremap <Space><Space>mt :silent make! test  \| redraw!<CR>
262 269
 endif
263 270
 if has('terminal')
264
-  nnoremap <Space>md :terminal make debug<CR>
271
+  nnoremap <Space><Space>md :terminal make debug<CR>
265 272
 endif
266 273
 
267 274
 """ Improve default mappings
... ...
@@ -325,7 +332,7 @@ endif
325 332
 """ Diffs
326 333
 
327 334
 " Current file.
328
-nnoremap <silent> <Space>dd :w !diff --color -u %:S -<CR>
335
+nnoremap <silent> <Space><Space>dd :w !diff --color -u %:S -<CR>
329 336
 
330 337
 " Analogous with |dp| |do| in Normal mode.
331 338
 nnoremap <silent> <Space>dpp :.diffput<CR>
... ...
@@ -357,8 +364,8 @@ nnoremap zV zMzv
357 364
 
358 365
 " Focus next/previous fold. Overwrites default move to start/end of
359 366
 " next/previous fold.
360
-nnoremap zj zvm<zjzvm>gvzc'>zv
361
-nnoremap zk zvzcVoVgkzvgkzvzcVoVzv
367
+nnoremap <silent> zj m<zjzvm>gvzc'>zv
368
+nnoremap <silent> zk zvzckVzvV:<C-R>=prevnonblank(line('.'))<CR><CR>zvzcVoVzv
362 369
 
363 370
 " Open/close nested folds recursively. Overwrites default open/close fold under
364 371
 " cursor recursively.
... ...
@@ -468,10 +475,6 @@ autocmd vimrc VimEnter,ColorScheme,OptionSet *
468 475
 \ highlight! SpellCap         term=NONE cterm=NONE gui=NONE ctermbg=NONE guibg=NONE ctermfg=LightRed guifg=LightRed |
469 476
 \ highlight! Todo             term=bold cterm=bold gui=NONE ctermbg=NONE guibg=NONE ctermfg=White    guifg=White    |
470 477
 
471
-"""" Comments
472
-autocmd vimrc VimEnter,ColorScheme,OptionSet *
473
-\ highlight! Comment guifg=#919191 ctermfg=Grey
474
-
475 478
 """" Diffs
476 479
 autocmd vimrc VimEnter,ColorScheme,OptionSet *
477 480
 \ highlight! DiffAdd          term=NONE cterm=NONE gui=NONE ctermfg=Black guifg=Black ctermbg=DarkGreen  guibg=Green  |
... ...
@@ -481,6 +484,10 @@ autocmd vimrc VimEnter,ColorScheme,OptionSet *
481 484
 \ highlight! diffAdded        term=NONE cterm=NONE gui=NONE ctermbg=NONE  guibg=NONE  ctermfg=DarkGreen  guifg=Green  |
482 485
 \ highlight! diffRemoved      term=NONE cterm=NONE gui=NONE ctermbg=NONE  guibg=NONE  ctermfg=DarkRed    guifg=Red    |
483 486
 
487
+"""" Comments
488
+autocmd vimrc VimEnter,ColorScheme,OptionSet *
489
+\ highlight! Comment guifg=#919191 ctermfg=Grey
490
+
484 491
 """" Folds
485 492
 autocmd vimrc VimEnter,ColorScheme,OptionSet *
486 493
 \ highlight! link Folded Comment |
... ...
@@ -667,6 +674,7 @@ if has('eval')
667 674
   GitAdd https://github.com/tommcdo/vim-exchange
668 675
 
669 676
   """" `qstrahl/vim-dentures`
677
+  " TODO: I'm not happy with this, replace.
670 678
   GitAdd https://github.com/qstrahl/vim-dentures
671 679
 
672 680
   """" `kana/vim-textobj-user`
... ...
@@ -735,12 +743,19 @@ if has('eval')
735 743
   """" `rcrnstn/vim-unobtrusive-fold`
736 744
   GitAdd https://git.rcrnstn.net/rcrnstn/vim-unobtrusive-fold
737 745
 
746
+  " As suggested in |unobtrusive_fold#text()|.
747
+  set foldtext=unobtrusive_fold#text()
748
+
749
+  " As suggested in |unobtrusive-fold-example|.
750
+  autocmd vimrc FileType *        UnobtrusiveFoldComment
751
+  autocmd vimrc FileType markdown UnobtrusiveFoldChar #
752
+
738 753
   """ Undo
739 754
 
740 755
   """" `mbbill/undotree`
741 756
   GitAdd https://github.com/mbbill/undotree
742 757
 
743
-  nnoremap <silent> <Space>u :UndotreeToggle<CR>
758
+  nnoremap <silent> <Space><Space>u :UndotreeToggle<CR>
744 759
 
745 760
   " let g:undotree_HighlightChangedText = 0
746 761
   " let g:undotree_DiffCommand = 'diff -u'
... ...
@@ -786,22 +801,22 @@ if has('eval')
786 801
   if has('unix')
787 802
     " TODO: Set `grepprg` to something similar, that skips things in
788 803
     " 'wildignore'.
789
-    " let g:ctrlp_user_command = 'find' .
790
-    " \ (g:ctrlp_follow_symlinks ? ' -L' : '') .
791
-    " \ ' %s' .
792
-    " \ ' -maxdepth ' . g:ctrlp_max_depth .
793
-    " \ ' \( -false' .
794
-    " \ (g:ctrlp_show_hidden ? '' : ' -o -name ".*"') .
795
-    " \ ' ' .
796
-    " \ join(map(split(&wildignore, ','), '"-o -name " . shellescape(v:val)')) .
797
-    " \ ' \) -prune -o' .
798
-    " \ ' -type f' .
804
+    let g:ctrlp_user_command = 'find' .
805
+    \ (g:ctrlp_follow_symlinks ? ' -L' : '') .
806
+    \ ' %s' .
807
+    \ ' -maxdepth ' . g:ctrlp_max_depth .
808
+    \ ' \( -false' .
809
+    \ (g:ctrlp_show_hidden ? '' : ' -o -name ".*"') .
810
+    \ ' ' .
811
+    \ join(map(split(&wildignore, ','), '"-o -name " . shellescape(v:val)')) .
812
+    \ ' \) -prune -o' .
813
+    \ ' -type f' .
814
+    \ ' 2> /dev/null' .
815
+    \ (g:ctrlp_max_files ? ' | head -n ' . g:ctrlp_max_files : '')
799 816
     " \ ' -exec grep -Il . {} +' .
800
-    " \ ' 2> /dev/null' .
801
-    " \ (g:ctrlp_max_files ? ' | head -n ' . g:ctrlp_max_files : '')
802
-    " " \ ' \(' .
803
-    " " \ (g:ctrlp_follow_symlinks == 2 ? ' -o -type l' : '') .
804
-    " " \ ' \)' .
817
+    " \ ' \(' .
818
+    " \ (g:ctrlp_follow_symlinks == 2 ? ' -o -type l' : '') .
819
+    " \ ' \)' .
805 820
   endif
806 821
 
807 822
   """" `tpope/vim-fugitive`
... ...
@@ -812,14 +827,18 @@ if has('eval')
812 827
   """" `tommcdo/vim-fugitive-blame-ext`
813 828
   GitAdd https://github.com/tommcdo/vim-fugitive-blame-ext
814 829
 
830
+  """" `iberianpig/tig-explorer.vim`
831
+  " GitAdd https://github.com/iberianpig/tig-explorer.vim
832
+
815 833
   """" `tpope/vim-dispatch`
816 834
   GitAdd https://github.com/tpope/vim-dispatch
817 835
 
818
-  nnoremap <Space>m% :Make %:r:S<CR>
819
-  nnoremap <Space>m# :Make #:r:S<CR>
820
-  nnoremap <Space>mm :Make<CR>
821
-  nnoremap <Space>ma :Make all<CR>
822
-  nnoremap <Space>mt :Make test<CR>
836
+  " TODO: Stick to the default mappings.
837
+  nnoremap <Space><Space>m% :Make %:r:S<CR>
838
+  nnoremap <Space><Space>m# :Make #:r:S<CR>
839
+  nnoremap <Space><Space>mm :Make<CR>
840
+  nnoremap <Space><Space>ma :Make all<CR>
841
+  nnoremap <Space><Space>mt :Make test<CR>
823 842
 
824 843
   """" `tpope/vim-eunuch`
825 844
   GitAdd https://github.com/tpope/vim-eunuch
... ...
@@ -841,7 +860,7 @@ if has('eval')
841 860
   " Common DeBugGer Protocol (DBGP) client. See
842 861
   " https://en.wikipedia.org/wiki/DBGp.
843 862
 
844
-endif " has('eval')
863
+endif "" has('eval')
845 864
 
846 865
 "" Syntax and file type
847 866
 if has('eval')
... ...
@@ -863,17 +882,24 @@ autocmd vimrc FileType man
863 882
 autocmd vimrc FileType c,cpp
864 883
 \ setlocal commentstring=//\ %s
865 884
 
885
+autocmd vimrc FileType dot
886
+\ setlocal commentstring=//\ %s
887
+
888
+autocmd vimrc FileType markdown
889
+\ setlocal complete+=kspell
890
+
891
+autocmd vimrc FileType *
892
+\ if &buftype ==# 'nowrite' |
893
+\   setlocal nospell nolist |
894
+\ endif |
895
+
866 896
 " As suggested in |ft-syntax-omni|, use syntax completion if no other
867 897
 " completion has been defined.
868 898
 autocmd vimrc FileType *
869
-\ if &omnifunc == '' |
899
+\ if &omnifunc ==# '' |
870 900
 \   setlocal omnifunc=syntaxcomplete#Complete |
871 901
 \ endif |
872 902
 
873
-" As suggested in |unobtrusive-fold-example|.
874
-autocmd vimrc FileType *        UnobtrusiveFoldComment
875
-autocmd vimrc FileType markdown UnobtrusiveFoldChar #
876
-
877 903
 "" Terminal overrides
878 904
 " See |terminal-options|.
879 905