aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim')
-rw-r--r--vim/after/ftplugin/c.vim16
-rw-r--r--vim/after/ftplugin/gitcommit.vim16
-rw-r--r--vim/after/ftplugin/html.vim19
-rw-r--r--vim/after/ftplugin/mail.vim125
-rw-r--r--vim/after/ftplugin/perl.vim19
-rw-r--r--vim/after/ftplugin/php.vim20
-rw-r--r--vim/after/ftplugin/python.vim35
-rw-r--r--vim/after/ftplugin/sh.vim4
-rw-r--r--vim/after/ftplugin/vim.vim10
-rw-r--r--vim/after/ftplugin/zsh.vim4
-rw-r--r--vim/after/indent/awk.vim2
-rw-r--r--vim/after/indent/c.vim4
-rw-r--r--vim/after/indent/css.vim2
-rw-r--r--vim/after/indent/gitconfig.vim6
-rw-r--r--vim/after/indent/html.vim3
-rw-r--r--vim/after/indent/javascript.vim2
-rw-r--r--vim/after/indent/mail.vim2
-rw-r--r--vim/after/indent/make.vim4
-rw-r--r--vim/after/indent/markdown.vim2
-rw-r--r--vim/after/indent/perl.vim2
-rw-r--r--vim/after/indent/php.vim2
-rw-r--r--vim/after/indent/sh.vim2
-rw-r--r--vim/after/indent/vim.vim9
-rw-r--r--vim/after/indent/yaml.vim2
-rw-r--r--vim/after/plugin/2html.vim11
-rw-r--r--vim/after/plugin/dist.vim1
-rw-r--r--vim/after/plugin/insert_cancel.vim4
-rw-r--r--vim/after/plugin/matchparen.vim4
-rw-r--r--vim/after/plugin/spellfile_local.vim13
-rw-r--r--vim/after/plugin/undofileskip.vim7
-rw-r--r--vim/after/syntax/bindzone.vim4
-rw-r--r--vim/after/syntax/mail.vim3
-rw-r--r--vim/after/syntax/resolv.vim6
-rw-r--r--vim/after/syntax/sh.vim12
-rw-r--r--vim/after/syntax/vim.vim6
-rw-r--r--vim/autoload/colorscheme.vim22
-rw-r--r--vim/autoload/diff.vim2
-rw-r--r--vim/autoload/filetype/repeat.vim (renamed from vim/autoload/filetype.vim)6
-rw-r--r--vim/autoload/gitcommit.vim1
-rw-r--r--vim/autoload/html.vim35
-rw-r--r--vim/autoload/html/timestamp.vim74
-rw-r--r--vim/autoload/html/url.vim15
-rw-r--r--vim/autoload/indent.vim35
-rw-r--r--vim/autoload/mail.vim97
-rw-r--r--vim/autoload/mail/header.vim59
-rw-r--r--vim/autoload/mail/header/field.vim45
-rw-r--r--vim/autoload/mail/importance.vim26
-rw-r--r--vim/autoload/markdown.vim34
-rw-r--r--vim/autoload/option.vim17
-rw-r--r--vim/autoload/option/item.vim14
-rw-r--r--vim/autoload/paste_insert.vim12
-rw-r--r--vim/autoload/patch.vim35
-rw-r--r--vim/autoload/quote.vim4
-rw-r--r--vim/autoload/reload.vim16
-rw-r--r--vim/autoload/spellfile_local.vim11
-rw-r--r--vim/autoload/utc.vim4
-rw-r--r--vim/autoload/xdg.vim67
m---------vim/bundle/alternate_filetypes0
m---------vim/bundle/copy_linebreak0
m---------vim/bundle/cursorline_current0
m---------vim/bundle/detect_indent0
m---------vim/bundle/digraph_search0
m---------vim/bundle/html_spelllang0
m---------vim/bundle/paste_insert0
m---------vim/bundle/put_date0
m---------vim/bundle/quickfix_auto_open0
m---------vim/bundle/redact_pass0
m---------vim/bundle/scratch_buffer0
m---------vim/bundle/select_old_files0
m---------vim/bundle/spellfile_local0
m---------vim/bundle/squeeze_repeat_blanks0
m---------vim/bundle/strip_trailing_whitespace0
m---------vim/bundle/undofileskip0
m---------vim/bundle/write_mkpath0
-rw-r--r--vim/compiler/pyflakes.vim9
-rw-r--r--vim/compiler/pylint.vim9
-rw-r--r--vim/filetype.vim229
-rw-r--r--vim/ftplugin/awk.vim4
-rw-r--r--vim/ftplugin/csv.vim2
-rw-r--r--vim/ftplugin/mail.vim15
-rw-r--r--vim/ftplugin/markdown.vim29
-rw-r--r--vim/ftplugin/sed.vim4
-rw-r--r--vim/ftplugin/textarea.vim10
-rw-r--r--vim/indent/csv.vim15
-rw-r--r--vim/indent/tsv.vim2
-rw-r--r--vim/plugin/dist.vim2
-rw-r--r--vim/plugin/matchit.vim2
-rw-r--r--vim/plugin/paste_insert.vim8
-rw-r--r--vim/plugin/put_date.vim6
-rw-r--r--vim/plugin/spellfile_local.vim19
-rw-r--r--vim/plugin/utc.vim6
-rw-r--r--vim/scripts.vim10
-rw-r--r--vim/syntax/jinja2.vim2
-rw-r--r--vim/vimrc1267
-rw-r--r--vim/vimrc.stub27
-rw-r--r--vim/vimrc.stub.vim11
96 files changed, 1683 insertions, 1019 deletions
diff --git a/vim/after/ftplugin/c.vim b/vim/after/ftplugin/c.vim
index b5989410..d67e3654 100644
--- a/vim/after/ftplugin/c.vim
+++ b/vim/after/ftplugin/c.vim
@@ -1,14 +1,18 @@
-" Set 'commentstring' and 'include' back to their default C-friendly values
-setlocal commentstring&vim
-setlocal include&vim
+" Set 'commentstring', 'define', and 'include' back to their default
+" C-friendly values
+setlocal commentstring&vim define&vim include&vim
+let b:undo_ftplugin .= '|setlocal commentstring< define< include<'
" Include macros in completion
setlocal complete+=d
+let b:undo_ftplugin .= '|setlocal complete<'
+
+" Fold based on indent level
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
" Include system headers on UNIX
if has('unix')
setlocal path+=/usr/include
+ let b:undo_ftplugin .= '|setlocal path<'
endif
-
-" Undo all of the above
-let b:undo_ftplugin .= '|setlocal commentstring< complete< include< path<'
diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim
index 4a1c3814..093dc5f5 100644
--- a/vim/after/ftplugin/gitcommit.vim
+++ b/vim/after/ftplugin/gitcommit.vim
@@ -4,13 +4,15 @@ setlocal formatoptions+=coqr
let b:undo_ftplugin .= '|setlocal comments< formatoptions<'
" Choose the color column depending on non-comment line count
-augroup gitcommit_cursorcolumn
- autocmd CursorMoved,CursorMovedI <buffer>
- \ let &l:colorcolumn = gitcommit#CursorColumn()
-augroup END
-let b:undo_ftplugin .= '|execute ''autocmd! gitcommit_cursorcolumn'''
- \ . '|augroup! gitcommit_cursorcolumn'
- \ . '|setlocal colorcolumn<'
+if exists('&colorcolumn')
+ augroup gitcommit_cursorcolumn
+ autocmd CursorMoved,CursorMovedI <buffer>
+ \ let &l:colorcolumn = gitcommit#CursorColumn()
+ augroup END
+ let b:undo_ftplugin .= '|execute ''autocmd! gitcommit_cursorcolumn'''
+ \ . '|augroup! gitcommit_cursorcolumn'
+ \ . '|setlocal colorcolumn<'
+endif
" Stop here if the user doesn't want ftplugin mappings
if exists('no_plugin_maps') || exists('no_gitcommit_maps')
diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim
index 93845a80..21a84a42 100644
--- a/vim/after/ftplugin/html.vim
+++ b/vim/after/ftplugin/html.vim
@@ -1,4 +1,10 @@
-" Spellcheck documents we're actually editing (not just viewing)
+" None of this is appropriate for other filetypes that are just sourcing this
+" filetype's scripts in, e.g. Markdown, PHP, so cut that off here
+if &filetype !=# 'html'
+ finish
+endif
+
+" Check the spelling of documents we're actually editing (not just viewing)
if &modifiable && !&readonly
setlocal spell
let b:undo_ftplugin .= '|setlocal spell<'
@@ -13,14 +19,14 @@ let b:undo_ftplugin .= '|unlet b:current_compiler'
" it; we map \= to do the former, but don't actually set 'equalprg' for the
" latter, instead falling back on the good-enough built-in Vim indentation
" behavior
-nnoremap <buffer> <Leader>= :<C-U>call html#TidyBuffer()<CR>
+nnoremap <buffer> <Leader>= :<C-U>call html#Tidy()<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <Leader>='
" Set up hooks for timestamp updating
augroup html_timestamp
autocmd BufWritePre <buffer>
\ if exists('b:html_timestamp_check')
- \| call html#TimestampUpdate()
+ \| call html#timestamp#Update()
\|endif
augroup END
let b:undo_ftplugin .= '|execute ''autocmd! html_timestamp'''
@@ -33,10 +39,5 @@ endif
" Transform URLs to HTML anchors
nnoremap <buffer> <LocalLeader>r
- \ :<C-U>call html#UrlLink()<CR>
+ \ :<C-U>call html#url#Anchor()<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>r'
-
-" Switch to PHP filetype for templated PHP
-nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=php<CR>
-let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>f'
diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim
index f4a4c91d..4c07bac3 100644
--- a/vim/after/ftplugin/mail.vim
+++ b/vim/after/ftplugin/mail.vim
@@ -1,86 +1,31 @@
+" Restore global value for no_mail_maps that we set in
+" ~/.vim/ftplugin/mail.vim to work around the bad maps set in
+" $VIMRUNTIME/ftplugin/mail.vim
+"
+if exists('b:no_mail_maps')
+ let no_mail_maps = b:no_mail_maps
+elseif exists('no_mail_maps')
+ unlet no_mail_maps
+endif
+
" Don't append spaces after quote chars, for strict compliance with
" format=flowed
let b:quote_space = 0
let b:undo_ftplugin .= '|unlet b:quote_space'
-" If something hasn't already moved the cursor, we'll move to an optimal point
-" to start writing
-function! s:SuggestStart() abort
-
- " Move to top of buffer
- call setpos('.', [0, 1, 1, 0])
-
- " Move to body text
- call search('\m^$', 'c') | +
-
- " Start by trying to move to the first quoted line; this may fail if there's
- " no quote, which is fine
- call search('\m^>', 'c')
-
- " Delete quoted blank lines or quoted greetings until we get to something
- " with substance. Yes, I like Perl, how could you tell?
- while getline('.') =~? '^> *'
- \ . '\%('
- \ . '\%('
- \ . 'g[''\u2019]\=day'
- \ . '\|\%(good \)\=\%(morning\|afternoon\|evening\)'
- \ . '\|h[eu]\%(ll\|rr\)o\+'
- \ . '\|hey\+'
- \ . '\|hi\+'
- \ . '\|sup'
- \ . '\|what[''\u2019]\=s up'
- \ . '\|yo'
- \ . '\)'
- \ . '[[:punct:] ]*'
- \ . '\%('
- \ . '\a\+'
- \ . '[[:punct:] ]*'
- \ . '\)\='
- \ . '\)\=$'
- delete
- endwhile
-
- " Now move to the first quoted or unquoted blank line
- call search('\m^>\= *$', 'c')
-endfunction
-command! -bar -buffer SuggestStart
- \ call s:SuggestStart()
+command -bar -buffer SuggestStart
+ \ call mail#SuggestStart()
let b:undo_ftplugin .= '|delcommand SuggestStart'
SuggestStart
-" Normalise quoting
-function! s:StrictQuote() abort
- let body = 0
- for lnum in range(1, line('$'))
-
- " Get current line
- let line = getline(lnum)
-
- " Skip lines until we hit a blank line, meaning body text
- let body = body || !strlen(line)
- if !body
- continue
- endif
-
- " Get the leading quote string, if any; skip if there isn't one
- let quote = matchstr(line, '^>[> ]*')
- if !strlen(quote)
- continue
- endif
-
- " Normalise the quote with no spaces
- let quote = substitute(quote, '[^>]', '', 'g')
-
- " Re-set the line
- let line = substitute(line, '^[> ]\+', quote, '')
- call setline(lnum, line)
-
- endfor
-endfunction
-command -bar -buffer StrictQuote
- \ call s:StrictQuote()
+" Normalize quoting
+command -bar -buffer -range=% StrictQuote
+ \ call mail#StrictQuote(<q-line1>, <q-line2>)
let b:undo_ftplugin .= '|delcommand StrictQuote'
-StrictQuote
+
+command -bar -buffer -nargs=1 SetImportance
+ \ call mail#importance#Set(<f-args>)
+let b:undo_ftplugin .= '|delcommand SetImportance'
" Add a space to the end of wrapped lines for format-flowed mail
setlocal formatoptions+=w
@@ -88,17 +33,8 @@ let b:undo_ftplugin .= '|setlocal formatoptions<'
" Mail-specific handling for custom vim-squeeze-repeat-blanks plugin
if exists('loaded_squeeze_repeat_blanks')
-
- " Set the blank line pattern
let b:squeeze_repeat_blanks_blank = '^[ >]*$'
let b:undo_ftplugin .= '|unlet b:squeeze_repeat_blanks_blank'
-
- " If there is anything quoted in this message (i.e. it looks like a reply),
- " squeeze blanks, but don't report lines deleted
- if search('\m^>', 'cnw')
- silent SqueezeRepeatBlanks
- endif
-
endif
" Spellcheck documents we're actually editing (not just viewing)
@@ -113,12 +49,15 @@ if exists('no_plugin_maps') || exists('no_mail_maps')
endif
" Flag messages as important/unimportant
-nnoremap <buffer> <LocalLeader>h
- \ :<C-U>call mail#FlagImportant()<CR>
-let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>h'
-nnoremap <buffer> <LocalLeader>l
- \ :<C-U>call mail#FlagUnimportant()<CR>
-let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>l'
+nnoremap <buffer> <LocalLeader>ih
+ \ :<C-U>SetImportance high<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>ih'
+nnoremap <buffer> <LocalLeader>il
+ \ :<C-U>SetImportance low<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>il'
+nnoremap <buffer> <LocalLeader>in
+ \ :<C-U>SetImportance normal<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>in'
" Quote operator
nnoremap <buffer> <expr> <LocalLeader>q
@@ -136,6 +75,14 @@ xnoremap <buffer> <expr> <LocalLeader>Q
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q'
\ . '|xunmap <buffer> <LocalLeader>Q'
+" Mappings for enforcing strict quoting
+nnoremap <buffer> <LocalLeader>s
+ \ :StrictQuote<CR>
+xnoremap <buffer> <LocalLeader>s
+ \ :StrictQuote<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>s'
+ \ . '|xunmap <buffer> <LocalLeader>s'
+
" Maps using autoloaded function for quoted paragraph movement
nnoremap <buffer> <silent> <LocalLeader>[
\ :<C-U>call mail#NewBlank(v:count1, 1, 0)<CR>
diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim
index a303fa75..9333e234 100644
--- a/vim/after/ftplugin/perl.vim
+++ b/vim/after/ftplugin/perl.vim
@@ -1,8 +1,15 @@
" Use Perl itself for checking and Perl::Tidy for tidying
compiler perl
-setlocal equalprg=perltidy
let b:undo_ftplugin .= '|unlet b:current_compiler'
- \ . '|setlocal equalprg< errorformat< makeprg<'
+ \ . '|setlocal errorformat< makeprg<'
+if executable('perltidy')
+ setlocal equalprg=perltidy
+ let b:undo_ftplugin .= '|setlocal equalprg<'
+endif
+
+" Fold based on indent level
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
" Add angle brackets to pairs of matched characters for q<...>
setlocal matchpairs+=<:>
@@ -33,6 +40,14 @@ nnoremap <buffer> <LocalLeader>l
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>c'
\ . '|nunmap <buffer> <LocalLeader>l'
+" Mappings to choose 'equalprg'
+nnoremap <buffer> <LocalLeader>t
+ \ :<C-U>setlocal equalprg=perltidy<CR>
+nnoremap <buffer> <LocalLeader>i
+ \ :<C-U>setlocal equalprg<<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>t'
+ \ . '|nunmap <buffer> <LocalLeader>i'
+
" Bump version numbers
nmap <buffer> <LocalLeader>v
\ <Plug>(PerlVersionBumpMinor)
diff --git a/vim/after/ftplugin/php.vim b/vim/after/ftplugin/php.vim
index 58d83c49..b747a14e 100644
--- a/vim/after/ftplugin/php.vim
+++ b/vim/after/ftplugin/php.vim
@@ -2,12 +2,20 @@
compiler php
let b:undo_ftplugin .= '|unlet b:current_compiler'
\ . '|setlocal errorformat< makeprg<'
+if executable('php-cs-fixer')
+ setlocal equalprg=phpcsff
+ let b:undo_ftplugin .= '|setlocal equalprg<'
+endif
" Set comment formats
setlocal comments=s1:/*,m:*,ex:*/,://,:#
setlocal formatoptions+=or
let b:undo_ftplugin .= '|setlocal comments< formatoptions<'
+" Fold based on indent level
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
+
" Use pman as 'keywordprg'
setlocal keywordprg=pman
let b:undo_ftplugin .= '|setlocal keywordprg<'
@@ -16,12 +24,20 @@ let b:undo_ftplugin .= '|setlocal keywordprg<'
let b:regex_escape_flavor = 'ere'
let b:undo_ftplugin .= '|unlet b:regex_escape_flavor'
+" Set HTML as an alternative filetype
+if !exists('b:alternate_filetypes')
+ let b:alternate_filetypes = [&filetype, 'html']
+endif
+
" Stop here if the user doesn't want ftplugin mappings
if exists('no_plugin_maps') || exists('no_php_maps')
finish
endif
-" Switch to HTML filetype for templated PHP
+" Mappings to choose 'equalprg'
nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=html<CR>
+ \ :<C-U>setlocal equalprg=phpcsff<CR>
+nnoremap <buffer> <LocalLeader>i
+ \ :<C-U>setlocal equalprg<<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>f'
+ \ . '|nunmap <buffer> <LocalLeader>i'
diff --git a/vim/after/ftplugin/python.vim b/vim/after/ftplugin/python.vim
new file mode 100644
index 00000000..2ca1ae89
--- /dev/null
+++ b/vim/after/ftplugin/python.vim
@@ -0,0 +1,35 @@
+" The Python runtime files didn't define b:undo_ftplugin until Vim v8.1.1048;
+" if it's not set yet, set it here (to something innoccuous) so that the
+" appending :let commands in the rest of this file don't break.
+"
+if !exists('b:undo_ftplugin')
+ let b:undo_ftplugin = 'setlocal tabstop<'
+endif
+
+" Use pyflakes for syntax checking and autopep8 for tidying
+compiler pyflakes
+if executable('autopep8')
+ setlocal equalprg=autopep8\ -aaa\ --\ -
+ let b:undo_ftplugin .= '|setlocal equalprg<'
+endif
+
+" Stop here if the user doesn't want ftplugin mappings
+if exists('no_plugin_maps') || exists('no_python_maps')
+ finish
+endif
+
+" Mappings to choose compiler
+nnoremap <buffer> <LocalLeader>c
+ \ :<C-U>compiler pyflakes<CR>
+nnoremap <buffer> <LocalLeader>l
+ \ :<C-U>compiler pylint<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>c'
+ \ . '|nunmap <buffer> <LocalLeader>l'
+
+" Mappings to choose 'equalprg'
+nnoremap <buffer> <LocalLeader>t
+ \ :<C-U>setlocal equalprg=autopep8\ -aaa\ --\ -<CR>
+nnoremap <buffer> <LocalLeader>i
+ \ :<C-U>setlocal equalprg<<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>t'
+ \ . '|nunmap <buffer> <LocalLeader>i'
diff --git a/vim/after/ftplugin/sh.vim b/vim/after/ftplugin/sh.vim
index 8468b133..2c68d83a 100644
--- a/vim/after/ftplugin/sh.vim
+++ b/vim/after/ftplugin/sh.vim
@@ -3,6 +3,10 @@ setlocal comments=:#
setlocal formatoptions+=or
let b:undo_ftplugin .= '|setlocal comments< formatoptions<'
+" Fold based on indent level
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
+
" If subtype is Bash, set 'keywordprg' to han(1df)
if exists('b:is_bash')
setlocal keywordprg=han
diff --git a/vim/after/ftplugin/vim.vim b/vim/after/ftplugin/vim.vim
index 30182bba..112523da 100644
--- a/vim/after/ftplugin/vim.vim
+++ b/vim/after/ftplugin/vim.vim
@@ -9,6 +9,10 @@ endif
let b:regex_escape_flavor = 'vim'
let b:undo_ftplugin .= '|unlet b:regex_escape_flavor'
+" Fold based on indent level
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
+
" Use :help as 'keywordprg' if not already set; this is the default since Vim
" v8.1.1290
if &keywordprg !=# ':help'
@@ -22,9 +26,9 @@ let &l:include = '\<source\>\|\<runtime!\=\>'
" Search runtime paths for included scripts
let &l:path = &runtimepath . ',' . &path
-" Adjust the match words for the matchit plugin; the default filetype plugin
-" matches e.g. an opening "function" with the first "return" within, which I
-" don't like
+" Adjust the match words for the matchit.vim plugin; the default filetype
+" plugin matches e.g. an opening "function" with the first "return" within,
+" which I don't like
if exists('loaded_matchit')
let b:match_words = '\<fu\%[nction]\>:\<endf\%[unction]\>,'
\ . '\<\(wh\%[ile]\|for\)\>:\<end\(w\%[hile]\|fo\%[r]\)\>,'
diff --git a/vim/after/ftplugin/zsh.vim b/vim/after/ftplugin/zsh.vim
index 5aa2600a..c361c859 100644
--- a/vim/after/ftplugin/zsh.vim
+++ b/vim/after/ftplugin/zsh.vim
@@ -2,3 +2,7 @@
compiler zsh
let b:undo_ftplugin .= '|unlet b:current_compiler'
\ . '|setlocal errorformat< makeprg<'
+
+" Fold based on indent level, but start with all folds open
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
diff --git a/vim/after/indent/awk.vim b/vim/after/indent/awk.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/awk.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/c.vim b/vim/after/indent/c.vim
new file mode 100644
index 00000000..45db2ebc
--- /dev/null
+++ b/vim/after/indent/c.vim
@@ -0,0 +1,4 @@
+" If the path to the file looks like the Vim sources, set 'shiftwidth' to 4
+if expand('%:p') =~# '/vim.*src/'
+ setlocal shiftwidth=4
+endif
diff --git a/vim/after/indent/css.vim b/vim/after/indent/css.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/css.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/gitconfig.vim b/vim/after/indent/gitconfig.vim
deleted file mode 100644
index 16a948ab..00000000
--- a/vim/after/indent/gitconfig.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-" Use tabs for indent in Git config files, rather than fighting with the
-" frontend tool
-setlocal noexpandtab
-setlocal softtabstop=0
-let &shiftwidth = &tabstop
-let b:undo_indent .= '|setlocal expandtab< softtabstop< shiftwidth<'
diff --git a/vim/after/indent/html.vim b/vim/after/indent/html.vim
index a7a085fe..4cb4a678 100644
--- a/vim/after/indent/html.vim
+++ b/vim/after/indent/html.vim
@@ -1,3 +1,6 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
+
" Clear away the flag we set to indent after paragraphs
unlet html_indent_inctags
diff --git a/vim/after/indent/javascript.vim b/vim/after/indent/javascript.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/javascript.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/mail.vim b/vim/after/indent/mail.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/mail.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/make.vim b/vim/after/indent/make.vim
deleted file mode 100644
index 341cd7f6..00000000
--- a/vim/after/indent/make.vim
+++ /dev/null
@@ -1,4 +0,0 @@
-" Use 'tabstop' (8 columns, a full tab) for indent operations in Makefiles.
-" It seems odd that the stock plugin doesn't force this on its own.
-setlocal shiftwidth=0
-let b:undo_indent = 'setlocal shiftwidth<'
diff --git a/vim/after/indent/markdown.vim b/vim/after/indent/markdown.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/markdown.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/perl.vim b/vim/after/indent/perl.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/perl.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/php.vim b/vim/after/indent/php.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/php.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/sh.vim b/vim/after/indent/sh.vim
new file mode 100644
index 00000000..bff1b904
--- /dev/null
+++ b/vim/after/indent/sh.vim
@@ -0,0 +1,2 @@
+" Use four spaces for indentation
+call indent#Spaces(4)
diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim
index 0767bca0..4300e125 100644
--- a/vim/after/indent/vim.vim
+++ b/vim/after/indent/vim.vim
@@ -5,10 +5,5 @@ if !exists('b:undo_indent')
let b:undo_indent = 'setlocal indentkeys<'
endif
-" Observe VimL conventions for two-space indents
-setlocal shiftwidth=2
-let b:undo_indent .= '|setlocal shiftwidth<'
-if &softtabstop != -1
- let &l:softtabstop = &l:shiftwidth
- let b:undo_indent .= '|setlocal softtabstop<'
-endif
+" Use two (not four!) spaces for indentation, per convention
+call indent#Spaces(2)
diff --git a/vim/after/indent/yaml.vim b/vim/after/indent/yaml.vim
new file mode 100644
index 00000000..d0478631
--- /dev/null
+++ b/vim/after/indent/yaml.vim
@@ -0,0 +1,2 @@
+" Use two (not four!) spaces for indentation, per convention
+call indent#Spaces(2)
diff --git a/vim/after/plugin/2html.vim b/vim/after/plugin/2html.vim
new file mode 100644
index 00000000..dd65486d
--- /dev/null
+++ b/vim/after/plugin/2html.vim
@@ -0,0 +1,11 @@
+" Don't make these settings if the base plugin didn't load
+if !exists('g:loaded_2html_plugin')
+ finish
+endif
+
+" Set preferred fonts for the HTML rendering
+let g:html_font = [
+ \ 'DejaVu Sans Mono',
+ \ 'Ubuntu Mono',
+ \ 'Consolas',
+ \]
diff --git a/vim/after/plugin/dist.vim b/vim/after/plugin/dist.vim
index 98574de8..c53ebd2c 100644
--- a/vim/after/plugin/dist.vim
+++ b/vim/after/plugin/dist.vim
@@ -7,3 +7,4 @@ unlet loaded_rrhelper
unlet loaded_spellfile_plugin
unlet loaded_tarPlugin
unlet loaded_zipPlugin
+unlet loaded_manpager_plugin
diff --git a/vim/after/plugin/insert_cancel.vim b/vim/after/plugin/insert_cancel.vim
new file mode 100644
index 00000000..a8abe6ed
--- /dev/null
+++ b/vim/after/plugin/insert_cancel.vim
@@ -0,0 +1,4 @@
+" Set mapping for insert_cancel.vim
+if exists('loaded_insert_cancel')
+ imap <C-C> <Plug>(InsertCancel)
+endif
diff --git a/vim/after/plugin/matchparen.vim b/vim/after/plugin/matchparen.vim
new file mode 100644
index 00000000..b2be8f61
--- /dev/null
+++ b/vim/after/plugin/matchparen.vim
@@ -0,0 +1,4 @@
+" If matchparen.vim didn't load, use 'showmatch' instead
+if !exists('loaded_matchparen')
+ set showmatch matchtime=3
+endif
diff --git a/vim/after/plugin/spellfile_local.vim b/vim/after/plugin/spellfile_local.vim
new file mode 100644
index 00000000..7d805660
--- /dev/null
+++ b/vim/after/plugin/spellfile_local.vim
@@ -0,0 +1,13 @@
+" Don't make these settings if the base plugin didn't load
+if !exists('g:loaded_spellfile_local')
+ finish
+endif
+
+" Use XDG dirs for 'spellfile' if XDG_DATA_HOME is useable
+if xdg#DataHome() !=# ''
+ let g:spellfile_local_dirs = [ xdg#DataHome() ]
+ call extend(
+ \ g:spellfile_local_dirs,
+ \ xdg#DataDirs(),
+ \)
+endif
diff --git a/vim/after/plugin/undofileskip.vim b/vim/after/plugin/undofileskip.vim
new file mode 100644
index 00000000..e7116940
--- /dev/null
+++ b/vim/after/plugin/undofileskip.vim
@@ -0,0 +1,7 @@
+" If undofileskip.vim loaded, add a few applicable paths to its list
+if !exists('g:undofileskip')
+ finish
+endif
+
+" Just split and copy 'backupskip'
+let g:undofileskip = option#Split(&backupskip)
diff --git a/vim/after/syntax/bindzone.vim b/vim/after/syntax/bindzone.vim
index 29d5f4b8..f95aff8f 100644
--- a/vim/after/syntax/bindzone.vim
+++ b/vim/after/syntax/bindzone.vim
@@ -1,5 +1,5 @@
-" Highlight TLSA and SSHFP records correctly
+" Highlight some newer/weirder records correctly
" <https://github.com/vim/vim/issues/220>
syn keyword zoneRRType
- \ contained TLSA SSHFP
+ \ contained CAA SSHFP TLSA
\ nextgroup=zoneRData skipwhite
diff --git a/vim/after/syntax/mail.vim b/vim/after/syntax/mail.vim
new file mode 100644
index 00000000..77c76f00
--- /dev/null
+++ b/vim/after/syntax/mail.vim
@@ -0,0 +1,3 @@
+" Don't spellcheck code in mail messages
+syntax region mailCode start='`' end='`' keepend contains=@NoSpell
+syntax region mailCodeBlock start=' \{4\}' end='$' contains=@NoSpell
diff --git a/vim/after/syntax/resolv.vim b/vim/after/syntax/resolv.vim
new file mode 100644
index 00000000..4c8ec165
--- /dev/null
+++ b/vim/after/syntax/resolv.vim
@@ -0,0 +1,6 @@
+" Over-simple but good-enough `nameserver` rule fix including IPv6
+" Version 1.4 of the syntax file has a more accurate fix
+if !has('patch-8.2.0380')
+ syntax clear resolvIPNameserver
+ syntax match resolvIPNameserver contained /[0-9.a-fA-F:]\+/
+endif
diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim
index af7670d5..d7cf040d 100644
--- a/vim/after/syntax/sh.vim
+++ b/vim/after/syntax/sh.vim
@@ -16,11 +16,11 @@ elseif exists('b:is_posix')
endif
" The syntax highlighter seems to flag '/baz' in '"${foo:-"$bar"/baz}"' as an
-" error, which it isn't, at least in POSIX sh, Bash, and Ksh.
+" error, which it isn't, at least in POSIX sh, Bash, and Korn shell.
syntax clear shDerefWordError
-" The syntax highlighter doesn't match parens for subshells for 'if' tests
-" correctly if they're on separate lines. This happens enough that it's
+" The syntax highlighter doesn't match parentheses for subshells for 'if'
+" tests correctly if they're on separate lines. This happens enough that it's
" probably not worth keeping the error.
syntax clear shParenError
@@ -33,7 +33,7 @@ syntax clear shTestError
if exists('b:is_posix')
" Highlight some commands that are both defined by POSIX and builtin
- " commands in dash, as a rough but useable proxy for 'shell builtins'. This
+ " commands in dash, as a rough but usable proxy for 'shell builtins'. This
" list was mostly wrested from `man 1 dash`. Also include control structure
" keywords like `break`, `continue`, and `return`.
syntax clear shStatement
@@ -76,8 +76,8 @@ if exists('b:is_posix')
" Core syntax/sh.vim puts IFS and other variables that affect shell function
" in another color, but a subset of them actually apply to POSIX shell too
- " (and plain Bourne). These are selected by searching the POSIX manpages. I
- " added NLSPATH too, which wasn't in the original.
+ " (and plain Bourne). These are selected by searching the POSIX man pages.
+ " I added NLSPATH too, which wasn't in the original.
syntax clear shShellVariables
syntax cluster shCommandSubList add=shShellVariables
syntax keyword shShellVariables
diff --git a/vim/after/syntax/vim.vim b/vim/after/syntax/vim.vim
index e67803cc..bd7d8274 100644
--- a/vim/after/syntax/vim.vim
+++ b/vim/after/syntax/vim.vim
@@ -1,8 +1,10 @@
-" Remove special highlighting for double-quoted strings in comments
+" Remove special highlighting for double-quoted strings and colon labels in
+" comments
syntax clear vimCommentString
+syntax clear vimCommentTitle
" Highlight :CompilerSet commands like :set/:setlocal, but only in compiler
-" scripts in recognisable paths
+" scripts in recognizable paths
if expand('%:p:h:t') ==# 'compiler'
\ && expand('%:e') ==# 'vim'
syntax keyword vimCommand contained
diff --git a/vim/autoload/colorscheme.vim b/vim/autoload/colorscheme.vim
new file mode 100644
index 00000000..349ee374
--- /dev/null
+++ b/vim/autoload/colorscheme.vim
@@ -0,0 +1,22 @@
+" Reset window-global value for 'cursorline' based on current colorscheme name
+function! colorscheme#UpdateCursorline(colors_name, list) abort
+
+ " Record current tab and window number so we can jump back once we're done
+ let l:tab = tabpagenr()
+ let l:win = winnr()
+
+ " Set the window-global value for 'cursorline' in each window of each tab;
+ " on if the current colorscheme is in the whitelist, and off otherwise; fire
+ " the WinEnter and WinLeave events so any other 'cursorline' related hooks
+ " can run too
+ "
+ let l:cursorline = index(a:list, a:colors_name) >= 0
+ tabdo windo let &g:cursorline = l:cursorline
+ \| silent doautocmd WinEnter,WinLeave
+
+ " Move back to the tab and window the user started in
+ execute l:tab . 'tabnext'
+ execute l:win . 'wincmd w'
+ \| silent doautocmd WinEnter
+
+endfunction
diff --git a/vim/autoload/diff.vim b/vim/autoload/diff.vim
index 29389b95..6e87b62a 100644
--- a/vim/autoload/diff.vim
+++ b/vim/autoload/diff.vim
@@ -1,7 +1,7 @@
" Move between diff block headers
function! diff#MoveBlock(count, up, visual) abort
- " Reselect visual selection
+ " Re-select visual selection
if a:visual
normal! gv
endif
diff --git a/vim/autoload/filetype.vim b/vim/autoload/filetype/repeat.vim
index 6a66d62e..899bbcc4 100644
--- a/vim/autoload/filetype.vim
+++ b/vim/autoload/filetype/repeat.vim
@@ -1,6 +1,6 @@
" Helper function to run the 'filetypedetect' group on a file with its
" extension stripped off
-function! filetype#StripRepeat() abort
+function! filetype#repeat#Strip() abort
" Check we have the fnameescape() function
if !exists('*fnameescape')
@@ -33,7 +33,7 @@ endfunction
" Helper function to run the 'filetypedetect' group on a file in a temporary
" sudoedit(8) directory, modifying it with an attempt to reverse the temporary
" filename change
-function! filetype#SudoRepeat() abort
+function! filetype#repeat#Sudo() abort
" Check we have the fnameescape() function
if !exists('*fnameescape')
@@ -53,7 +53,7 @@ function! filetype#SudoRepeat() abort
elseif fn =~# '/[^/]\+\.\w\{8}$'
let fn = expand('<afile>:r')
- " Unrecognised pattern; return, don't repeat
+ " Unrecognized pattern; return, don't repeat
else
return
endif
diff --git a/vim/autoload/gitcommit.vim b/vim/autoload/gitcommit.vim
index 7aba1c5b..72d2b9ff 100644
--- a/vim/autoload/gitcommit.vim
+++ b/vim/autoload/gitcommit.vim
@@ -3,6 +3,7 @@ function! gitcommit#CursorColumn() abort
" If we can find a line after the first that isn't a comment, we're
" composing the message
+ "
for num in range(1, line('$'))
if num == 1
continue
diff --git a/vim/autoload/html.vim b/vim/autoload/html.vim
index 9466be33..2ce5288d 100644
--- a/vim/autoload/html.vim
+++ b/vim/autoload/html.vim
@@ -1,39 +1,6 @@
-" Make a bare URL into a link to itself
-function! html#UrlLink() abort
-
- " Yank this whole whitespace-separated word
- normal! yiW
- " Open a link tag
- normal! i<a href="">
- " Paste the URL into the quotes
- normal! hP
- " Move to the end of the link text URL
- normal! E
- " Close the link tag
- normal! a</a>
-
-endfunction
-
" Tidy the whole buffer
-function! html#TidyBuffer() abort
+function! html#Tidy() abort
let view = winsaveview()
%!tidy -quiet
call winrestview(view)
endfunction
-
-" Update a timestamp
-function! html#TimestampUpdate() abort
- if !&modified
- return
- endif
- let cv = winsaveview()
- call cursor(1,1)
- let li = search('\C^\s*<em>Last updated: .\+</em>$', 'n')
- if li
- let date = substitute(system('date -u'), '\C\n$', '', '')
- let line = getline(li)
- call setline(li, substitute(line, '\C\S.*',
- \ '<em>Last updated: '.date.'</em>', ''))
- endif
- call winrestview(cv)
-endfunction
diff --git a/vim/autoload/html/timestamp.vim b/vim/autoload/html/timestamp.vim
new file mode 100644
index 00000000..8f250710
--- /dev/null
+++ b/vim/autoload/html/timestamp.vim
@@ -0,0 +1,74 @@
+" Keys and date formats for return value of s:Timestamp()
+let s:formats = {
+ \ 'human': '%a, %d %b %Y %T %Z',
+ \ 'machine': '%Y-%m-%dT%H:%M:%SZ',
+ \}
+
+" Get UTC timestamp string dictionary with layout in s:formats
+function! s:Timestamp(time) abort
+
+ " Force UTC, recording previous timezone, if any
+ if exists('$TZ')
+ let tz = $TZ
+ endif
+ let $TZ = 'UTC'
+
+ " Get current time
+ let time = localtime()
+
+ " Fill out timestamp dictionary
+ let timestamp = {}
+ for key in keys(s:formats)
+ let timestamp[key] = strftime(s:formats[key], time)
+ endfor
+
+ " Clear UTC and restore previous timezone, if any
+ unlet $TZ
+ if exists('tz')
+ let $TZ = tz
+ endif
+
+ " Return filled-out timestamp dictionary
+ return timestamp
+
+endfunction
+
+" Define timestamp prefix string
+let s:prefix = 'Last updated: '
+
+" Define pattern to match date timestamps; no ZALGO, please
+let s:pattern = '\m\C'
+ \.s:prefix
+ \.'<time datetime="[^"]\+">'
+ \.'[^<]\+'
+ \.'</time>'
+
+" Update a timestamp
+function! html#timestamp#Update() abort
+
+ " Do nothing if the buffer hasn't been modified
+ if !&modified
+ return
+ endif
+
+ " Find the first occurrence of the timestamp pattern, bail if none
+ let lnum = search(s:pattern, 'nw')
+ if !lnum
+ return
+ endif
+
+ " Get timestamp dictionary
+ let timestamp = s:Timestamp(localtime())
+
+ " Fill out updated timestamp string with dictionary values
+ let update = s:prefix
+ \.'<time datetime="'.timestamp['machine'].'">'
+ \.timestamp['human']
+ \.'</time>'
+
+ " Apply the updated timestamp
+ let line = getline(lnum)
+ let line = substitute(line, s:pattern, update, '')
+ keepjumps call setline(lnum, line)
+
+endfunction
diff --git a/vim/autoload/html/url.vim b/vim/autoload/html/url.vim
new file mode 100644
index 00000000..99b4409e
--- /dev/null
+++ b/vim/autoload/html/url.vim
@@ -0,0 +1,15 @@
+" Make a bare URL into a link to itself
+function! html#url#Anchor() abort
+
+ " Yank this whole whitespace-separated word
+ normal! yiW
+ " Open a link tag
+ normal! i<a href="">
+ " Paste the URL into the quotes
+ normal! hP
+ " Move to the end of the link text URL
+ normal! E
+ " Close the link tag
+ normal! a</a>
+
+endfunction
diff --git a/vim/autoload/indent.vim b/vim/autoload/indent.vim
new file mode 100644
index 00000000..19a9f03d
--- /dev/null
+++ b/vim/autoload/indent.vim
@@ -0,0 +1,35 @@
+" Set the current buffer to space indent
+function! indent#Spaces(...) abort
+ setlocal expandtab
+
+ " If an argument was provided, use that for the number of spaces; otherwise,
+ " set 'shiftwidth' to 0, which then copies 'tabstop'
+ let &l:shiftwidth = a:0
+ \ ? a:1
+ \ : 0
+
+ " If we have the patch that supports it, set 'softtabstop' to dynamically
+ " mirror the value of 'shiftwidth'; failing that, just copy it
+ let &l:softtabstop = patch#('7.3.693')
+ \ ? -1
+ \ : &l:shiftwidth
+
+ call indent#Undo()
+endfunction
+
+" Set the current buffer to tab indent
+function! indent#Tabs() abort
+ setlocal noexpandtab shiftwidth< softtabstop<
+ call indent#Undo()
+endfunction
+
+" Add commands to b:undo_indent to clean up buffer-local indentation changes
+" on a change of filetype
+function! indent#Undo() abort
+ let undo = 'setlocal expandtab< shiftwidth< softtabstop<'
+ if exists('b:undo_indent')
+ let b:undo_indent .= '|'.undo
+ else
+ let b:undo_indent = undo
+ endif
+endfunction
diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim
index 40b7fb7f..6d4874ca 100644
--- a/vim/autoload/mail.vim
+++ b/vim/autoload/mail.vim
@@ -1,39 +1,7 @@
-" Add a header to a mail message
-function! mail#AddHeaderField(name, body) abort
- let num = 0
- while num < line('$') && getline(num + 1) !=# ''
- let num += 1
- endwhile
- call append(num, a:name.': '.a:body)
-endfunction
-
-" Add a set of headers to a mail message
-function! mail#AddHeaderFields(fields) abort
- for name in sort(keys(a:fields))
- call mail#AddHeaderField(name, a:fields[name])
- endfor
-endfunction
-
-" Flag a message as important
-function! mail#FlagImportant() abort
- call mail#AddHeaderFields({
- \ 'Importance': 'High',
- \ 'X-Priority': 1
- \ })
-endfunction
-
-" Flag a message as unimportant
-function! mail#FlagUnimportant() abort
- call mail#AddHeaderFields({
- \ 'Importance': 'Low',
- \ 'X-Priority': 5
- \ })
-endfunction
-
" Move through quoted paragraphs like normal-mode `{` and `}`
function! mail#NewBlank(count, up, visual) abort
- " Reselect visual selection
+ " Re-select visual selection
if a:visual
normal! gv
endif
@@ -79,3 +47,66 @@ function! mail#NewBlank(count, up, visual) abort
endif
endfunction
+
+function! mail#StrictQuote(start, end) abort
+ let body = 0
+ for lnum in range(a:start, a:end)
+
+ " Get current line
+ let line = getline(lnum)
+
+ " Get the leading quote string, if any; skip if there isn't one
+ let quote = matchstr(line, '^>[> ]*')
+ if !strlen(quote)
+ continue
+ endif
+
+ " Normalize the quote with no spaces
+ let quote = substitute(quote, '[^>]', '', 'g')
+
+ " Re-set the line
+ let line = substitute(line, '^[> ]\+', quote, '')
+ call setline(lnum, line)
+
+ endfor
+endfunction
+
+" Attempt to move to a good spot to start writing
+function! mail#SuggestStart() abort
+
+ " Move to top of buffer
+ call setpos('.', [0, 1, 1, 0])
+
+ " Move to body text
+ call search('\m^$', 'c') | +
+
+ " Start by trying to move to the first quoted line; this may fail if there's
+ " no quote, which is fine
+ call search('\m^>', 'c')
+
+ " Delete quoted blank lines or quoted greetings until we get to something
+ " with substance. Yes, I like Perl, how could you tell?
+ while getline('.') =~? '^> *'
+ \ . '\%('
+ \ . '\%('
+ \ . 'g[''\u2019]\=day'
+ \ . '\|\%(good \)\=\%(morning\|afternoon\|evening\)'
+ \ . '\|h[eu]\%(ll\|rr\)o\+'
+ \ . '\|hey\+'
+ \ . '\|hi\+'
+ \ . '\|sup'
+ \ . '\|what[''\u2019]\=s up'
+ \ . '\|yo'
+ \ . '\)'
+ \ . '[[:punct:] ]*'
+ \ . '\%('
+ \ . '\a\+'
+ \ . '[[:punct:] ]*'
+ \ . '\)\='
+ \ . '\)\=$'
+ delete
+ endwhile
+
+ " Now move to the first quoted or unquoted blank line
+ call search('\m^>\= *$', 'c')
+endfunction
diff --git a/vim/autoload/mail/header.vim b/vim/autoload/mail/header.vim
new file mode 100644
index 00000000..5284b84d
--- /dev/null
+++ b/vim/autoload/mail/header.vim
@@ -0,0 +1,59 @@
+" Parse a mail header into a list of dictionaries with 'name' and 'body' keys;
+" preserve case of the name and whitespace in body, including leading space
+"
+function! mail#header#Read() abort
+ let fields = []
+ for lnum in range(1, line('$'))
+ let line = getline(lnum)
+ let matchlist = matchlist(
+ \ line,
+ \ '^\([a-zA-Z0-9-]\+\):\s*\(\_.*\)',
+ \)
+ if !empty(matchlist)
+ let field = {
+ \ 'name': matchlist[1],
+ \ 'body': matchlist[2],
+ \}
+ call add(fields, field)
+ elseif line =~# '^\s' && exists('field')
+ let field['body'] .= "\n" . line
+ elseif line ==# ''
+ break
+ else
+ throw 'Parse error'
+ endif
+ endfor
+ let header = {
+ \'fields': fields,
+ \}
+ return header
+endfunction
+
+" Flatten a header data structure into a string
+function! mail#header#String(header) abort
+ let fields = copy(a:header['fields'])
+ return join(
+ \ map(
+ \ copy(a:header['fields']),
+ \ 'v:val[''name''] . '': '' . v:val[''body''] . "\n"'),
+ \ '',
+ \)
+endfunction
+
+" Replace existing mail header with the provided one
+function! mail#header#Write(header) abort
+ let start = 1
+ for lnum in range(1, line('$'))
+ if getline(lnum) ==# ''
+ break
+ endif
+ let end = lnum
+ endfor
+ let curpos = getpos('.')
+ if exists('end')
+ let range = join([start, end], ',')
+ execute join(['silent', range, 'delete'])
+ endif
+ silent 0 put =mail#header#String(a:header)
+ call setpos('.', curpos)
+endfunction
diff --git a/vim/autoload/mail/header/field.vim b/vim/autoload/mail/header/field.vim
new file mode 100644
index 00000000..db38c09f
--- /dev/null
+++ b/vim/autoload/mail/header/field.vim
@@ -0,0 +1,45 @@
+" Add a field to a header, regardless of whether a field by the same name is
+" already present
+function! mail#header#field#Add(header, name, body) abort
+ let new = {
+ \ 'name': a:name,
+ \ 'body': a:body,
+ \}
+ call add(a:header['fields'], new)
+endfunction
+
+" Set a field in a header, replacing the first one with the same name (if
+" any), and removing any others
+"
+function! mail#header#field#Set(header, name, body) abort
+ let fields = []
+ let new = {
+ \ 'name': a:name,
+ \ 'body': a:body,
+ \}
+ for field in a:header['fields']
+ if field['name'] ==? a:name
+ if exists('new')
+ let field = new | unlet new
+ else
+ continue
+ endif
+ endif
+ call add(fields, field)
+ endfor
+ if exists('new')
+ call add(fields, new) | unlet new
+ endif
+ let a:header['fields'] = fields
+endfunction
+
+" Remove a header field
+function! mail#header#field#Clear(header, name) abort
+ let fields = []
+ for field in a:header['fields']
+ if field['name'] !=? a:name
+ call add(fields, field)
+ endif
+ endfor
+ let a:header['fields'] = fields
+endfunction
diff --git a/vim/autoload/mail/importance.vim b/vim/autoload/mail/importance.vim
new file mode 100644
index 00000000..78fb53ac
--- /dev/null
+++ b/vim/autoload/mail/importance.vim
@@ -0,0 +1,26 @@
+" Define header fields for high, low, and normal priorities
+let s:fields = {
+ \ 'high': {
+ \ 'Importance': 'High',
+ \ 'X-Priority': '1',
+ \},
+ \ 'low': {
+ \ 'Importance': 'Low',
+ \ 'X-Priority': '5',
+ \},
+ \ 'normal': {},
+ \}
+
+" Set the priority headers; pass in "high", "low", or "normal"
+function! mail#importance#Set(level) abort
+ let header = mail#header#Read()
+ let fields = s:fields[a:level]
+ for name in ['Importance', 'X-Priority']
+ if has_key(fields, name)
+ call mail#header#field#Set(header, name, fields[name])
+ else
+ call mail#header#field#Clear(header, name)
+ endif
+ endfor
+ call mail#header#Write(header)
+endfunction
diff --git a/vim/autoload/markdown.vim b/vim/autoload/markdown.vim
index c0818246..0f03961c 100644
--- a/vim/autoload/markdown.vim
+++ b/vim/autoload/markdown.vim
@@ -1,3 +1,26 @@
+" Let's try this heading-based fold method out (Tim Pope)
+function! markdown#Fold() abort
+ let line = getline(v:lnum)
+
+ " Regular headers
+ let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=')
+ if depth > 0
+ return '>' . depth
+ endif
+
+ " Setext style headings
+ if line =~# '^.\+$'
+ let nextline = getline(v:lnum + 1)
+ if nextline =~# '^=\+$'
+ return '>1'
+ elseif nextline =~# '^-\+$'
+ return '>2'
+ endif
+ endif
+
+ return '='
+endfunction
+
" Add an underline under a heading
function! markdown#Heading(char) abort
@@ -9,10 +32,17 @@ function! markdown#Heading(char) abort
" Build underline string by repeating character by the string length of the
" heading text
+ "
let underline = repeat(a:char, strlen(heading))
- " Append the heading text to the buffer on a new line after the heading
- call append(pos[1], underline)
+ " If the line after this one looks like it's already an underline, replace
+ " it; otherwise, create a new underline
+ "
+ if getline(pos[1] + 1) =~# '^[-=]\{2,}$'
+ call setline(pos[1] + 1, underline)
+ else
+ call append(pos[1], underline)
+ endif
" Move to the first column of the underline we just inserted
let pos[1] += 1
diff --git a/vim/autoload/option.vim b/vim/autoload/option.vim
new file mode 100644
index 00000000..49fbf1a4
--- /dev/null
+++ b/vim/autoload/option.vim
@@ -0,0 +1,17 @@
+" Split a comma-separated option value into parts, accounting for escaped
+" commas and leading whitespace as Vim itself does internally
+"
+function! option#Split(expr, ...) abort
+ if a:0 > 1
+ echoerr 'Too many arguments'
+ endif
+ let keepempty = a:0 ? a:1 : 0
+ let parts = split(a:expr, '\\\@<!,[, ]*', keepempty)
+ return map(copy(parts), 'substitute(v:val, ''\\,'', '','', ''g'')')
+endfunction
+
+" Escape the right-hand side of a :set option value
+"
+function! option#Escape(expr) abort
+ return escape(a:expr, ' |"\')
+endfunction
diff --git a/vim/autoload/option/item.vim b/vim/autoload/option/item.vim
new file mode 100644
index 00000000..ee92101f
--- /dev/null
+++ b/vim/autoload/option/item.vim
@@ -0,0 +1,14 @@
+" Escape a single item for a comma-separated list, optionally escaping any
+" filename wildcards
+"
+function! option#item#Escape(item, ...) abort
+ if a:0 > 1
+ echoerr 'Too many arguments'
+ endif
+ let item = a:item
+ let wild = a:0 ? a:1 : 0
+ if wild
+ let item = escape(item, '\*?[{`''$~')
+ endif
+ return escape(item, ',')
+endfunction
diff --git a/vim/autoload/paste_insert.vim b/vim/autoload/paste_insert.vim
deleted file mode 100644
index ada11456..00000000
--- a/vim/autoload/paste_insert.vim
+++ /dev/null
@@ -1,12 +0,0 @@
-function! paste_insert#() abort
- augroup paste_insert
- autocmd!
- autocmd CursorHold,CursorMoved,User *
- \ set nopaste paste?
- \|autocmd! paste_insert
- autocmd InsertEnter *
- \ set paste paste?
- \|autocmd paste_insert InsertLeave *
- \ doautocmd paste_insert User
- augroup END
-endfunction
diff --git a/vim/autoload/patch.vim b/vim/autoload/patch.vim
new file mode 100644
index 00000000..3a17ccda
--- /dev/null
+++ b/vim/autoload/patch.vim
@@ -0,0 +1,35 @@
+" Wrapper to emulate the nicer has() syntax for simultaneous version and patch
+" level checking that was introduced in v7.4.236 and fixed in v7.4.237.
+"
+" * <https://github.com/vim/vim/releases/tag/v7.4.236>
+" * <https://github.com/vim/vim/releases/tag/v7.4.237>
+"
+function! patch#(version) abort
+
+ " If the Vim running is new enough for its has() function to support
+ " checking patch levels with version prefixes, we can just add a "patch-"
+ " prefix to the query, and pass it on to has().
+ "
+ if has('patch-7.4.237')
+ return has('patch-'.a:version)
+ endif
+
+ " Failing that, we need to do our own version number and patch number
+ " comparisons; split the queried version on dots.
+ "
+ let [major, minor, patch] = split(a:version, '\.')
+
+ " The internal variable v:version describing the running Vim looks like
+ " e.g. 801 for v8.1; reproduce that logic for the queried version.
+ "
+ let l:version = major * 100 + minor
+
+ " If the running version number is the same as the required one, return
+ " whether we have the specific patch requested; otherwise, return whether
+ " the running version number is greater than the required one.
+ "
+ return v:version == l:version
+ \ ? has('patch-'.patch)
+ \ : v:version > l:version
+
+endfunction
diff --git a/vim/autoload/quote.vim b/vim/autoload/quote.vim
index 690ba2db..7574ed71 100644
--- a/vim/autoload/quote.vim
+++ b/vim/autoload/quote.vim
@@ -24,8 +24,8 @@ function! quote#QuoteOpfunc(type) abort
continue
endif
- " If configured to do so, add a a space after the quote character, but
- " only if this line isn't already quoted
+ " If configured to do so, add a space after the quote character, but only
+ " if this line isn't already quoted
let new = char
if space && cur[0] != char
let new .= ' '
diff --git a/vim/autoload/reload.vim b/vim/autoload/reload.vim
new file mode 100644
index 00000000..322c44d2
--- /dev/null
+++ b/vim/autoload/reload.vim
@@ -0,0 +1,16 @@
+" Re-run filetype detection, if it's run before
+function! reload#FileType() abort
+ if exists('g:did_load_filetypes')
+ doautocmd filetypedetect BufRead
+ endif
+endfunction
+
+" Re-read .vimrc file, reloading filetypes afterwards to avoid masking
+" filetype plugin settings
+"
+function! reload#Vimrc() abort
+ noautocmd source $MYVIMRC
+ call reload#FileType()
+ redraw
+ echomsg fnamemodify($MYVIMRC, ':p:~').' reloaded'
+endfunction
diff --git a/vim/autoload/spellfile_local.vim b/vim/autoload/spellfile_local.vim
deleted file mode 100644
index aafe64ef..00000000
--- a/vim/autoload/spellfile_local.vim
+++ /dev/null
@@ -1,11 +0,0 @@
-function! spellfile_local#() abort
- let spellfile = join([
- \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'),
- \ substitute(v:lang, '_.*', '', ''),
- \ &encoding
- \ ], '.') . '.add'
- Establish $MYVIM/cache/spell/local
- execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile
- nnoremap <buffer> zG 2zg
- xnoremap <buffer> zG 2zg
-endfunction
diff --git a/vim/autoload/utc.vim b/vim/autoload/utc.vim
deleted file mode 100644
index 1a464342..00000000
--- a/vim/autoload/utc.vim
+++ /dev/null
@@ -1,4 +0,0 @@
-function! utc#(command) abort
- let tz = expand('$TZ')
- let $TZ = 'UTC' | execute a:command | let $TZ = tz
-endfunction
diff --git a/vim/autoload/xdg.vim b/vim/autoload/xdg.vim
new file mode 100644
index 00000000..cb7adcf5
--- /dev/null
+++ b/vim/autoload/xdg.vim
@@ -0,0 +1,67 @@
+" <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables>
+let s:defaults = {
+ \ 'XDG_CACHE_HOME': $HOME.'/.cache',
+ \ 'XDG_CONFIG_HOME': $HOME.'/.config',
+ \ 'XDG_CONFIG_DIRS': '/etc/xdg',
+ \ 'XDG_DATA_HOME': $HOME.'/.local/share',
+ \ 'XDG_DATA_DIRS': '/usr/local/share:/usr/share',
+ \ 'XDG_STATE_HOME': $HOME.'/.local/state',
+ \}
+
+function! s:Get(name) abort
+ let name = a:name
+ if !has_key(s:defaults, name)
+ throw 'Illegal XDG basedirs env var name'
+ endif
+ let value = s:defaults[name]
+ if exists('$'.a:name)
+ execute 'let value = $'.a:name
+ endif
+ return value
+endfunction
+
+function! s:Absolute(path) abort
+ return a:path =~# '^/'
+ \ || a:path =~# '^\~/'
+ \ || a:path ==# '~'
+endfunction
+
+function! s:Home(name) abort
+ let home = s:Get(a:name)
+ if !s:Absolute(home)
+ return ''
+ endif
+ return home.'/vim'
+endfunction
+
+function! s:Dirs(name) abort
+ let dirs = split(s:Get(a:name), ':')
+ return map(
+ \ filter(copy(dirs), 's:Absolute(v:val)')
+ \,'v:val.''/vim'''
+ \)
+endfunction
+
+function! xdg#CacheHome() abort
+ return has('unix') ? s:Home('XDG_CACHE_HOME') : ''
+endfunction
+
+function! xdg#ConfigHome() abort
+ return has('unix') ? s:Home('XDG_CONFIG_HOME') : ''
+endfunction
+
+function! xdg#DataHome() abort
+ return has('unix') ? s:Home('XDG_DATA_HOME') : ''
+endfunction
+
+function! xdg#StateHome() abort
+ return has('unix') ? s:Home('XDG_STATE_HOME') : ''
+endfunction
+
+function! xdg#ConfigDirs() abort
+ return has('unix') ? s:Dirs('XDG_CONFIG_DIRS') : []
+endfunction
+
+function! xdg#DataDirs() abort
+ return has('unix') ? s:Dirs('XDG_DATA_DIRS') : []
+endfunction
diff --git a/vim/bundle/alternate_filetypes b/vim/bundle/alternate_filetypes
new file mode 160000
+Subproject 8110b88643276c17079e597a61ca3c3736b36fd
diff --git a/vim/bundle/copy_linebreak b/vim/bundle/copy_linebreak
-Subproject 6692eef760ccfc2e1b888d1d604e3e1a156fcbc
+Subproject a0004c18da5f524f62e2da6e19be1a51ce282f3
diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current
-Subproject 39dca4f5c795766837dfdc1d868b2cd365c1f7f
+Subproject d1b8db2fe6b06bd556c777c7bd9d4632f12a3a1
diff --git a/vim/bundle/detect_indent b/vim/bundle/detect_indent
new file mode 160000
+Subproject 96f46cae148517e4b8e8a5bbe13b623ddde6b70
diff --git a/vim/bundle/digraph_search b/vim/bundle/digraph_search
-Subproject 005fb8c6e4042e8eca2af224b9ada2d61824f9b
+Subproject 06eb698192dfa4ea64458aa1483d024d251e82e
diff --git a/vim/bundle/html_spelllang b/vim/bundle/html_spelllang
new file mode 160000
+Subproject 161e47f00cd5a1bdcef61097b7ba100ffd69a48
diff --git a/vim/bundle/paste_insert b/vim/bundle/paste_insert
new file mode 160000
+Subproject 1ffcb96611315dd068b734d5aae7ff07fa2b3a2
diff --git a/vim/bundle/put_date b/vim/bundle/put_date
new file mode 160000
+Subproject fa0b0289b80fadbe9af87ca2faa3b5da4512d3f
diff --git a/vim/bundle/quickfix_auto_open b/vim/bundle/quickfix_auto_open
-Subproject b3b1385490c60ad624d631b4cf99f84e058637b
+Subproject 2e1caf2a9af5c61a53bac0027131c9ea4b03071
diff --git a/vim/bundle/redact_pass b/vim/bundle/redact_pass
-Subproject a5ff8935fc2e81de46375d85378e59e333ee1ad
+Subproject 403a44dc32533e631384dfcca40d520b9088b0d
diff --git a/vim/bundle/scratch_buffer b/vim/bundle/scratch_buffer
new file mode 160000
+Subproject d2340baaf1f79b76aebc6d74ab68fbacb41e3a4
diff --git a/vim/bundle/select_old_files b/vim/bundle/select_old_files
new file mode 160000
+Subproject c9ed42c145e09ea121b8e3ff94061253fe4dbd9
diff --git a/vim/bundle/spellfile_local b/vim/bundle/spellfile_local
new file mode 160000
+Subproject 6199ee785c6fb964292ec6e82c5b8a0f79e2606
diff --git a/vim/bundle/squeeze_repeat_blanks b/vim/bundle/squeeze_repeat_blanks
-Subproject 8c849183f8723086e6b61a0644292bdb1ad99c1
+Subproject 27dd1b5858b4839b34249c106d2b3963a3da416
diff --git a/vim/bundle/strip_trailing_whitespace b/vim/bundle/strip_trailing_whitespace
-Subproject 90e60095bcfcfeb60bea60ba7f51bbfac3bf469
+Subproject 03782cdaf9db6329665316e1dc2d1b8270714a3
diff --git a/vim/bundle/undofileskip b/vim/bundle/undofileskip
new file mode 160000
+Subproject 1d0a5cf3aa1bf1f360862819d229d756958df32
diff --git a/vim/bundle/write_mkpath b/vim/bundle/write_mkpath
-Subproject 9f12c7a85e4a2f1cd6f6ba39c5a55a45fe4ea79
+Subproject 2e8372a1c589ccd03207010c7777e155f2f7823
diff --git a/vim/compiler/pyflakes.vim b/vim/compiler/pyflakes.vim
new file mode 100644
index 00000000..727fbd76
--- /dev/null
+++ b/vim/compiler/pyflakes.vim
@@ -0,0 +1,9 @@
+" :compiler support for Python syntax checking with pyflakes
+" <https://pypi.org/project/pyflakes/>
+if exists('current_compiler') || &compatible || !has('patch-7.4.191')
+ finish
+endif
+let current_compiler = 'pyflakes'
+
+CompilerSet makeprg=pyflakes\ %:S
+CompilerSet errorformat=%f:%l:%c:\ %m
diff --git a/vim/compiler/pylint.vim b/vim/compiler/pylint.vim
new file mode 100644
index 00000000..589f78e3
--- /dev/null
+++ b/vim/compiler/pylint.vim
@@ -0,0 +1,9 @@
+" :compiler support for Python linting with pylint
+" <https://pypi.org/project/pyflakes/>
+if exists('current_compiler') || &compatible || !has('patch-7.4.191')
+ finish
+endif
+let current_compiler = 'pylint'
+
+CompilerSet makeprg=pylint\ --output-format=parseable\ --score=n\ %:S
+CompilerSet errorformat=%f:%l:\ %m
diff --git a/vim/filetype.vim b/vim/filetype.vim
index 19f65e23..eea7f1f5 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -16,7 +16,7 @@ augroup filetypedetect
\,?*~
\,?*.{bak,example,in,new,old,orig,sample,test}
\,?*.dpkg-{bak,dist,new,old}
- \ call filetype#StripRepeat()
+ \ call filetype#repeat#Strip()
" Stuff Tom cares about enough and edits often enough to type based on
" filename patterns follows.
@@ -24,6 +24,7 @@ augroup filetypedetect
" Apache config
autocmd BufNewFile,BufRead
\ .htaccess
+ \,htaccess
\,*/apache*/?*.conf
\ setfiletype apache
" Assembly language files
@@ -44,6 +45,7 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.c
\,?*.h
+ \,*/proto/?*.pro
\ setfiletype c
" C++ files
autocmd BufNewFile,BufRead
@@ -66,20 +68,37 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.csv
\ setfiletype csv
+ " Debian package sources
+ autocmd BufNewFile,BufRead
+ \ sources.list
+ \,*/etc/apt/sources.list.d/*.list
+ \ setfiletype debsources
+ " Desktop files
+ autocmd BufNewFile,BufRead
+ \ ?*.desktop
+ \,?*.directory
+ \ setfiletype desktop
" Diff and patch files
autocmd BufNewFile,BufRead
\ ?*.diff
\,?*.patch
\,?*.rej
\ setfiletype diff
- " INI files
+ " INI format files
autocmd BufNewFile,BufRead
\ ?*.ini
+ \,.editorconfig
+ \,perlcriticrc
+ \,.perlcriticrc
\ setfiletype dosini
" DOT graphs
autocmd BufNewFile,BufRead
\ ?*.dot
\ setfiletype dot
+ " NFS exports
+ autocmd BufNewFile,BufRead
+ \ exports
+ \ setfiletype exports
" Forth
autocmd BufNewFile,BufRead
\ ?*.fs,?*.ft
@@ -92,11 +111,18 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ .gdbinit
\ setfiletype gdb
+ " Gemini markup
+ autocmd BufNewFile,BufRead
+ \ *.gmi
+ \,*.gemini
+ \ setfiletype gemtext
" Git commit messages
autocmd BufNewFile,BufRead
\ COMMIT_EDITMSG
+ \,EDIT_DESCRIPTION
\,MERGE_MSG
\,TAG_EDITMSG
+ \,NOTES_EDITMSG
\ setfiletype gitcommit
" Git config files
autocmd BufNewFile,BufRead
@@ -104,6 +130,7 @@ augroup filetypedetect
\,.gitconfig
\,.gitmodules
\,gitconfig
+ \,*/.config/git/config
\ setfiletype gitconfig
" Git rebase manifests
autocmd BufNewFile,BufRead
@@ -114,25 +141,29 @@ augroup filetypedetect
\ *gnupg/options
\,*gnupg/gpg.conf
\ setfiletype gpg
+ " Golang
+ autocmd BufNewFile,BufRead
+ \ ?*.go
+ \ setfiletype go
" UNIX group file
autocmd BufNewFile,BufRead
- \ /etc/group
- \,/etc/group-
- \,/etc/group.edit
- \,/etc/gshadow
- \,/etc/gshadow-
- \,/etc/gshadow.edit
+ \ */etc/group
+ \,*/etc/group-
+ \,*/etc/group.edit
+ \,*/etc/gshadow
+ \,*/etc/gshadow-
+ \,*/etc/gshadow.edit
\ setfiletype group
" GTK settings files
autocmd BufNewFile,BufRead
- \ .gktrc*,
- \,gktrc*
+ \ .gtkrc*
+ \,gtkrc*
\ setfiletype gtkrc
" Vim help files
autocmd BufNewFile,BufRead
- \ ~/.vim/doc/?*.txt
+ \ */*.vim/doc/?*.txt
\,*/vim-*/doc/?*.txt
- \,*/*.vim/doc/?*.txt
+ \,*/vim/*/doc/?*.txt
\,$VIMRUNTIME/doc/?*.txt
\ setfiletype help
" HTML files
@@ -142,7 +173,7 @@ augroup filetypedetect
\ setfiletype html
" hosts(5) file
autocmd BufNewFile,BufRead
- \ /etc/hosts
+ \ */etc/hosts
\ setfiletype hostconf
" inittab(5) files
autocmd BufNewFile,BufRead
@@ -153,6 +184,10 @@ augroup filetypedetect
\ ?*.java
\,?*.jav
\ setfiletype java
+ " Jinja2 templates
+ autocmd BufNewFile,BufRead
+ \ ?*.j2
+ \ setfiletype jinja2
" JSON files
autocmd BufNewFile,BufRead
\ ?*.js
@@ -166,6 +201,11 @@ augroup filetypedetect
\ ?*.l
\,?*.lex
\ setfiletype lex
+ " limits.conf(5) files
+ autocmd BufNewFile,BufRead
+ \ limits.conf
+ \,*/limits.d/*.conf
+ \ setfiletype limits
" Lisp
autocmd BufNewFile,BufRead
\ ?*.lisp
@@ -173,10 +213,19 @@ augroup filetypedetect
\,.emacs
\,emacs
\ setfiletype lisp
+ " Login configuration
+ autocmd BufNewFile,BufRead
+ \ */etc/login.defs
+ \ setf logindefs
" Lua files
autocmd BufNewFile,BufRead
\ ?*.lua
\ setfiletype lua
+ " Lynx configuration
+ au BufNewFile,BufRead
+ \ lynx.cfg
+ \,.lynxrc
+ \ setfiletype lynx
" m4 files
autocmd BufNewFile,BufRead
\ ?*.m4
@@ -186,10 +235,15 @@ augroup filetypedetect
\ ?*.msg
\,mutt-*-[0-9]\+-[0-9]\+-[0-9]\+
\ setfiletype mail
- " Mail messages
+ " Mail aliases
autocmd BufNewFile,BufRead
\ aliases
\ setfiletype mailaliases
+ " Mailcap (MIME app reference) files
+ autocmd BufNewFile,BufRead
+ \ mailcap
+ \,.mailcap
+ \ setfiletype mailcap
" Makefiles
autocmd BufNewFile,BufRead
\ Makefile
@@ -201,13 +255,24 @@ augroup filetypedetect
\ ?*.markdown
\,?*.md
\ setfiletype markdown
+ " Meson configuration
+ autocmd BufNewFile,BufRead
+ \ meson.build
+ \,meson_options.txt
+ \ setfiletype meson
+ " SNMP MIB files
+ autocmd BufNewFile,BufRead
+ \ *.mib
+ \,*.my
+ \ setfiletype mib
" Mutt configuration files
autocmd BufNewFile,BufRead
\ Muttrc
- \,*/.muttrc.d/*.rc
+ \,*/.muttrc.d/?*.rc
+ \,*/muttrc.d/?*.rc
\,.muttrc
\,muttrc
- \,/etc/Muttrc.d/*
+ \,*/etc/Muttrc.d/*
\ setfiletype muttrc
" BIND configuration file
autocmd BufNewFile,BufRead
@@ -233,14 +298,18 @@ augroup filetypedetect
\ setfiletype nroff
" UNIX password and shadow files
autocmd BufNewFile,BufRead
- \ /etc/passwd
- \,/etc/passwd-
- \,/etc/passwd.edit
- \,/etc/shadow
- \,/etc/shadow-
- \,/etc/shadow.edit
+ \ */etc/passwd
+ \,*/etc/passwd-
+ \,*/etc/passwd.edit
+ \,*/etc/shadow
+ \,*/etc/shadow-
+ \,*/etc/shadow.edit
\ setfiletype passwd
- " Perl 5 files
+ " Packet capture files
+ autocmd BufNewFile,BufRead
+ \ ?*.pcap
+ \ setfiletype pcap
+ " Perl files
autocmd BufNewFile,BufRead
\ ?*.pl
\,?*.pm
@@ -248,12 +317,6 @@ augroup filetypedetect
\,*/xt/?*.t
\,Makefile.PL
\ setfiletype perl
- " Perl 6 files
- autocmd BufNewFile,BufRead
- \ ?*.p6
- \,?*.pl6
- \,?*.pm6
- \ setfiletype perl6
" PHP files
autocmd BufNewFile,BufRead
\ ?*.php
@@ -266,9 +329,21 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.pod6
\ setfiletype pod6
+ " protocols(5) files
+ autocmd BufNewFile,BufRead
+ \ protocols
+ \ setfiletype protocols
+ " printcap(5) files
+ autocmd BufNewFile,BufRead
+ \ printcap
+ \ let b:ptcap_type = 'print'
+ \|setfiletype ptcap
" Python files
autocmd BufNewFile,BufRead
\ ?*.py
+ \,?*.pyw
+ \,?*.pythonstartup
+ \,?*.pythonrc
\ setfiletype python
" Readline configuration file
autocmd BufNewFile,BufRead
@@ -293,13 +368,27 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.rb
\ setfiletype ruby
+ " Rust
+ autocmd BufNewFile,BufRead
+ \ ?*.rs
+ \ setfiletype rust
+ " Samba config
+ autocmd BufNewFile,BufRead
+ \ smb.conf
+ \ setfiletype samba
+ " Scheme
+ au BufNewFile,BufRead
+ \ ?*.scm
+ \,*.ss
+ \,*.sld
+ \ setfiletype scheme
" sed files
autocmd BufNewFile,BufRead
\ ?*.sed
\ setfiletype sed
" Services files
autocmd BufNewFile,BufRead
- \ /etc/services
+ \ */etc/services
\ setfiletype services
" Bash shell
autocmd BufNewFile,BufRead
@@ -332,12 +421,21 @@ augroup filetypedetect
\,.shinit
\,.shrc
\,.xinitrc
- \,/etc/default/*
+ \,.xprofile
+ \,.xsession
+ \,.xsessionrc
+ \,*/etc/default/*
\,configure
\,profile
\,shinit
\,shrc
\,xinitrc
+ \,xprofile
+ \,xsession
+ \,xsessionrc
+ \,*/etc/X11/xinit
+ \,*/etc/X11/Xreset
+ \,*/etc/X11/Xsession
\ let b:is_posix = 1
\|setfiletype sh
" SQL
@@ -345,22 +443,32 @@ augroup filetypedetect
\ ?*.sql
\ setfiletype sql
" OpenSSH configuration
+ "" client
autocmd BufNewFile,BufRead
- \ ssh_config,*/.ssh/config
+ \ ssh_config
+ \,*/ssh_config.d/*.conf
+ \,*/.ssh/config,
+ \,*/.ssh/config.d/*.conf
\ setfiletype sshconfig
+ "" server
+ autocmd BufNewFile,BufRead
+ \ sshd_config
+ \,*/sshd_config.d/*.conf
+ \ setfiletype sshdconfig
" sudoers(5)
autocmd BufNewFile,BufRead
\ sudoers
\,sudoers.tmp
- \ setfiletype sshdconfig
- " OpenSSH server configuration
- autocmd BufNewFile,BufRead
- \ sshd_config
\ setfiletype sudoers
" Subversion commit
autocmd BufNewFile,BufRead
\ svn-commit*.tmp
\ setfiletype svn
+ " sysctl configuration files
+ autocmd BufNewFile,BufRead
+ \ */etc/sysctl.conf
+ \,*/etc/sysctl.d/*.conf
+ \ setfiletype sysctl
" Systemd unit files
autocmd BufNewFile,BufRead
\ */systemd/*.*
@@ -373,10 +481,6 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.ti
\ setfiletype terminfo
- " TextEditorAnywhere text field
- autocmd BufNewFile,BufRead
- \ TextEditorAnywhere_??_??_??.txt
- \ setfiletype textarea
" Tidy config
autocmd BufNewFile,BufRead
\ .tidyrc
@@ -387,22 +491,24 @@ augroup filetypedetect
\ .tmux.conf
\,tmux.conf
\ setfiletype tmux
+ " TOML configuration files
+ autocmd BufNewFile,BufRead
+ \ ?*.toml
+ \ setfiletype toml
" Tab-separated (TSV) files
autocmd BufNewFile,BufRead
\ ?*.tsv
\ setfiletype tsv
- " VimL files
+ " Vim script files
autocmd BufNewFile,BufRead
\ ?*.vim
- \,*.exrc
- \,*.gvimrc
- \,*.vimrc
- \,_exrc
- \,_gvimrc
- \,_vimrc
- \,exrc
- \,gvimrc
+ \,.exrc
\,vimrc
+ \,vimrc.*
+ \,[._]vimrc
+ \,gvimrc
+ \,gvimrc.*
+ \,[._]gvimrc
\ setfiletype vim
" .viminfo files
autocmd BufNewFile,BufRead
@@ -414,12 +520,10 @@ augroup filetypedetect
\ .wgetrc
\,wgetrc
\ setfiletype wget
- " Add automatic commands to find Xresources subfiles
+ " Add automatic commands to find .Xresources subfiles
autocmd BufNewFile,BufRead
\ .Xresources
- \,*/.Xresources.d/*
\,Xresources
- \,*/Xresources.d/*
\ setfiletype xdefaults
" XHTML files
autocmd BufNewFile,BufRead
@@ -441,7 +545,8 @@ augroup filetypedetect
\ setfiletype yacc
" YAML files
autocmd BufNewFile,BufRead
- \ ?*.yaml
+ \ ?*.yml
+ \,?*.yaml
\ setfiletype yaml
" Z shell files
autocmd BufNewFile,BufRead
@@ -452,8 +557,8 @@ augroup filetypedetect
\,zshrc
\ setfiletype zsh
- " If it's a new file in a bin, libexec, or scripts subdir that has a
- " Makefile.PL sibling, and I'm editing it, it's almost definitely Perl.
+ " If it's a new file in a bin, libexec, or scripts subdirectory that has
+ " a Makefile.PL sibling, and I'm editing it, it's almost definitely Perl.
autocmd BufNewFile
\ ?*/bin/?*
\,?*/libexec/?*
@@ -468,10 +573,10 @@ augroup filetypedetect
" Clumsy attempt at typing files in `sudo -e` if a filename hasn't already
" been found
autocmd BufNewFile,BufRead
- \ /var/tmp/?*????????.*
- \,/var/tmp/?*.????????
+ \ */var/tmp/?*????????.*
+ \,*/var/tmp/?*.????????
\ if !did_filetype()
- \| call filetype#SudoRepeat()
+ \| call filetype#repeat#Sudo()
\|endif
" Generic text, config, and log files, if no type assigned yet
@@ -480,15 +585,15 @@ augroup filetypedetect
\,?*.txt
\,INSTALL
\,README
- \,/etc/issue
- \,/etc/motd
+ \,*/etc/issue
+ \,*/etc/motd
\ setfiletype text
autocmd BufNewFile,BufRead
\ ?*.cfg
\,?*.conf
\,?*.config
- \,/etc/*
- \ setfiletype config
+ \,*/etc/*
+ \ setfiletype conf
autocmd BufNewFile,BufRead
\ */log/*
\,?*.log
diff --git a/vim/ftplugin/awk.vim b/vim/ftplugin/awk.vim
index 663ba810..76637486 100644
--- a/vim/ftplugin/awk.vim
+++ b/vim/ftplugin/awk.vim
@@ -9,6 +9,10 @@ setlocal comments=:#
setlocal formatoptions+=or
let b:undo_ftplugin = 'setlocal comments< formatoptions<'
+" Fold based on indent level, but start with all folds open
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
+
" Specify ERE flavor for regex_escape.vim
let b:regex_escape_flavor = 'ere'
let b:undo_ftplugin .= '|unlet b:regex_escape_flavor'
diff --git a/vim/ftplugin/csv.vim b/vim/ftplugin/csv.vim
index 9bd3e86e..68378d62 100644
--- a/vim/ftplugin/csv.vim
+++ b/vim/ftplugin/csv.vim
@@ -4,6 +4,6 @@ if exists('b:did_ftplugin')
endif
let b:did_ftplugin = 1
-" No autoformatting
+" No automatic formatting
setlocal formatoptions=
let b:undo_ftplugin = 'formatoptions<'
diff --git a/vim/ftplugin/mail.vim b/vim/ftplugin/mail.vim
new file mode 100644
index 00000000..bc10a2ec
--- /dev/null
+++ b/vim/ftplugin/mail.vim
@@ -0,0 +1,15 @@
+" Only do this when not yet done for this buffer--but don't set the flag
+" ourselves, either; this is intended to be a prelude to
+" $VIMRUNTIME/ftplugin/mail.vim
+"
+if exists('b:did_ftplugin')
+ finish
+endif
+
+" Force no_mail_maps value on to work around loading bad maps in
+" $VIMRUNTIME/ftplugin/mail.vim
+"
+if exists('no_mail_maps')
+ let b:no_mail_maps = no_mail_maps
+endif
+let no_mail_maps = 1
diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim
index d119e599..ddd88e2c 100644
--- a/vim/ftplugin/markdown.vim
+++ b/vim/ftplugin/markdown.vim
@@ -18,30 +18,9 @@ let &l:formatlistpat = '^\s*\d\+\.\s\+\|^[-*+]\s\+\|^\[^\ze[^\]]\+\]:'
let b:undo_ftplugin .= '|setlocal formatoptions< formatlistpat<'
" Let's try this heading-based fold method out (Tim Pope)
-function! MarkdownFold()
- let line = getline(v:lnum)
-
- " Regular headers
- let depth = match(line, '\(^#\+\)\@<=\( .*$\)\@=')
- if depth > 0
- return '>' . depth
- endif
-
- " Setext style headings
- if line =~# '^.\+$'
- let nextline = getline(v:lnum + 1)
- if nextline =~# '^=\+$'
- return '>1'
- elseif nextline =~# '^-\+$'
- return '>2'
- endif
- endif
-
- return '='
-endfunction
-setlocal foldexpr=MarkdownFold()
+setlocal foldexpr=markdown#Fold()
setlocal foldmethod=expr
-let b:undo_ftplugin .= '|delfunction MarkdownFold|setlocal foldexpr< foldmethod<'
+let b:undo_ftplugin .= '|setlocal foldexpr< foldmethod<'
" Spellcheck documents we're actually editing (not just viewing)
if &modifiable && !&readonly
@@ -77,8 +56,8 @@ xnoremap <buffer> <expr> <LocalLeader>Q
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q'
\ . '|xunmap <buffer> <LocalLeader>Q'
-" Autoformat headings
-command! -buffer -nargs=1 MarkdownHeading
+" Automatically format headings
+command -buffer -nargs=1 MarkdownHeading
\ call markdown#Heading(<f-args>)
nnoremap <buffer> <LocalLeader>=
\ :<C-U>MarkdownHeading =<CR>
diff --git a/vim/ftplugin/sed.vim b/vim/ftplugin/sed.vim
index 9627941d..04d86d7d 100644
--- a/vim/ftplugin/sed.vim
+++ b/vim/ftplugin/sed.vim
@@ -8,3 +8,7 @@ let b:did_ftplugin = 1
setlocal comments=:#
setlocal formatoptions+=or
let b:undo_ftplugin = 'setlocal comments< formatoptions<'
+
+" Fold based on indent level, but start with all folds open
+setlocal foldmethod=indent
+let b:undo_ftplugin .= '|setlocal foldmethod<'
diff --git a/vim/ftplugin/textarea.vim b/vim/ftplugin/textarea.vim
deleted file mode 100644
index 872ae4c6..00000000
--- a/vim/ftplugin/textarea.vim
+++ /dev/null
@@ -1,10 +0,0 @@
-" Stop here if the user doesn't want ftplugin mappings
-if exists('no_plugin_maps') || exists('no_textarea_maps')
- finish
-endif
-
-" Switch to mail filetype, just because that's very often the contents of text
-" areas I edit using TextEditorAnywhere
-nnoremap <buffer> <LocalLeader>f
- \ :<C-U>setlocal filetype=mail<CR>
-let b:undo_ftplugin = 'nunmap <buffer> <LocalLeader>f'
diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim
deleted file mode 100644
index 78bddd33..00000000
--- a/vim/indent/csv.vim
+++ /dev/null
@@ -1,15 +0,0 @@
-" Only do this when not done yet for this buffer
-if exists('b:did_indent')
- finish
-endif
-let b:did_indent = 1
-
-" Manual indenting
-setlocal noautoindent
-let b:undo_indent = 'setlocal autoindent<'
-
-" Literal tabs
-setlocal noexpandtab
-setlocal softtabstop=0
-let &shiftwidth = &tabstop
-let b:undo_indent = 'setlocal expandtab< softtabstop< shiftwidth<'
diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim
deleted file mode 100644
index ae72397c..00000000
--- a/vim/indent/tsv.vim
+++ /dev/null
@@ -1,2 +0,0 @@
-" TSVs have the same indent options as CSVs
-runtime! indent/csv.vim
diff --git a/vim/plugin/dist.vim b/vim/plugin/dist.vim
index 3a84abaa..94974f5f 100644
--- a/vim/plugin/dist.vim
+++ b/vim/plugin/dist.vim
@@ -14,3 +14,5 @@ let loaded_netrwPlugin = 1
let loaded_rrhelper = 1
" I don't need extra spelling files
let loaded_spellfile_plugin = 1
+" No thanks, just plain `less` is fine for manual pages
+let loaded_manpager_plugin = 1
diff --git a/vim/plugin/matchit.vim b/vim/plugin/matchit.vim
index f842bd9c..392b2728 100644
--- a/vim/plugin/matchit.vim
+++ b/vim/plugin/matchit.vim
@@ -1,5 +1,5 @@
" Get matchit.vim, one way or another
-if has('packages') && !has('nvim')
+if has('packages')
packadd matchit
else
runtime macros/matchit.vim
diff --git a/vim/plugin/paste_insert.vim b/vim/plugin/paste_insert.vim
deleted file mode 100644
index 9cd5415e..00000000
--- a/vim/plugin/paste_insert.vim
+++ /dev/null
@@ -1,8 +0,0 @@
-if exists('loaded_paste_insert')
- finish
-endif
-let loaded_paste_insert = 1
-command! -bar PasteInsert
- \ call paste_insert#()
-nnoremap <Plug>PasteInsert
- \ :<C-U>PasteInsert<CR>
diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim
deleted file mode 100644
index d911486e..00000000
--- a/vim/plugin/put_date.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-if exists('loaded_put_date')
- finish
-endif
-let loaded_put_date = 1
-command! -bar -range PutDate
- \ <line1>put =strftime('%a, %d %b %Y %T %z')
diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim
deleted file mode 100644
index c026d626..00000000
--- a/vim/plugin/spellfile_local.vim
+++ /dev/null
@@ -1,19 +0,0 @@
-if exists('loaded_spellfile_local')
- finish
-endif
-let loaded_spellfile_local = 1
-
-let s:spellfile = join([
- \ substitute(v:lang, '_.*', '', ''),
- \ &encoding
- \ ], '.') . '.add'
-Establish $MYVIM/cache/spell
-execute 'set spellfile=$MYVIM/cache/spell/'.s:spellfile
-
-command! -bar AddLocalSpellFile
- \ call spellfile_local#()
-
-augroup spellfile_local
- autocmd BufNew,BufRead *
- \ AddLocalSpellFile
-augroup END
diff --git a/vim/plugin/utc.vim b/vim/plugin/utc.vim
deleted file mode 100644
index 9b8b647a..00000000
--- a/vim/plugin/utc.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-if exists('loaded_utc')
- finish
-endif
-let loaded_utc = 1
-command! -bar -complete=command -nargs=1 UTC
- \ call utc#(<q-args>)
diff --git a/vim/scripts.vim b/vim/scripts.vim
index 3c3c53cd..e025a77a 100644
--- a/vim/scripts.vim
+++ b/vim/scripts.vim
@@ -13,14 +13,14 @@ if s:line !~# '^#!'
elseif s:line =~# '\<[gm]\=awk\d*\>'
setfiletype awk
-" Perl 5
+" Lua
+elseif s:line =~# '\<lua\d*\>'
+ setfiletype lua
+
+" Perl
elseif s:line =~# '\<perl5\=\>'
setfiletype perl
-" Perl 6
-elseif s:line =~# '\<perl6\>'
- setfiletype perl6
-
" PHP
elseif s:line =~# '\<php\d*\>'
setfiletype php
diff --git a/vim/syntax/jinja2.vim b/vim/syntax/jinja2.vim
new file mode 100644
index 00000000..2b4aef1a
--- /dev/null
+++ b/vim/syntax/jinja2.vim
@@ -0,0 +1,2 @@
+" Django is similar enough to Jinja2 to be useful for highlighting
+runtime! syntax/django.vim
diff --git a/vim/vimrc b/vim/vimrc
index 2175f114..66c1c68f 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -1,24 +1,8 @@
-" Tom Ryder (tejr)'s Literate Vimrc
-" =================================
+" -----------------------------------
+" Tom Ryder (tejr)'s Literate Vimrc
+" -----------------------------------
"
-" <https://sanctum.geek.nz/cgit/dotfiles.git>
-"
-" This is an attempt at something like a 'literate vimrc', in the tradition of
-" Donald Knuth's "literate programming".
-"
-" <http://www.literateprogramming.com/>
-"
-" It's a long file, and comments abound. If this bothers you, you can do
-" something like this to strip out all the blank lines and lines with only
-" comments:
-"
-" :g/\m^$\|^\s*"/d
-"
-" This file should be saved as "vimrc" in the user runtime directory. On
-" Unix-like operating systems, this is ~/.vim; on Windows, it's ~/vimfiles.
-" It requires Vim 7.0 or newer with +eval, with 'nocompatible'. The vimrc
-" stub at ~/.vimrc on Unix or ~/_vimrc on Windows should checks that these
-" conditions are met before loading this file with `:runtime vimrc`.
+" Last updated: Sun, 14 Jan 2024 03:06:40 +0000
"
" > And I was lifted up in heart, and thought
" > Of all my late-shown prowess in the lists,
@@ -27,282 +11,201 @@
" > Had heaven appeared so blue, nor earth so green,
" > For all my blood danced in me, and I knew
" > That I should light upon the Holy Grail.
-" >
-" > --Tennyson
"
-
-" This file has characters outside the ASCII character set, which makes the
-" Vim script linter vim-vint recommend declaring the file encoding with
-" a :scriptencoding command. The :help for this command specifies that it
-" should be done after 'encoding' is set, so we'll do that here at the top of
-" the file too.
-"
-" On Unix, I keep LANG defined in my environment, and it's almost always set
-" to a multibyte (UTF-8) locale. This informs Vim's choice of internal
-" character encoding, but the default for the 'encoding' option in LANG's
-" absence is "latin1". Nowadays, this is never what I want, so we'll manually
-" choose "utf-8" as an encoding instead if LANG is not defined.
-"
-if !exists('$LANG')
- set encoding=utf-8
-endif
-scriptencoding utf-8
-
-" With encoding handled, the next thing we'll do is ensure we have an
-" environment variable MYVIM set that specifies the path to the directory
-" holding user runtime files. We'll only set our own if such a variable does
-" not already exist in the environment.
-"
-" We'll use the path nominated in the MYVIM variable as the root of our
-" 'backupdir', 'directory', 'undodir', and 'viminfofile' caches, and anywhere
-" else we need a sensible writable location for Vim-related files. Having it
-" available as an environment variable makes assignments with :set and
-" escaping much more convenient, without requiring awkward :execute wrappers.
-"
-" I think the absence of a variable like this is a glaring omission from Vim.
-" We have VIM, VIMRUNTIME, and MYVIMRC, so why is there not an environment
-" variable for the user's Vim runtime directory? It is a mystery.
-"
-" The default value for MYVIM will be the first path in &runtimepath. This is
-" similar to what Vim does internally for situating its spelling database
-" files, in the absence of a specific setting for 'spellfile'.
-"
-" Splitting the values of a comma-separated option like 'runtimepath'
-" correctly is surprisingly complicated. The list separator for such options
-" is more accurately defined as follows:
-"
-" > A comma not preceded by a backslash, and possibly followed by an arbitrary
-" > number of spaces and commas.
-"
-" The pattern required for the split breaks down like this:
-"
-" \\ <- Literal backslash
-" \@<! <- Negative lookbehind assertion; means that whatever occurred
-" before this pattern, here a backslash, cannot precede what
-" follows, but anything that does precede it is not removed from
-" the data as part of the split delimiter
-" , <- Literal comma
-" [, ]* <- Any number of commas and spaces
+" ---Tennyson
"
-" For the edge case of a blank 'runtimepath', MYVIM will be set to the empty
-" string, due to the way that split() works by default without its third
-" parameter {keepempty} set to false.
+" > your vimrc is better than the bible
"
-" Once we have the path elements, we have to remove the escaping for periods,
-" specifically remove up to one backslash before all periods. We do that with
-" a map() over substitute(), string-eval style to accommodate older Vim before
-" Funcref variables were added.
+" ---@polanco@mastodon.sdf.org
+" <https://mastodon.sdf.org/@polanco/104069285780040986>
"
-" We don't, however, have to deal with escaped backslashes, or any other
-" character; you can read the source code for the ad-hoc tokenizer in
-" copy_option_part() in src/misc2.c in Vim's source code and test it with some
-" values of your own if you want to understand why.
+
+" This file is an attempt at something like a "literate vimrc", in the
+" tradition of Donald Knuth's "literate programming":
+" <http://www.literateprogramming.com/>
"
-" I'll factor this out into a global function if I ever need it anywhere else.
+" The dotfiles project as part of which it is maintained is here:
+" <https://dev.sanctum.geek.nz/cgit/dotfiles.git>
"
-" Vim, I love you, but you are really weird.
+" This is a long file, and comments abound. Should this be bothersome, one
+" could execute this command in Vim itself, to strip out comment blocks and
+" blank lines:
"
-let s:runtimepath = map(
- \ split(&runtimepath, '\\\@<!,[, ]*'),
- \ "substitute(v:val, '\\\\,', '', 'g')"
- \ )
-if !exists('$MYVIM')
- let $MYVIM = s:runtimepath[0]
-endif
-
-" Having either imported or defined a value for the MYVIM environment
-" variable, we now need to ensure it's not going to cause problems for the
-" rest of this file. If any of those conditions are met, we'll throw an
-" explanatory error and stop reading this file. Most of the file doesn't
-" depend on MYVIM, but there's not much point accommodating these edge cases.
+" :g/\m^$\|^\s*"/d
"
-
-" Firstly, MYVIM can't be an empty string. We need a real path.
+" This file should be saved as `vimrc`---note no leading period---in the user
+" runtime directory. On GNU/Linux, Mac OS X, and BSD, that directory is
+" `~/.vim`. On Windows, it's `~/vimfiles`. It requires Vim v7.0.0 or newer,
+" including the +eval feature, and with the 'compatible' option turned off.
+" That's to allow line continuations. The vimrc stub at ~/.vimrc (Unix) or
+" ~/_vimrc (Windows) checks that these conditions are met before loading this
+" file.
"
-if $MYVIM ==# ''
- echoerr 'Blank user runtime path'
- finish
-endif
-
-" Secondly, if MYVIM's value contains a comma, its use in comma-separated
-" option values will confuse Vim into thinking more than one directory is
-" being specified, splitting our value into parts. This is normal :set
-" behavior. It's possible to work around this with some careful escaping or
-" :execute abstraction, but it's not really worth the extra complexity for
-" such a niche situation.
+" The Vim script linter Vint should raise no errors, warnings, or style
+" problems with this file. <https://github.com/Kuniwak/vint>
"
-if $MYVIM =~# ','
- echoerr 'Illegal comma in user runtime path'
- finish
-endif
-" Thirdly, Vim v7 prior to v7.1.055 had a nasty bug with escaping with
-" multiple backslash characters on the command line, and so on these older
-" versions of Vim, we'll need to forbid that character in the value of MYVIM
-" in order to be confident that we're stashing files in the correct path.
+" We'll begin by making sure that this file and Vim are speaking the same
+" language. Since it's been the future for a few years now, this file
+" indulges in characters outside the ASCII character set. The presence of
+" such characters prompts Vint to suggest declaring the file encoding with
+" a :scriptencoding command:
"
-" To reproduce this bug on these older versions, try this command:
+" > vim/vimrc:1:1: Use scriptencoding when multibyte char exists (see :help
+" > :scriptencoding)
"
-" :file foo\ bar\ baz
+" Furthermore, the :help for :scriptencoding specifies that :scriptencoding
+" should be set *after* 'encoding'.
"
-" It should rename the buffer as "foo bar aaz"; note the change in the first
-" letter of the last word of the filename.
+" Which encoding to use? The answer is the UTF-8 encoding for Unicode,
+" wherever possible. On POSIX-fearing operating systems, I define the primary
+" locale environment variable $LANG to `en_NZ.UTF-8`. This informs Vim's
+" choice of internal character encoding. In the absence of such a setting,
+" 'encoding' defaults to `latin1` (ISO-8859-1) in most circumstances. Since
+" this is almost never what I want, even if I haven't said so explicitly by
+" exporting $LANG, we'll fall back to UTF-8 instead.
"
-" <https://github.com/vim/vim/releases/tag/v7.1.055>
+" However, we need to test that the +multi_byte feature is available before
+" doing any of this, because it was a compile-time feature that wasn't even
+" enabled by default in Vim v7.0. Its status as an optional feature wasn't
+" removed until v8.1.0733.
"
-if $MYVIM =~# '\\'
- \ && (v:version < 701 || v:version == 701 && !has('patch55'))
- echoerr 'Illegal backslash in user runtime path on Vim < v7.1.055'
- finish
-endif
-
-" Now that we have a bit more confidence in our runtime environment, set up
-" all of the filetype detection, plugin, and indent hooks.
-"
-filetype plugin indent on
-
-" There are a couple of contexts in which it's useful to reload filetypes for
-" the current buffer, quietly doing nothing if filetypes aren't enabled.
-" We'll set up a user command named :ReloadFileType to do this, with
-" a script-local function backing it.
+" <https://github.com/vim/vim/releases/tag/v8.1.0733>
"
-function! s:ReloadFileType() abort
- if exists('g:did_load_filetypes')
- doautocmd filetypedetect BufRead
+if has('multi_byte')
+ if &encoding ==# 'latin1' && !exists('$LANG')
+ set encoding=utf-8
endif
-endfunction
-command! -bar ReloadFileType
- \ call s:ReloadFileType()
-
-" We'll also define a :ReloadVimrc command. This may seem like overkill, at
-" first. Surely just `:source $MYVIMRC` would be good enough?
-"
-" The problem is there are potential side effects to the current buffer when
-" the vimrc is reloaded. The :set commands for options like 'expandtab' and
-" 'shiftwidth' may trample over different buffer-local settings that were
-" specified by filetype and indent plugins. To ensure these local values are
-" reinstated, we'll define the new command wrapper to issue a :ReloadFileType
-" command after the vimrc file is sourced.
-"
-" We can't put the actual :source command into the script-local function we
-" define here, because Vim would get upset that we're trying to redefine
-" a function as it executes!
-"
-" Just to be on the safe side, we also suppress any further ##SourceCmd hooks
-" from running the :source command with a :noautocmd wrapper. This is
-" a defensive measure to avoid infinite recursion. It may not actually be
-" necessary.
-"
-" We emit a faked display of the command, as well, just to make it clear that
-" something has happened. The :redraw just before that message seems to be
-" necessary for this message to display correctly. I'm not sure why.
-"
-function! s:ReloadVimrc() abort
- ReloadFileType
- redraw
- echomsg fnamemodify($MYVIMRC, ':p:~').' reloaded'
-endfunction
-command! -bar ReloadVimrc
- \ noautocmd source $MYVIMRC | call s:ReloadVimrc()
+ scriptencoding utf-8
+endif
-" We'll now create or reset a group of automatic command hooks specific to
-" matters related to reloading the vimrc itself, or maintaining and managing
-" options set within it.
+" With encoding handled, we'll turn our attention to the value of the
+" 'runtimepath' option, since any scripts loaded from the paths specified
+" therein control so much of the behavior of Vim. We build this path up as
+" accurately as possible, accounting for Vim's unusual escaping behavior for
+" these list options.
+"
+" One of the first things we'll need to be able to do is split the value of
+" 'runtimepath' into its constituent paths. Correctly splitting the values of
+" comma-separated Vim options is surprisingly complicated. It's not as simple
+" as just splitting on commas, or even unescaped commas; a more accurate
+" definition of the delimiter is:
+"
+" > Any comma not preceded by a backslash, followed by any number of spaces
+" > and commas.
+"
+" The pattern we use for the call to split() therefore breaks down like this:
+"
+" \\ <- A literal backslash
+" \@<! <- A negative lookbehind assertion; this means that whatever
+" occurred before this pattern---in this case, a backslash---
+" cannot precede what follows, but anything that *does* precede it
+" is considered part of the datum, and not the delimiter.
+" , <- A literal comma
+" [, ]* <- Any number of commas and spaces
"
-augroup vimrc
- autocmd!
-augroup END
-
-" Reload the stub vimrc, and thereby this main one, each time either of them
-" is saved. This often makes errors in the file immediately apparent, and
-" saves restarting Vim or running the :source command manually, which
-" I almost always want to do after changing my vimrc file anyway.
+" We don't, however, have to deal with backslashes before other backslashes,
+" nor before any other character. If this seems wrong to you, I encourage you
+" to read the source code for the ad-hoc tokenizer in copy_option_part() in
+" src/misc2.c in Vim's source code.
"
-autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
- \ ReloadVimrc
-
-" If Vim is new enough (v7.0.187) to support the ##SourceCmd event for
-" automatic command hooks, we'll also apply a hook for that event to catch
-" invocations of :source of either vimrc file, and translate that into
-" reloading the stub vimrc.
+" Vim, I do love you, but sometimes you're really weird.
"
-" <https://github.com/vim/vim/releases/tag/v7.0.187>
+" We fold all that mess away into an autoloaded function option#Split(); see
+" vim/autoload/option.vim. Provided a 'runtimepath' is actually set, using
+" the list returned from that function, we define an environment variable
+" MYVIM---to complement MYVIMRC---for ~/.vim or ~/vimfiles, by retrieving the
+" first value from the 'runtimepath'. We'll use this later on in the file to
+" comprehensively match expected paths for vimrc files.
"
-if exists('##SourceCmd')
- autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
- \ ReloadVimrc
+if &runtimepath ==# ''
+ throw 'Empty ''runtimepath'''
+endif
+let $MYVIM = option#Split(&runtimepath)[0]
+
+" The next components of the runtime directory that we'll set up here will
+" make use of the user's configured XDG base directories:
+"
+" <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables>
+"
+" Note that this isn't an attempt to shoehorn all of Vim into the XDG mold;
+" all of this distribution's files are still expected to be installed into
+" $MYVIM, per the above. We're just leaning on XDG's conventions to provide
+" separate locations for cache files and other configuration.
+"
+" We'll start by retrieving the list of valid paths for configuration from
+" both the XDG_CONFIG_HOME and XDG_CONFIG_DIRS variables, or from their
+" defaults, using autoloaded xdg# functions.
+"
+let s:xdgconfigdirs
+ \ = xdg#ConfigDirs()
+let s:xdgconfighome
+ \ = xdg#ConfigHome()
+let s:xdgdatadirs
+ \ = xdg#DataDirs()
+let s:xdgdatahome
+ \ = xdg#DataHome()
+let s:xdgstatehome
+ \ = xdg#StateHome()
+
+" We put XDG_CONFIG_HOME at the front of the 'runtimepath' list with insert(),
+" provided it isn't empty, which is what the function returns when the
+" configured path isn't absolute. This is per the standard's dictum:
+"
+" > All paths set in these environment variables must be absolute. If an
+" > implementation encounters a relative path in any of these variables it
+" > should consider the path invalid and ignore it.
+"
+" ---XDG Base Directory Specification v0.7 (24th November 2010), "Basics",
+" <https://specifications.freedesktop.org/basedir-spec/0.7/ar01s02.html>
+"
+" Ours not to reason why...
+"
+if s:xdgconfighome !=# '' || !empty(s:xdgconfigdirs)
+ execute 'set runtimepath^='.option#Escape(join(map(
+ \ extend(
+ \ s:xdgconfighome !=# '' ? [s:xdgconfighome] : [],
+ \ s:xdgconfigdirs
+ \),
+ \ 'option#item#Escape(v:val)'
+ \), ','))
+ execute 'set runtimepath+='.option#Escape(join(map(
+ \ reverse(extend(
+ \ s:xdgconfighome !=# '' ? [s:xdgconfighome] : [],
+ \ s:xdgconfigdirs
+ \)),
+ \ 'option#item#Escape(v:val.''/after'')'
+ \), ','))
endif
-" We're going to be creating a few directories now. The code to do so in
-" a compatible way is verbose, mostly because we need to check whether the
-" directory already exists, even though we're specifying the special 'p' value
-" for its optional {path} argument. This is because until v8.0.1708, mkdir()
-" raises an error if the directory to be created already exists, even with
-" a {path} of 'p', where the analogous `mkdir` shell command does not do so
-" with its -p option included.
-"
-" <https://github.com/vim/vim/releases/tag/v8.0.1708>
-"
-" So, let's wrap that logic in a script-local function s:Establish(), and then
-" hide it behind a user command :Establish. We'll lock down all the
-" directories that we create with restrictive permissions, too. Who knows
-" what secrets are in your file buffers?
-"
-" We set the command's tab completion to provide directory names as
-" candidates, and specify that there must be only one argument, which we'll
-" provide as a quoted parameter to the function.
-"
-function! s:Establish(name) abort
- let name = expand(a:name)
- let path = 'p'
- let prot = 0700
- if !isdirectory(name) && exists('*mkdir')
- call mkdir(name, path, prot)
- endif
-endfunction
-command! -bar -complete=dir -nargs=1 Establish
- \ call s:Establish(<f-args>)
-
-" Now that we have a clean means to create directories if they don't already
-" exist, let's apply it for the first time to the user runtime directory.
-" Note that we aren't checking whether this actually succeeded. We do want
-" errors raised if there were problems with the creation, but we'll barrel on
-" ahead regardless after warning the user about our failure.
-"
-Establish $MYVIM
-
-" Our next application of our new :Establish command is to configure the path
-" for the viminfo metadata file, putting it in a cache subdirectory of the
-" user runtime directory set in MYVIM.
-"
-" Using this non-default location for viminfo has the nice benefit of
+" Using a logical but non-default location for viminfo has the nice benefit of
" preventing command and search history from getting clobbered when something
" runs Vim without using this vimrc, because such an instance will safely
-" write its history to the default viminfo path instead. It also contributes
-" to our aim of having everything related to the Vim runtime process in one
-" dedicated directory tree.
-"
-" The normal method of specifying the path to the viminfo file, as applied
-" here, is an addendum of the path to the 'viminfo' option with an "n" prefix.
-" Vim v8.1.716 introduced a nicer way to set this with an option named
-" 'viminfofile', which is too new for us to use just yet.
+" write its own history to the default viminfo path instead.
"
-" <https://github.com/vim/vim/releases/tag/v8.1.0716>
+" This is the portable way to specify the path to the viminfo file, as an
+" addendum of the path to the 'viminfo' option with an `n` prefix. Vim
+" v8.1.716 introduced a way to set this with an option named 'viminfofile',
+" but I don't see a reason to use that.
"
-Establish $MYVIM/cache
-set viminfo+=n$MYVIM/cache/viminfo
+if s:xdgstatehome !=# ''
+ if !isdirectory(s:xdgstatehome)
+ call mkdir(s:xdgstatehome, 'p', 0700)
+ endif
+ execute 'set viminfo+='.option#Escape(
+ \ 'n'.s:xdgstatehome.'/viminfo'
+ \)
+endif
" Speaking of recorded data in viminfo files, the default Vim limit of a mere
-" 50 entries for command and search history is pretty mean. Because I don't
-" think I'm ever likely to be in a situation where remembering several
-" thousand Vim commands and search patterns is going to severely tax memory,
-" let alone disk space, I'd rather this limit were much higher. It's
-" sometimes really handy to dig up commands from many days ago.
+" 50 entries for command and search history is pretty stingy. The documented
+" maximum value for this option is 10000. I used that for a while, but
+" eventually found that on lower-powered machines, keeping this much command
+" history slowed Vim startup down a bit much for my liking, so I've scaled
+" this back to a more conservative 300. If I end up missing useful commands,
+" I might try switching this on available memory instead.
"
-" The maximum value for the 'history' option is documented in `:help
-" 'history'` as 10000, so let's just use that, and see if anything breaks.
-"
-set history=10000
+set history=300
" We'll now enable automatic backups of most file buffers, since that's off by
" default. In practice, I don't need these backups very much, at least if I'm
@@ -321,11 +224,13 @@ set history=10000
" this trailing slashes hint for a long time before 'backupdir' caught up to
" them. The 'directory' option for swap files has supported it at least as
" far back as v5.8.0 (2001), and 'undodir' appears to have supported it since
-" its creation in v7.2.438. Even though the :help for 'backupdir' didn't say
-" so, people assumed it would work the same way, when in fact Vim simply
-" ignored it until v8.1.0251. I don't want to add the slashes to the option
-" value in older versions of Vim where they don't do anything, so we'll check
-" the version ourselves to see if there's any point in including them.
+" its creation in v7.2.438. Even though `:help 'backupdir'` didn't say so,
+" people assumed it would work the same way, when in fact Vim simply ignored
+" it until v8.1.0251.
+"
+" I don't want to add the slashes to the option value in older versions of Vim
+" where they don't do anything, so we'll check the version ourselves to see if
+" there's any point in including them.
"
" <https://github.com/vim/vim/releases/tag/v8.1.0251>
"
@@ -333,71 +238,196 @@ set history=10000
" 'backupfullname', 'swapfilefullname' would have been clearer.
"
set backup
-Establish $MYVIM/cache/backup
-if has('patch-8.1.251')
- set backupdir^=$MYVIM/cache/backup//
-else
- set backupdir^=$MYVIM/cache/backup
+if s:xdgstatehome !=# ''
+ if !isdirectory(s:xdgstatehome.'/backup')
+ call mkdir(s:xdgstatehome.'/backup', 'p', 0700)
+ endif
+ execute 'set backupdir^='.option#Escape(option#item#Escape(
+ \ s:xdgstatehome.'/backup'.(patch#('8.1.251') ? '//' : '')
+ \))
endif
" Files in certain directories on Unix-compatible filesystems should not be
" backed up, for security reasons. This is particularly important if editing
-" temporary files created by sudoedit(8). On Unix-like systems, we here add
-" a few paths to the default value of 'backupskip' in order to prevent the
-" creation of such undesired backup files.
-"
-" * /dev/shm: RAM disk, default path for password-store's temporary files
-" * /usr/tmp: Hard-coded path for sudoedit(8) [1/2]
-" * /var/tmp: Hard-coded path for sudoedit(8) [2/2]
-"
-" Prior to v8.1.1519, Vim didn't check patterns added to 'backupskip' for
-" uniqueness, so adding the same path repeatedly resulted in duplicate strings
-" in the value. This was due to the absence of the P_NODUP flag for the
-" option's definition in src/option.c in the Vim source code. If we're using
-" a version older than v8.1.1519, we'll need to explicitly reset 'backupskip'
-" to its default value before adding patterns to it, so that reloading this
-" file doesn't stack up multiple copies of any added paths.
-"
-" <https://github.com/vim/vim/releases/tag/v8.1.1519>
+" temporary files created by sudoedit(8). We add a few path patterns to the
+" default value of 'backupskip' here, in order to prevent the creation of such
+" undesired backup files.
"
if has('unix')
- if !has('patch-8.1.1519')
+
+ " Prior to v8.1.1519, Vim didn't check patterns added to 'backupskip' for
+ " uniqueness, so adding the same path repeatedly resulted in duplicate
+ " strings in the value. This was due to the absence of the P_NODUP flag for
+ " the option's definition in src/option.c in the Vim source code. If we're
+ " using a version older than v8.1.1519, we'll need to explicitly reset
+ " 'backupskip' to its default value before adding patterns to it, so that
+ " reloading this file doesn't stack up multiple copies of any added paths.
+ "
+ " <https://github.com/vim/vim/releases/tag/v8.1.1519>
+ "
+ if !patch#('8.1.1519')
set backupskip&
endif
- set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/*
+
+ " Typical temporary file locations
+ "" RAM disk, default path for password-store's temporary files
+ set backupskip+=/dev/shm/*
+ "" Hard-coded paths for sudoedit
+ set backupskip+=/usr/tmp/*,/var/tmp/*
+
+ " Per-repository temporary files for Git
+ "" Commit and tag messages
+ set backupskip+=*/*.git/?*_EDITMSG
+ "" Edited patches
+ set backupskip+=*/*.git/ADD_EDIT.patch
+ "" Email messages
+ set backupskip+=*/*.git/.gitsendemail.msg.*
+ "" Interactive rebase manifests
+ set backupskip+=*/*.git/rebase-merge/git-rebase-todo
+
+ " systemd user manager unit files
+ "" Full unit files
+ set backupskip+=*/systemd/user/.#?*.?*????????????????
+ "" Per-unit overrides
+ set backupskip+=*/systemd/user/?*.?*.d/.#override.conf????????????????
+
endif
" Keep swap files for file buffers in a dedicated directory, rather than the
" default of writing them to the same directory as the buffer file. Add two
" trailing slashes to the path to prompt Vim to use the full escaped path in
" its name, in order to avoid filename collisions, since the 'directory'
-" option has supported that hint for much longer than 'backupdir' has. We
-" apply :Establish to attempt to create the path first, if needed.
+" option has supported that hint for much longer than 'backupdir' has.
"
-Establish $MYVIM/cache/swap
-set directory^=$MYVIM/cache/swap//
+if s:xdgstatehome !=# ''
+ if !isdirectory(s:xdgstatehome.'/swap')
+ call mkdir(s:xdgstatehome.'/swap', 'p', 0700)
+ endif
+ execute 'set directory^='.option#Escape(option#item#Escape(
+ \ s:xdgstatehome.'/swap//'
+ \))
+endif
" Keep tracked undo history for files permanently, in a dedicated cache
" directory, so that the u/:undo and CTRL-R/:redo commands will work between
" Vim invocations.
"
" The 'undodir' option has the same structure as 'backupdir' and 'directory';
-" if we have a user runtime directory, create a sub-subdirectory within it
-" dedicated to the undo files cache. Note also the trailing double-slash as
-" a signal to Vim to use the full path of the original file in its undo file
-" cache's name.
+" if we have a user cache directory, create a subdirectory within it dedicated
+" to the undo files cache. Note also the trailing double-slash as a signal to
+" Vim to use the full path of the original file in its undo file cache's name.
"
" Support for these persistent undo file caches was not released until v7.3.0,
" so we need to check for the feature's presence before we enable it.
"
-if has('persistent_undo')
- Establish $MYVIM/cache/undo
+if s:xdgstatehome !=# '' && has('persistent_undo')
set undofile
- set undodir^=$MYVIM/cache/undo//
+ if !isdirectory(s:xdgstatehome.'/undo')
+ call mkdir(s:xdgstatehome.'/undo', 'p', 0700)
+ endif
+ execute 'set undodir^='.option#Escape(option#item#Escape(
+ \ s:xdgstatehome.'/undo//'
+ \))
+endif
+
+" Set up a directory for files generated by :mkview. To date, I think I have
+" used this twice in my life, but may as well be consistent with the other
+" directories of this type. This isn't a comma-separated list like the others
+" ('backupdir', 'directory', 'spell', 'undodir')
+"
+if s:xdgstatehome !=# '' && has('mksession')
+ if !isdirectory(s:xdgstatehome.'/view')
+ call mkdir(s:xdgstatehome.'/view', 'p', 0700)
+ endif
+ execute 'set viewdir='.option#Escape(option#item#Escape(
+ \ s:xdgstatehome.'/view'
+ \))
+endif
+
+" Now that we have a bit more confidence in our runtime environment, set up
+" all of the filetype detection, plugin, and indent hooks.
+"
+filetype plugin indent on
+
+" There are a couple of contexts in which it's useful to reload filetypes for
+" the current buffer, quietly doing nothing if filetypes aren't enabled.
+" We'll set up a user command named :ReloadFileType to do this, with
+" an autoloaded function backing it.
+"
+command! -bar ReloadFileType
+ \ call reload#FileType()
+
+" We'll also define a :ReloadVimrc command. This may seem like overkill, at
+" first. Surely just `:source $MYVIMRC` would be good enough?
+"
+" The problem is there are potential side effects to the current buffer when
+" the vimrc is reloaded. The global :set commands for some options may
+" trample over different buffer-local settings that were specified by filetype
+" and indent plugins. To ensure these local values are reinstated, we'll
+" define the new command wrapper around an autoloaded function that itself
+" issues a :ReloadFileType command after the vimrc file is sourced.
+"
+command! -bar ReloadVimrc
+ \ call reload#Vimrc()
+
+" We'll now create or reset a group of automatic command hooks specific to
+" matters related to reloading the vimrc itself, or maintaining and managing
+" options set within it.
+"
+augroup vimrc
+ autocmd!
+augroup END
+
+" Reload the stub vimrc, and thereby this main one, each time either of them
+" is written. This often makes errors in the file immediately apparent, and
+" saves restarting Vim or running the :source command manually, which I almost
+" always want to do after changing my vimrc file anyway.
+"
+autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
+ \ ReloadVimrc
+
+" If Vim is new enough (v7.0.187) to support the ##SourceCmd event for
+" automatic command hooks, we'll also apply a hook for that event to catch
+" invocations of :source of either vimrc file, and translate that into
+" reloading the stub vimrc.
+"
+" <https://github.com/vim/vim/releases/tag/v7.0.187>
+"
+if exists('##SourceCmd')
+ autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
+ \ ReloadVimrc
+endif
+
+" For spelling, use New Zealand English by default, but later on we'll
+" configure a leader mapping to switch to United States English, since I so
+" often have to write for Yankees.
+"
+set spelllang=en_nz
+
+" Spell checking includes optional support for catching lower case letters at
+" the start of sentences, and defines a pattern in 'spellcapcheck' for the end
+" of a sentence. The default is pretty good, but with two-spacing with
+" 'cpoptions' including `J` and 'formatoptions' including `p` as set later in
+" this file, we can be less ambiguous in this pattern. We require two
+" consecutive spaces, a newline, a carriage return, or a tab to mark the end
+" of a sentence. This means that we could make abbreviations like "i.e.
+" something" without flagging "something" as a spelling error.
+"
+set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\)
+
+" When spell-checking snakeCased or CamelCased words, treat every upper-case
+" character in a word text object as the beginning of a new word for separate
+" spell-checking. At the time of writing, this is still a very new option
+" (v8.2.0953, June 2020).
+"
+" <https://github.com/vim/vim/releases/tag/v8.2.0953>
+"
+if exists('+spelloptions')
+ set spelloptions+=camel
endif
" For word completion in insert mode with CTRL-X CTRL-K, or if 'complete'
-" includes the 'k' flag, the 'dictionary' option specifies the path to the
+" includes the `k` flag, the 'dictionary' option specifies the path to the
" system word list. This makes the dictionary completion work consistently,
" even if 'spell' isn't set at the time to coax it into using 'spellfile'.
"
@@ -408,33 +438,37 @@ endif
" At some point, I may end up having to set this option along with 'spellfile'
" a bit more intelligently to ensure that spell checking and dictionary
" function consistently, and with reference to the same resources. For the
-" moment, I've just added another entry referring to a directory in the user
-" runtime directory, but I don't have anything distinct to put there yet.
-"
-" In much the same way, we add an expected path to a thesaurus, for completion
-" with CTRL-X CTRL-T in insert mode, or with 't' added to 'completeopt'. The
-" thesaurus data isn't installed as part of the default `install-vim` target
-" in tejr's dotfiles, but it can be retrieved and installed with
-" `install-vim-thesaurus`.
-"
-" I got the thesaurus itself from the link in the :help for 'thesaurus' in
-" v8.1. It's from WordNet and MyThes-1. I maintain a mirror on my own
-" website that the Makefile recipe attempts to retrieve. I had to remove the
-" first two metadata lines from thesaurus.txt, as Vim appeared to interpret
-" them as part of the body data.
-"
-" Extra checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM
-" need to be made, because the P_NDNAME property is assigned to them, which
-" enforces a character blacklist in the option value. We check for the same
-" set of blacklist characters here, and if the MYVIM path offends, we just
-" skip the setting entirely, rather than throwing cryptic errors at the user.
-" None of them are particularly wise characters to have in paths, anyway,
-" legal though they may be on Unix filesystems.
+" moment, I've just added additional entries referring to the user's data
+" directory.
"
set dictionary^=/usr/share/dict/words
-if $MYVIM !~# '[*?[|;&<>\r\n]'
- set dictionary^=$MYVIM/ref/dictionary.txt
- set thesaurus^=$MYVIM/ref/thesaurus.txt
+if s:xdgdatahome !=# '' || !empty(s:xdgdatadirs)
+ execute 'set dictionary^='.option#Escape(join(map(
+ \ extend(
+ \ s:xdgdatahome !=# '' ? [s:xdgdatahome] : [],
+ \ s:xdgdatadirs
+ \),
+ \ 'option#item#Escape(v:val.''/dictionary.txt'')'
+ \), ','))
+endif
+
+" In much the same way as 'dictionary', we add an expected path to
+" a thesaurus, for completion with CTRL-X CTRL-T in insert mode, or with `t`
+" added to 'completeopt'. The thesaurus data isn't installed as part of the
+" default `install-vim` target in tejr's dotfiles, but a decent one can be
+" retrieved from my website at <https://sanctum.geek.nz/ref/thesaurus.txt>.
+" I got this from the link in the :help for 'thesaurus' in v8.1. It's from
+" WordNet and MyThes-1. I had to remove the first two metadata lines from
+" thesaurus.txt, as Vim appeared to interpret them as part of the body data.
+"
+if s:xdgdatahome !=# '' || !empty(s:xdgdatadirs)
+ execute 'set thesaurus^='.option#Escape(join(map(
+ \ extend(
+ \ s:xdgdatahome !=# '' ? [s:xdgdatahome] : [],
+ \ s:xdgdatadirs
+ \),
+ \ 'option#item#Escape(v:val.''/thesaurus.txt'')'
+ \), ','))
endif
" Next, we'll modernize a little in adjusting some options with old
@@ -462,42 +496,13 @@ endif
"
" The default value for the 'path' option is similar, in that it has an aged
" default; this option specifies directories in which project files and
-" includes can be unearthed by navigation commands like 'gf'. Specifically,
+" includes can be unearthed by navigation commands like `gf`. Specifically,
" its default value comprises /usr/include, which is another C default. Let's
" get rid of that, too.
"
set comments= commentstring= define= include=
set path-=/usr/include
-" Next, we'll adjust the global indentation settings. In general and as
-" a default, I prefer spaces to tabs, and I like to use four of them, for
-" a more distinct visual structure. Should you happen to disagree with this,
-" I cordially invite you to fite me irl.
-"
-" <https://sanctum.geek.nz/blinkenlights/spaces.webm>
-"
-" Filetype indent plugins will often refine these settings for individual
-" buffers. For example, 'expandtab' is not appropriate for Makefiles, nor for
-" the Go programming language. For another, two-space indents are more
-" traditional for Vim script.
-"
-set autoindent " Use indent of previous line on new lines
-set expandtab " Insert spaces when tab key is pressed in insert mode
-set shiftwidth=4 " Indent command like < and > use four-space indents
-
-" Apply 'softtabstop' option to make a tab key press in insert mode insert the
-" same number of spaces as defined by the indent depth in 'shiftwidth'. If
-" Vim is new enough to support it (v7.3.693), apply a negative value to do
-" this dynamically if 'shiftwidth' changes.
-"
-" <https://github.com/vim/vim/releases/tag/v7.3.693>
-"
-if v:version > 730 || v:version == 730 && has('patch693')
- set softtabstop=-1
-else
- let &softtabstop = &shiftwidth
-endif
-
" Relax traditional vi's harsh standards over what regions of the buffer can
" be removed with backspace in insert mode. While this admittedly allows bad
" habits to continue, since insert mode by definition is not really intended
@@ -551,6 +556,14 @@ if exists('+breakindent')
set breakindent
endif
+" I use `cd` with no argument to go $HOME in the shell all the time.
+" Analogous behavior for Vim with :cd makes sense to me. I can use :pwd (or
+" my <Leader>g mapping) if I want to see where I am.
+"
+if exists('+cdhome')
+ set cdhome
+endif
+
" Rather than rejecting operations like :write or :saveas when 'readonly' is
" set or in other situations in which data might be lost, Vim should give me
" a prompt to allow me to confirm that I know what I'm doing.
@@ -561,7 +574,7 @@ set confirm
" if it's going to be followed by another key code, despite this being how the
" function keys and Meta/Alt modifier are implemented for many terminal types.
" Otherwise, if I press Escape, there's an annoying delay before 'showmode'
-" stops showing '--INSERT--'.
+" stops showing `--INSERT--`.
"
" This breaks the function keys and the Meta/Alt modifier in insert mode in
" most or maybe all of the terminals I use, but I don't want those keys in
@@ -569,34 +582,21 @@ set confirm
"
set noesckeys
-" By default, I prefer that figuring out where a region of text to fold away
-" should be done by the indent level of its lines, since I tend to be careful
-" about my indentation even in languages where it has no semantic meaning.
+" Always start with 'foldlevel' set high enough to have all folds of any
+" practical depth open by default.
"
-set foldmethod=indent
-
-" That said, I don't want any of these indent-based folds to start off closed.
-" Therefore, we set the depth level at which folds should automatically start
-" as closed to a rather high number, per the documentation's recommendations.
-"
-" I think of a Vim window with a file buffer loaded into it as
-" a two-dimensional, planar view of the file, so that moving down one screen
-" line means moving down one buffer line, at least when 'wrap' is unset.
-" Folds break that mental model, and so I usually enable them explicitly only
-" when I'm struggling to grasp some code with very long functions or loops.
-"
-set foldlevelstart=99
+set foldlevel=256
" Automatic text wrapping options using flags in the 'formatoptions' option
-" begin here. I rely on the filetype plugins to set the 't' and 'c' flags for
+" begin here. I rely on the filetype plugins to set the `t` and `c` flags for
" this option to configure whether text or comments should be wrapped, as
" appropriate for the document type or language, and so I don't mess with
" either of those flags here.
" If a line is already longer than 'textwidth' would otherwise limit when
" editing of that line begins in insert mode, don't suddenly automatically
-" wrap it; I'll break it apart myself with a command like 'gq'. This doesn't
-" seem to stop paragraph reformatting with 'a', if that's set.
+" wrap it; I'll break it apart myself with a command like `gq`. This doesn't
+" seem to stop paragraph reformatting with `a`, if that's set.
"
set formatoptions+=l
@@ -611,8 +611,8 @@ set formatoptions+=1
" If the filetype plugins have correctly described what the comment syntax for
" the buffer's language looks like, it makes sense to use that to figure out
" how to join lines within comments without redundant comment syntax cropping
-" up. For example, with this set, joining lines in this very comment with 'J'
-" would remove the leading '"' characters.
+" up. For example, with this set, joining lines in this very comment with `J`
+" would remove the leading `"` characters.
"
" This 'formatoptions' flag wasn't added until v7.3.541. Because we can't
" test for the availability of option flags directly, we resort to a version
@@ -622,23 +622,23 @@ set formatoptions+=1
"
" <https://github.com/vim/vim/releases/tag/v7.3.541>
"
-if v:version > 730 || v:version == 730 && has('patch541')
+if patch#('7.3.541')
set formatoptions+=j
endif
-" A momentary digression here into the doldrums of 'cpoptions'--after
+" A momentary digression here into the doldrums of 'cpoptions'---after
" staunchly opposing it for years, I have converted to two-spacing. You can
" blame Steve Losh:
"
" <http://stevelosh.com/blog/2012/10/why-i-two-space/>
"
-" Consequently, we specify that sentence objects for the purposes of the 's'
-" text object, the '(' and ')' sentence motions, and formatting with the 'gq'
+" Consequently, we specify that sentence objects for the purposes of the `s`
+" text object, the `(` and `)` sentence motions, and formatting with the 'gq'
" command must be separated by *two* spaces. One space does not suffice.
"
" My defection to the two-spacers is also the reason I now leave 'joinspaces'
" set, per its default, so that two spaces are inserted when consecutive
-" sentences separated by a line break are joined onto one line by the 'J'
+" sentences separated by a line break are joined onto one line by the `J`
" command.
"
set cpoptions+=J
@@ -651,18 +651,18 @@ set cpoptions+=J
" If we're using two-period spacing for sentences, Vim can interpret the
" different spacing to distinguish between the two types, and can thereby
" avoid breaking a line just after an abbreviating period. For example, the
-" two words in "Mr. Moolenaar" should never be split apart, preventing
-" confusion on the reader's part lest the word "Mr." look too much like the
-" end of a sentence, and also preserving the semantics of that same period for
-" subsequent reformatting; its single-space won't get lost.
+" two words in "Mr. Moolenaar" should never be split apart, lest the
+" abbreviation "Mr." look too much like the end of a sentence. This also
+" preserves the semantics of that same period for subsequent reformatting; its
+" single-space won't get lost.
"
-" So, getting back to our 'formatoptions' settings, that is what the 'p' flag
+" So, getting back to our 'formatoptions' settings, that is what the `p` flag
" does. I wrote the patch that added it, after becoming envious of an
" analogous feature during an ill-fated foray into GNU Emacs usage.
"
" <https://github.com/vim/vim/releases/tag/v8.1.1523>
"
-if has('patch-8.1.728')
+if patch#('8.1.728')
set formatoptions+=p
endif
@@ -678,22 +678,22 @@ if has('gui_running')
set guioptions+=M
endif
-" By default, Vim doesn't allow a file buffer to have unsaved changes if it's
-" not displayed in a window. Setting this option removes that restriction so
-" that buffers can remain in a modified state while not actually displayed
-" anywhere.
+" By default, Vim doesn't allow a file buffer to have unwritten changes if
+" it's not displayed in a window. Setting this option removes that
+" restriction so that buffers can remain in a modified state while not
+" actually displayed anywhere.
"
" This option is set in almost every vimrc I read; it's so pervasive that
" I sometimes see comments expressing astonishment or annoyance that it isn't
" set by default. However, I didn't actually need this option for several
" years of Vim usage, because I instinctively close windows onto buffers only
-" after the buffers within them were saved anyway.
+" after the buffers within them have been written anyway.
"
" However, the option really is required for batch operations performed with
-" commands like :argdo or :bufdo, because Vim won't otherwise tolerate unsaved
-" changes to a litany of buffers that are not displayed in any window. After
-" I started using such command maps a bit more often, I realized I finally had
-" a reason to turn this on permanently.
+" commands like :argdo or :bufdo, because Vim won't otherwise tolerate
+" unwritten changes to a litany of buffers that are not displayed in any
+" window. After I started using such command maps a bit more often,
+" I realized I finally had a reason to turn this on permanently.
"
set hidden
@@ -743,7 +743,7 @@ set listchars+=nbsp:+ " Non-breaking spaces
" precedes: Signals presence of unwrapped text to screen left
" « U+00BB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
"
-" Failing that, '<' and '>' will do the trick.
+" Failing that, `<` and `>` will do the trick.
"
if has('multi_byte_encoding')
set listchars+=extends:»,precedes:«
@@ -788,7 +788,12 @@ set noruler
set sessionoptions-=localoptions " No buffer options or mappings
set sessionoptions-=options " No global options or mappings
-" The 'I' flag for the 'shortmess' option prevents the display of the Vim
+" Turn 'showcmd' off if a system vimrc has been rude enough to set it; I don't
+" like how it can interfere with the display of longer lines.
+"
+set noshowcmd
+
+" The `I` flag for the 'shortmess' option prevents the display of the Vim
" startup screen with version information, :help hints, and donation
" suggestion. After I registered Vim and donated to Uganda per the screen's
" plea, I didn't feel bad about turning this off anymore. Even with this
@@ -801,6 +806,15 @@ set sessionoptions-=options " No global options or mappings
"
set shortmess+=I
+" Scrolling by screen line rather than file line makes sense to me. Turn the
+" option to do so on, if it's there. This only works with mouse scrolling,
+" which I don't use, and with CTRL-E, CTRL-Y, which I should be using more
+" anyway.
+"
+if exists('+smoothscroll')
+ set smoothscroll
+endif
+
" I find the defaults of new windows opening above or to the left of the
" previous window too jarring, because I'm used to both the i3 window manager
" and the tmux terminal multiplexer doing it the other way around, in reading
@@ -809,22 +823,11 @@ set shortmess+=I
"
set splitbelow splitright
-" Limit the number of characters per line that syntax highlighting will
-" attempt to match. This is as much an effort to encourage me to break long
-" lines and do hard wrapping correctly as it is for efficiency.
-"
-set synmaxcol=500
-
-" Vim has an internal list of terminal types that support using smoother
-" terminal redrawing, and for which 'ttyfast' is normally set, described in
-" `:help 'ttyfast'`. That list includes most of the terminals I use, but
-" there are a couple more for which the 'ttyfast' option should apply: the
-" windows terminal emulator PuTTY, and the terminal multiplexer tmux, both of
-" which I use heavily.
+" I don't like the titles of my terminal windows being changed, especially
+" when changing them back doesn't actually work. Just leave them alone, Vim,
+" even if you think you can handle it.
"
-if &term =~# '^putty\|^tmux'
- set ttyfast
-endif
+set notitle
" We really don't want a mouse; while I use it a lot for cut and paste in X,
" it just gets in the way if the tool running in the terminal tries to use it
@@ -885,7 +888,7 @@ set wildmode=list:longest,full
" giving patterns for the top 100 alphanumeric extensions for files from the
" running user's home directory:
"
-" $ (LC_ALL=C find "$HOME" ! -type d -name '*.?*' -exec \
+" $ (LC_ALL=C ; find "$HOME" ! -type d -name '*.?*' -exec \
" sh -c 'for fn ; do
" ext=${fn##*.}
" case $ext in
@@ -898,7 +901,7 @@ set wildmode=list:longest,full
"
" I turned out to have rather a lot of .html and .vim files.
"
-" If you're scoffing at that and thinking "I could write a much simpler one",
+" If you're scoffing at that and thinking "I could write a much simpler one,"
" please do so, and send it to me at <tom@sanctum.geek.nz> to have yours put
" in here instead, with appropriate credit. Don't forget to handle more than
" ARG_MAX files, include filenames with newlines, and that the -z or -0 null
@@ -906,11 +909,6 @@ set wildmode=list:longest,full
"
" <https://mywiki.wooledge.org/UsingFind#Complex_actions>
"
-" It's tempting to put the list of patterns here into a separate file--or at
-" least into a more readily editable intermediate list variable--rather than
-" the minor maintenance hassle it presently constitutes in this compact form.
-" I'm not sure whether I'll do that just yet.
-"
set wildignore=*~,#*#,*.7z,.DS_Store,.git,.hg,.svn,*.a,*.adf,*.asc,*.au,*.aup
\,*.avi,*.bin,*.bmp,*.bz2,*.class,*.db,*.dbm,*.djvu,*.docx,*.exe
\,*.filepart,*.flac,*.gd2,*.gif,*.gifv,*.gmo,*.gpg,*.gz,*.hdf,*.ico
@@ -919,18 +917,20 @@ set wildignore=*~,#*#,*.7z,.DS_Store,.git,.hg,.svn,*.a,*.adf,*.asc,*.au,*.aup
\,*.s3m,*.sdbm,*.sqlite,*.swf,*.swp,*.tar,*.tga,*.ttf,*.wav,*.webm,*.xbm
\,*.xcf,*.xls,*.xlsx,*.xpm,*.xz,*.zip
-" Allow me to be lazy and type a path to complete on the Ex command line in
-" all-lowercase, and transform the consequent completion to match the
-" appropriate case, like the Readline setting completion-ignore-case can be
-" used for GNU Bash.
+" Allow me to type a path to complete on the Ex command line in all-lowercase,
+" and transform the consequent completion to match the appropriate case, like
+" the Readline setting `completion-ignore-case` can be used for GNU Bash.
+"
+" When completing filenames on the command line, choose completions without
+" regard to case, allowing me the ease of typing a partial path in
+" all-lowercase. This is very similar to the Readline setting
+" `completion-ignore-case` used for Bash.
"
-" As far as I can tell, despite its name, the 'wildignore' case option doesn't
-" have anything to do with the 'wildignore' option, and so files that would
-" match any of those patterns only with case insensitivity implied will still
-" be candidates for completion.
+" The 'wildignorecase' option is not related to the similarly-named
+" 'wildignore' option, nor to the +wildmenu feature.
"
-" The option wasn't added until v7.3.72, so we need to check it exists before
-" we try to set it.
+" We need to check that the 'wildignorecase' option exists before we set it,
+" because it wasn't added to Vim until v7.3.72:
"
" <https://github.com/vim/vim/releases/tag/v7.3.072>
"
@@ -970,26 +970,33 @@ endif
" background. For any other color scheme, turn the option off, because it
" almost always stands out too much for my liking.
"
+" You'd think the pattern here could be used to match the color scheme name,
+" and it can be---after patch v7.4.108, when Christian Brabandt fixed it.
+" Until that version, it matched against the current buffer name, so we're
+" forced to have an explicit test in the command instead.
+"
+" <https://github.com/vim/vim/releases/tag/v7.4.108>
+"
autocmd vimrc ColorScheme *
- \ set nocursorline
-autocmd vimrc ColorScheme sahara
- \ set cursorline
+ \ call colorscheme#UpdateCursorline(g:colors_name, ['sahara'])
-" We'll have Vim try to use my 'sahara' fork of the 'desert256' color scheme.
-" If we fail to load the color scheme, for whatever reason, suppress the
-" error, and ensure a dark background for the default color scheme.
+" Use `dark` as my default value for 'background', in the absence of an
+" environment variable COLORFGBG or a response in v:termrbgresp that would set
+" it specifically.
"
-" There's also a very simple grayscale color scheme I occasionally use instead
-" called 'juvenile', which is included as a Git submodule with this dotfiles
-" distribution.
+if !exists('$COLORFGBG') && !get(v:, 'termrbgresp')
+ set background=dark
+endif
+
+" If the background seems to be dark, and I have either the GUI or a 256 color
+" terminal, and my custom sahara.vim color scheme looks to be available, load
+" it.
"
-try
+if &background ==# 'dark'
+ \ && (has('gui_running') || str2nr(&t_Co) >= 256)
+ \ && globpath(&runtimepath, 'colors/sahara.vim') !=# ''
colorscheme sahara
-catch
- if &background !=# 'dark'
- set background=dark
- endif
-endtry
+endif
" My mapping definitions begin here. I have some general personal rules for
" approaches to mappings:
@@ -1010,7 +1017,7 @@ endtry
" extent possible, and avoid "doing more" in insert mode besides merely
" inserting text as it's typed.
"
-" * Avoid key chords with Ctrl in favor of leader keys.
+" * Avoid key chords with CTRL in favor of leader keys.
"
" * Never use Alt/Meta key chords; the terminal support for them is just too
" confusing and flaky.
@@ -1026,6 +1033,13 @@ endtry
" many of these.
"
+" I use Mosh (the mobile shell) a lot, which uses CTRL-^ as its escape key.
+" That shadows Vim's shortcut to switch to the alternate buffer. Map
+" <Backspace> to do that instead.
+"
+nnoremap <Backspace>
+ \ <C-^>
+
" I find the space bar's default behavior in normal mode of moving right one
" character to be useless. Instead, I remap it to be a lazy way of paging
" through the argument list buffers, scrolling a page until the last line of
@@ -1035,48 +1049,8 @@ endtry
"
nnoremap <expr> <Space>
\ line('w$') < line('$')
- \ ? "\<PageDown>"
- \ : ":\<C-U>next\<CR>"
-
-" I hate CTRL-C's default insert mode behavior. It ends the insert session
-" without firing the InsertLeave event for automatic command hooks. Why would
-" anyone want that? It breaks plugins that hinge on mirrored functionality
-" between the InsertEnter and InsertLeave events, and doesn't otherwise differ
-" from Escape or :stopinsert. Even worse, people think it's a *synonym* for
-" Escape, and use it because it's easier to reach than the Escape key or
-" CTRL-[. Terrible!
-"
-" Instead, I apply a custom plugin named insert_cancel.vim to make it cancel
-" the current insert operation; that is, if the buffer has changed at all
-" since the start of the insert operation, pressing CTRL-C will reverse it,
-" while ending insert mode and firing InsertLeave as normal. This makes way
-" more sense to me, and I use it all the time now.
-"
-" <https://sanctum.geek.nz/cgit/vim-insert-cancel.git/about/>
-"
-" You might think on a first look, as I did, that a plugin is overkill, and
-" that a mapping like this would be all that's required:
-"
-" :inoremap <C-C> <Esc>u
-"
-" Indeed, it *mostly* works, but there are some subtle problems with it. The
-" primary issue is that if you didn't make any changes during the insert mode
-" session that you're terminating, it *still* reverses the previous change,
-" which will be something else entirely that you probably *didn't* mean to be
-" undone. The plugin's way of working around this and the other shortcomings
-" of the simple mapping above is not too much more complicated, but it was not
-" easy to figure out.
-"
-" At any rate, we only want to establish the mapping if we can expect the
-" plugin to load, so test that 'loadplugins' is set and that the plugin file
-" exists with the expected filename.
-"
-" If the plugin isn't available, I just abandon CTRL-C to continue its
-" uselessness.
-"
-if &loadplugins && globpath(&runtimepath, 'plugin/insert_cancel.vim') !=# ''
- imap <C-C> <Plug>(InsertCancel)
-endif
+ \ ? "\<PageDown>"
+ \ : ":\<C-U>next\<CR>"
" I often can't remember (or guess) digraph codes, and want to look up how to
" compose a specific character that I can name, at least in part. The table
@@ -1100,7 +1074,7 @@ endif
" > Í I' LATIN CAPITAL LETTER I WITH ACUTE
" > ...etc...
"
-" <https://sanctum.geek.nz/cgit/vim-digraph-search.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-digraph-search.git/about/>
"
" This leaves you in insert mode, ready to hit CTRL-K one more time and then
" type the digraph that you've hopefully found.
@@ -1109,7 +1083,8 @@ endif
" checking that the plugin's available before we map to it; it'll just quietly
" do nothing.
"
-imap <C-K><C-K> <Plug>(DigraphSearch)
+imap <C-K><C-K>
+ \ <Plug>(DigraphSearch)
" I end up hitting CTRL-L to clear or redraw the screen in interactive shells
" and tools like Mutt and Vim pretty often. It feels natural to me to stack
@@ -1132,33 +1107,36 @@ nnoremap <C-L>
" for this, but it didn't work. Maybe i_CTRL-O doesn't respect mappings.
" I couldn't find any documentation about it.
"
-inoremap <C-L> <C-O>:execute "normal \<C-L>"<CR>
+inoremap <C-L>
+ \ <C-O>:execute "normal \<C-L>"<CR>
-" We use :vnoremap here rather than :xnoremap and thereby make the mapping
-" apply to select mode as well, because CTRL-L doesn't reflect a printable
-" character, and so we may as well make it work, even though I don't actually
-" use select mode directly.
+" We use :vmap here rather than :xmap to have the mapping applied for select
+" mode as well as visual mode. This is because CTRL-L doesn't reflect
+" a printable character, and so we don't shadow anything by making it work,
+" even though I don't actually use select mode directly very much.
"
-vmap <C-L> <Esc><C-L>gv
+vmap <C-L>
+ \ <Esc><C-L>gv
-" By default, the very-useful normal mode command '&' that repeats the
+" By default, the very-useful normal mode command `&` that repeats the
" previous :substitute command doesn't preserve the flags from that
" substitution. I'd prefer it to do so, like the :&& command does, and it's
" easily remapped for both normal and visual mode, so let's just do it.
"
-nnoremap &
- \ :&&<CR>
-xnoremap &
+noremap &
\ :&&<CR>
+ounmap &
+sunmap &
-" I really like using the '!' command in normal mode as an operator to filter
+" I really like using the `!` command in normal mode as an operator to filter
" text through a shell command. It always bugged me a little that there
" didn't seem to be an analogue for a motion to filter text through an
" internal command like :sort, so I wrote one.
"
-" <https://sanctum.geek.nz/cgit/vim-colon-operator.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-colon-operator.git/about/>
"
-nmap g: <Plug>(ColonOperator)
+nmap g:
+ \ <Plug>(ColonOperator)
" I used Tim Pope's unimpaired.vim plugin for ages, and I liked some of these
" bracket pair mappings, so I've carried a few of the simpler ones over. All
@@ -1192,10 +1170,12 @@ nnoremap ]l
" put_blank_lines.vim. These use operator functions so that they're
" repeatable without repeat.vim. They accept count prefixes, too.
"
-" <https://sanctum.geek.nz/cgit/vim-put-blank-lines.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-put-blank-lines.git/about/>
"
-nmap [<Space> <Plug>(PutBlankLinesAbove)
-nmap ]<Space> <Plug>(PutBlankLinesBelow)
+nmap [<Space>
+ \ <Plug>(PutBlankLinesAbove)
+nmap ]<Space>
+ \ <Plug>(PutBlankLinesBelow)
" We're on to the leader maps, now. It's difficult to know in what order to
" describe and specify these. I used to have them in alphabetical order, but
@@ -1211,6 +1191,16 @@ nmap ]<Space> <Plug>(PutBlankLinesBelow)
let mapleader = '\'
let maplocalleader = ','
+" If the local leader is a comma, map double-tap comma to its original
+" function in the relevant modes so that I can still use it quickly without
+" relying on mapping 'timeout'.
+"
+if maplocalleader ==# ','
+ noremap ,,
+ \ ,
+ sunmap ,,
+endif
+
" Let's start with some simple ones; these ones all just toggle a boolean
" option, and print its new value. They're dirt simple to specify, and don't
" require any plugins.
@@ -1221,66 +1211,73 @@ let maplocalleader = ','
" 'cursorline' is always off when in any visual mode, including block mode,
" where it actually might have been really handy.
+"" Leader,TAB toggles automatic indentation based on the previous line
+nnoremap <Leader><Tab>
+ \ :<C-U>set autoindent! autoindent?<CR>
+"" Leader,c toggles highlighted cursor row; doesn't work in visual mode
+nnoremap <Leader>c
+ \ :<C-U>set cursorline! cursorline?<CR>
"" Leader,h toggles highlighting search results
nnoremap <Leader>h
\ :<C-U>set hlsearch! hlsearch?<CR>
"" Leader,i toggles showing matches as I enter my pattern
nnoremap <Leader>i
\ :<C-U>set incsearch! incsearch?<CR>
-"" Leader,TAB toggles automatic indentation based on the previous line
-nnoremap <Leader><Tab>
- \ :<C-U>setlocal autoindent! autoindent?<CR>
-"" Leader,c toggles highlighted cursor row; doesn't work in visual mode
-nnoremap <Leader>c
- \ :<C-U>setlocal cursorline! cursorline?<CR>
"" Leader,s toggles spell checking
nnoremap <Leader>s
- \ :<C-U>setlocal spell! spell?<CR>
+ \ :<C-U>set spell! spell?<CR>
" The next group of option-toggling maps are much the same as the previous
" group, except they also include analogous maps for visual mode, defined as
" recursive maps into normal mode that conclude with re-selecting the text.
-"" Leader,N toggles position display in bottom right
-nnoremap <Leader>N
- \ :<C-U>set ruler! ruler?<CR>
-xmap <Leader>N <Esc><Leader>Ngv
"" Leader,C toggles highlighted cursor column; works in visual mode
-nnoremap <Leader>C
- \ :<C-U>setlocal cursorcolumn! cursorcolumn?<CR>
-xmap <Leader>C <Esc><Leader>Cgv
+noremap <Leader>C
+ \ :<C-U>set cursorcolumn! cursorcolumn?<CR>
+ounmap <Leader>C
+sunmap <Leader>C
"" Leader,l toggles showing tab, end-of-line, and trailing white space
-nnoremap <Leader>l
- \ :<C-U>setlocal list! list?<CR>
-xmap <Leader>l <Esc><Leader>lgv
+noremap <Leader>l
+ \ :<C-U>set list! list?<CR>
+ounmap <Leader>l
+sunmap <Leader>l
"" Leader,n toggles line number display
-nnoremap <Leader>n
- \ :<C-U>setlocal number! number?<CR>
-xmap <Leader>n <Esc><Leader>ngv
+noremap <Leader>n
+ \ :<C-U>set number! number?<CR>
+ounmap <Leader>n
+sunmap <Leader>n
+"" Leader,N toggles position display in bottom right
+noremap <Leader>N
+ \ :<C-U>set ruler! ruler?<CR>
+ounmap <Leader>N
+sunmap <Leader>N
"" Leader,w toggles soft wrapping
-nnoremap <Leader>w
- \ :<C-U>setlocal wrap! wrap?<CR>
-xmap <Leader>w <Esc><Leader>wgv
-
-" This next one just shows option state of the 'formatoptions' affecting how
-" text is automatically formatted; it doesn't change its value.
-
-"" Leader,f shows the current 'formatoptions' at a glance
-nnoremap <Leader>f
- \ :<C-U>setlocal formatoptions?<CR>
+noremap <Leader>w
+ \ :<C-U>set wrap! wrap?<CR>
+ounmap <Leader>w
+sunmap <Leader>w
" I often have to switch between US English and NZ English. The latter is
" almost exactly the same as UK English in most locales, although we use
" dollars rather than pounds. This is mostly so I remember things like
-" excluding or including the 'u' in words like 'favourite', depending on the
+" excluding or including the `u` in words like `favourite`, depending on the
" target audience. I generally use US English for international audiences.
-
-"" Leader,u sets US English spelling language
-nnoremap <Leader>u
- \ :<C-U>setlocal spelllang=en_us<CR>
-"" Leader,z sets NZ English spelling language
+"
nnoremap <Leader>z
- \ :<C-U>setlocal spelllang=en_nz<CR>
+ \ :<C-U>set spelllang=en_nz<CR>
+nnoremap <Leader>u
+ \ :<C-U>set spelllang=en_us<CR>
+
+" I've also been trying to learn French lately (2023-04-03), and having
+" a spelling check there is handy for doing my homework.
+"
+" This mapping used to show the state of 'formatoptions', but I haven't been
+" using that nearly as often lately.
+"
+" <https://sanctum.geek.nz/images/ze-cultured-frenchman.png>
+"
+nnoremap <Leader>f
+ \ :<C-U>set spelllang=fr<CR>
" The next mapping is also for toggling an option, but it's more complicated;
" it uses a simple plugin of mine called copy_linebreak.vim to manage several
@@ -1295,11 +1292,12 @@ nnoremap <Leader>z
" larger blocks of text or for manipulating the text as it leaves the buffer,
" it makes more sense to use :! commands.
"
-" <https://sanctum.geek.nz/cgit/vim-copy-linebreak.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-copy-linebreak.git/about/>
"
"" Leader,b toggles settings friendly to copying and pasting
-nmap <Leader>b <Plug>(CopyLinebreakToggle)
+nmap <Leader>b
+ \ <Plug>(CopyLinebreakToggle)
" The above mappings show that mappings for toggling boolean options are
" simple, but there isn't a way to toggle single flags within option strings
@@ -1308,13 +1306,14 @@ nmap <Leader>b <Plug>(CopyLinebreakToggle)
" the name of an option, and the second is the flag within it that should be
" toggled on or off.
-"" Leader,a toggles 'formatoptions' 'a' auto-flowing flag
+"" Leader,a toggles 'formatoptions' `a` auto-flowing flag
nnoremap <Leader>a
\ :<C-U>ToggleFlagLocal formatoptions a<CR>
"" Leader,L toggles 'colorcolumn' showing the first column beyond 'textwidth'
-nnoremap <Leader>L
+noremap <Leader>L
\ :<C-U>ToggleFlagLocal colorcolumn +1<CR>
-xmap <Leader>L <Esc><Leader>Lgv
+ounmap <Leader>L
+sunmap <Leader>L
" This mapping uses my paste_insert.vim plugin to queue up automatic commands
" for the next insert operation. It's still pretty new. It replaces my old
@@ -1322,7 +1321,8 @@ xmap <Leader>L <Esc><Leader>Lgv
" kept confusing me. I'm hoping this will be better.
"" Leader,p prepares the next insert for paste mode
-nmap <Leader>p <Plug>PasteInsert
+nmap <Leader>p
+ \ <Plug>PasteInsert
" These mappings are for managing filetypes. The first one uses the
" :ReloadFileType command that was defined much earlier in this file for
@@ -1333,34 +1333,33 @@ nnoremap <Leader>F
\ :<C-U>ReloadFileType<CR>
"" Leader,t shows current filetype
nnoremap <Leader>t
- \ :<C-U>setlocal filetype?<CR>
+ \ :<C-U>set filetype?<CR>
"" Leader,T clears filetype
nnoremap <Leader>T
- \ :<C-U>setlocal filetype=<CR>
+ \ :<C-U>set filetype=<CR>
-" These mappings use my put_date.vim and utc.vim plugins for date insertion
-" into the buffer.
+" These mappings use my put_date.vim plugin for date insertion into the
+" buffer.
"" Leader,d inserts the local date (RFC 2822)
nnoremap <Leader>d
\ :PutDate<CR>
"" Leader,D inserts the UTC date (RFC 2822)
nnoremap <Leader>D
- \ :<Home>UTC<End> PutDate<CR>
+ \ :PutDate!<CR>
" This group contains mappings that are to do with file and path management
-" relative to the current buffer. The Leader,P mapping that creates
-" directory hierarchies uses the :Establish command created earlier.
+" relative to the current buffer.
"" Leader,g shows the current file's fully expanded path
nnoremap <Leader>g
\ :<C-U>echo expand('%:p')<CR>
"" Leader,G changes directory to the current file's location
nnoremap <Leader>G
- \ :<C-U>cd %:h<Bar>pwd<CR>
+ \ :<C-U>cd %:h <Bar> pwd<CR>
"" Leader,P creates the path to the current file if it doesn't exist
nnoremap <Leader>P
- \ :<C-U>Establish %:h<CR>
+ \ :<C-U>call mkdir(expand('%:h'), 'p')<CR>
" This group contains mappings that show information about Vim's internals:
" marks, registers, variables, and the like.
@@ -1410,35 +1409,45 @@ nnoremap <Leader><Insert>
\ :<C-U>enew<CR>
"" Leader,e forces a buffer to be editable, even a :help one
nnoremap <Leader>e
- \ :<C-U>setlocal modifiable noreadonly<CR>
+ \ :<C-U>set modifiable noreadonly<CR>
"" Leader,E locks a buffer, reversible with <Leader>e
nnoremap <Leader>E
- \ :<C-U>setlocal nomodifiable readonly<CR>
-"" Leader,j jumps to buffers ("jetpack")
+ \ :<C-U>set nomodifiable readonly<CR>
+"" Leader,j jumps to buffers---the "jetpack"
nnoremap <Leader>j
\ :<C-U>buffers<CR>:buffer<Space>
-" This ground defines mappings for filtering and batch operations to clean up
+" Leader,o hacks up the list of old files from viminfo just long enough to
+" ensure that :browse :oldfiles fits in a screen, avoiding an Enter or `q`
+" keystroke before entering the number. This one is handy followed by
+" <Leader>,\ to jump back to the last remembered position in that file, since
+" by definition viminfo remembers that mark, too.
+"
+nmap <Leader>o
+ \ <Plug>(SelectOldFiles)
+
+" This group defines mappings for filtering and batch operations to clean up
" buffer text. All of these mappings use commands from my custom plugins:
"
" :KeepPosition
-" <https://sanctum.geek.nz/cgit/vim-keep-position.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-keep-position.git/about/>
" :SqueezeRepeatBlanks
-" <https://sanctum.geek.nz/cgit/vim-squeeze-repeat-blanks.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-squeeze-repeat-blanks.git/about/>
" :StripTrailingWhitespace
-" <https://sanctum.geek.nz/cgit/vim-strip-trailing-whitespace.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-strip-trailing-whitespace.git/about/>
"
"" Leader,x strips trailing whitespace
-nnoremap <Leader>x
- \ :StripTrailingWhitespace<CR>
-xnoremap <Leader>x
+noremap <Leader>x
\ :StripTrailingWhitespace<CR>
+ounmap <Leader>x
+sunmap <Leader>x
+
"" Leader,X squeezes repeated blank lines
-nnoremap <Leader>X
- \ :SqueezeRepeatBlanks<CR>
-xnoremap <Leader>X
+noremap <Leader>X
\ :SqueezeRepeatBlanks<CR>
+ounmap <Leader>X
+sunmap <Leader>X
"" Leader,= runs the whole buffer through =, preserving position
nnoremap <Leader>=
\ :<C-U>KeepPosition execute 'normal! 1G=G'<CR>
@@ -1453,23 +1462,28 @@ nnoremap <Leader>+
"" Leader,_ uses last changed or yanked text as an object
onoremap <Leader>_
\ :<C-U>execute 'normal! `[v`]'<CR>
-"" Leader,% uses entire buffer as an object
+"" Leader,% or Leader,5 uses entire buffer as an object
onoremap <Leader>%
\ :<C-U>execute 'normal! 1GVG'<CR>
+omap <Leader>5
+ \ <Leader>%
" This group defines some useful motions, including navigating by indent
" block using a custom plugin:
"
-" <https://sanctum.geek.nz/cgit/vim-vertical-region.git/about/>
+" <https://dev.sanctum.geek.nz/cgit/vim-vertical-region.git/about/>
"
"" Leader,{ and Leader,} move to top and bottom of indent region
-map <Leader>{ <Plug>(VerticalRegionUp)
+map <Leader>{
+ \ <Plug>(VerticalRegionUp)
sunmap <Leader>{
-map <Leader>} <Plug>(VerticalRegionDown)
+map <Leader>}
+ \ <Plug>(VerticalRegionDown)
sunmap <Leader>}
-"" Leader,\ jumps to the last edit position mark: think "Now, where was I?"
-noremap <Leader>\ `"
+"" Leader,\ jumps to the last edit position mark; think "Now, where was I?"
+noremap <Leader>\
+ \ `"
sunmap <Leader>\
" This group does both: useful motions on defined text objects.
@@ -1493,29 +1507,68 @@ nnoremap <Leader>?
" other place. The plugin mappings probably require their own documentation
" comment block, but my hands are getting tired from all this typing.
"
-" * <https://sanctum.geek.nz/cgit/vim-replace-operator.git/about/>
-" * <https://sanctum.geek.nz/cgit/vim-regex-escape.git/about/>
+" * <https://dev.sanctum.geek.nz/cgit/vim-alternate-filetype.git/about/>
+" * <https://dev.sanctum.geek.nz/cgit/vim-regex-escape.git/about/>
+" * <https://dev.sanctum.geek.nz/cgit/vim-replace-operator.git/about/>
+" * <https://dev.sanctum.geek.nz/cgit/vim-scratch-buffer.git/about/>
"
"" Leader,. runs the configured make program into the location list
nnoremap <Leader>.
\ :<C-U>lmake!<CR>
"" Leader,q formats the current paragraph
-nnoremap <Leader>q gqap
+nnoremap <Leader>q
+ \ gqap
"" Leader,r acts as a replacement operator
-nmap <Leader>r <Plug>(ReplaceOperator)
-xmap <Leader>r <Plug>(ReplaceOperator)
-"" Leader,* escapes regex metacharacters
-nmap <Leader>* <Plug>(RegexEscape)
-xmap <Leader>* <Plug>(RegexEscape)
+map <Leader>r
+ \ <Plug>(ReplaceOperator)
+ounmap <Leader>r
+sunmap <Leader>r
+"" Leader,!/1 repeats the last command, adding a bang
+nnoremap <Leader>!
+ \ :<Up><Home><S-Right>!<CR>
+nmap <Leader>1
+ \ <Leader>!
+"" Leader,#/3 switches the current buffer to the next alternate filetype
+nmap <Leader>#
+ \ <Plug>(AlternateFileType)
+nmap <Leader>3
+ \ <Leader>#
+"" Leader,&/7 escapes regex metacharacters
+map <Leader>&
+ \ <Plug>(RegexEscape)
+ounmap <Leader>&
+sunmap <Leader>&
+map <Leader>7
+ \ <Leader>&
+ounmap <Leader>7
+sunmap <Leader>7
+"" Leader,*/8 is "sticky star":
+"" - Set search string to word under cursor
+"" - Show search highlighting if it's enabled
+"" - Don't move the cursor
+nnoremap <Leader>*
+ \ :<C-U>let @/ = expand('<cword>') <Bar> let &hlsearch = &hlsearch<CR>
+nmap <Leader>8
+ \ <Leader>*
+"" Leader,` opens a scratch buffer, horizontally split
+nnoremap <Leader>`
+ \ :<C-U>ScratchBuffer<CR>
+"" Leader,~ opens a scratch buffer, vertically split
+nnoremap <Leader>~
+ \ :<C-U>vertical ScratchBuffer<CR>
+
+" There's no digraph for ZERO WIDTH SPACE (U+200B), which I often need to work
+" around word boundary problems in tagging people on the Fediverse.
+"
+digraphs zs 8203
" And last, but definitely not least, I'm required by Vim fanatic law to
" include a mapping that reloads my whole configuration. This uses the
" command wrapper defined much earlier in the file, so that filetypes also get
" reloaded afterwards, meaning I don't need to follow <Leader>R with
" a <Leader>F to fix up broken global settings.
-
-"" Leader,R reloads ~/.vimrc
+"
nnoremap <Leader>R
\ :<C-U>ReloadVimrc<CR>
@@ -1524,17 +1577,28 @@ nnoremap <Leader>R
" pretty useful. First, some 'deliberate' abbreviations for stuff I type
" a lot:
"
-inoreabbrev tr@ tom@sanctum.geek.nz
-inoreabbrev tr/ <https://sanctum.geek.nz/>
+inoreabbrev tr@
+ \ tom@sanctum.geek.nz
+inoreabbrev tr/
+ \ <https://sanctum.geek.nz/>
" And then, just automatically fix some things I almsot always spell or type
" wrnog.
"
-inoreabbrev almsot almost
-inoreabbrev wrnog wrong
-inoreabbrev Fielding Feilding
-inoreabbrev THe The
-inoreabbrev THere There
+inoreabbrev almsot
+ \ almost
+inoreabbrev wrnog
+ \ wrong
+inoreabbrev Fielding
+ \ Feilding
+inoreabbrev Newsbeuter
+ \ Newsboat
+inoreabbrev newsbeuter
+ \ newsboat
+inoreabbrev THe
+ \ The
+inoreabbrev THere
+ \ There
" Here endeth the literate vimrc. Let us praise God.
"
@@ -1543,4 +1607,5 @@ inoreabbrev THere There
" > authors...as soon as this is perceived the book should be thrown away,
" > for time is precious.
" >
-" > -- Schopenhauer
+" > ---Schopenhauer
+"
diff --git a/vim/vimrc.stub b/vim/vimrc.stub
new file mode 100644
index 00000000..2acd2d10
--- /dev/null
+++ b/vim/vimrc.stub
@@ -0,0 +1,27 @@
+" We have a big, important decision to make here.
+"
+" Check that we're not running in 'compatible' mode, nor that the environment
+" calls for the same, and that we're running Vim v7.0.0 or newer. If it's all
+" clear, we can load the main vimrc file from ~/.vim/vimrc to use Vim in all
+" of its incompatible glory, and then stop sourcing the rest of this file.
+"
+if !&compatible && !exists('$POSIXLY_CORRECT')
+ if v:version >= 700
+ runtime vimrc
+ finish
+ endif
+endif
+
+" If we got this far, it means we're running a tiny, 'compatible', and/or
+" ancient version of Vim. So: strip out the user runtime dirs from
+" 'runtimepath', force 'compatible' on, :source your trusty ~/.exrc, put on
+" your dubbed cassette copy of Kraftwerk's 'Computerwelt', and start using vi
+" v3.7 on your engineering department's SunOS 2.0 server via your shiny new
+" VT220 terminal. It's December 1985, and you're going home soon for the
+" holidays. You're writing K&R C tonight. It's good for you, like raisin
+" bran.
+"
+set runtimepath-=~/.vim
+set runtimepath-=~/.vim/after
+set compatible shortmess+=I t_Co=0
+silent! source ~/.exrc
diff --git a/vim/vimrc.stub.vim b/vim/vimrc.stub.vim
deleted file mode 100644
index 1d8d3d9a..00000000
--- a/vim/vimrc.stub.vim
+++ /dev/null
@@ -1,11 +0,0 @@
-" If we have non-tiny Vim version >=7, source real vimrc; this works because
-" tiny and/or ancient builds of Vim quietly ignore all code in :if blocks
-if v:version >= 700 && !&compatible
- runtime vimrc
- finish
-endif
-
-" Otherwise, prevent an old and/or tiny Vim from using any part of our
-" configuration, because parts of it will break
-set runtimepath-=~/.vim
-set runtimepath-=~/.vim/after