aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim')
-rw-r--r--vim/after/ftplugin/gitcommit.vim16
-rw-r--r--vim/after/ftplugin/html.vim2
-rw-r--r--vim/after/ftplugin/mail.vim16
-rw-r--r--vim/after/ftplugin/vim.vim6
-rw-r--r--vim/after/plugin/2html.vim11
-rw-r--r--vim/after/plugin/spellfile_local.vim13
-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.vim2
-rw-r--r--vim/autoload/argument.vim8
-rw-r--r--vim/autoload/diff.vim2
-rw-r--r--vim/autoload/filetype/repeat.vim2
-rw-r--r--vim/autoload/fortune.vim59
-rw-r--r--vim/autoload/getenv.vim17
-rw-r--r--vim/autoload/html/timestamp.vim2
-rw-r--r--vim/autoload/mail.vim4
-rw-r--r--vim/autoload/mail/header/field.vim2
-rw-r--r--vim/autoload/option.vim8
-rw-r--r--vim/autoload/path.vim14
-rw-r--r--vim/autoload/put_date.vim24
-rw-r--r--vim/autoload/quote.vim4
-rw-r--r--vim/autoload/xdg.vim61
m---------vim/bundle/cursorline_current0
m---------vim/bundle/detect_indent0
m---------vim/bundle/paste_insert0
m---------vim/bundle/put_date0
m---------vim/bundle/spellfile_local0
m---------vim/bundle/squeeze_repeat_blanks0
m---------vim/bundle/undofileskip0
-rw-r--r--vim/filetype.vim46
-rw-r--r--vim/ftplugin/csv.vim2
-rw-r--r--vim/ftplugin/mail.vim15
-rw-r--r--vim/ftplugin/markdown.vim2
-rw-r--r--vim/plugin/2html.vim1
-rw-r--r--vim/plugin/fortune.vim4
-rw-r--r--vim/plugin/put_date.vim6
-rw-r--r--vim/vimrc537
-rw-r--r--vim/vimrc.stub15
40 files changed, 559 insertions, 367 deletions
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 7e2ba439..21a84a42 100644
--- a/vim/after/ftplugin/html.vim
+++ b/vim/after/ftplugin/html.vim
@@ -4,7 +4,7 @@ if &filetype !=# 'html'
finish
endif
-" Spellcheck documents we're actually editing (not just viewing)
+" Check the spelling of documents we're actually editing (not just viewing)
if &modifiable && !&readonly
setlocal spell
let b:undo_ftplugin .= '|setlocal spell<'
diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim
index 738f17ec..4c07bac3 100644
--- a/vim/after/ftplugin/mail.vim
+++ b/vim/after/ftplugin/mail.vim
@@ -1,3 +1,13 @@
+" 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
@@ -8,7 +18,7 @@ command -bar -buffer SuggestStart
let b:undo_ftplugin .= '|delcommand SuggestStart'
SuggestStart
-" Normalise quoting
+" Normalize quoting
command -bar -buffer -range=% StrictQuote
\ call mail#StrictQuote(<q-line1>, <q-line2>)
let b:undo_ftplugin .= '|delcommand StrictQuote'
@@ -66,9 +76,9 @@ let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q'
\ . '|xunmap <buffer> <LocalLeader>Q'
" Mappings for enforcing strict quoting
-nnoremap <LocalLeader>s
+nnoremap <buffer> <LocalLeader>s
\ :StrictQuote<CR>
-xnoremap <LocalLeader>s
+xnoremap <buffer> <LocalLeader>s
\ :StrictQuote<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>s'
\ . '|xunmap <buffer> <LocalLeader>s'
diff --git a/vim/after/ftplugin/vim.vim b/vim/after/ftplugin/vim.vim
index 01f971b9..112523da 100644
--- a/vim/after/ftplugin/vim.vim
+++ b/vim/after/ftplugin/vim.vim
@@ -26,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/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/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/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 438ce596..bd7d8274 100644
--- a/vim/after/syntax/vim.vim
+++ b/vim/after/syntax/vim.vim
@@ -4,7 +4,7 @@ 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/argument.vim b/vim/autoload/argument.vim
deleted file mode 100644
index 85d75eb1..00000000
--- a/vim/autoload/argument.vim
+++ /dev/null
@@ -1,8 +0,0 @@
-" Escape a single argument for use on an Ex command line; essentially
-" a backport of fnameescape() for versions before v7.1.299
-"
-function! argument#Escape(argument) abort
- return exists('*fnameescape')
- \ ? fnameescape(a:argument)
- \ : escape(a:argument, "\n\r\t".' *?[{`$\%#''"|!<')
-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/repeat.vim b/vim/autoload/filetype/repeat.vim
index f681932b..899bbcc4 100644
--- a/vim/autoload/filetype/repeat.vim
+++ b/vim/autoload/filetype/repeat.vim
@@ -53,7 +53,7 @@ function! filetype#repeat#Sudo() 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/fortune.vim b/vim/autoload/fortune.vim
deleted file mode 100644
index da6e2fa3..00000000
--- a/vim/autoload/fortune.vim
+++ /dev/null
@@ -1,59 +0,0 @@
-" Declare paths to check for fortune files
-let s:paths = [
- \ $HOME.'/.fortunes',
- \ $HOME.'/.local/share/games/fortunes',
- \]
-
-" List of executables for which we need to check
-let s:executables = [
- \ 'fortune',
- \ 'timeout',
- \]
-
-" Entry point for plugin
-function! fortune#() abort
-
- " Check we have all of the executables we need
- for executable in s:executables
- if !executable(executable)
- echoerr 'Missing executable "'.executable.'"'
- endif
- endfor
-
- " Maximum length of fortunes is the width of the screen minus 1; characters
- " wider than one column will break this
- "
- let limit = &columns - 1
-
- " Some implementations of fortune(6) thrash the disk if they can't meet the
- " length limit, so we need to rap this invocation in a timeout(1) call
- let command = [
- \ 'timeout',
- \ '0.3s',
- \ 'fortune',
- \ '-s',
- \ '-n',
- \ limit,
- \]
-
- " Find a path for custom fortunes and add it on to the command if found
- for path in s:paths
- if isdirectory(path)
- call add(command, path)
- break
- endif
- endfor
-
- " Run the command and condense any control or space character groups into
- " just one space
- let fortune = substitute(
- \ system(join(command)),
- \ '[[:cntrl:][:space:]]\+',
- \ ' ',
- \ 'g',
- \)
-
- " Show the fortune message!
- echomsg fortune
-
-endfunction
diff --git a/vim/autoload/getenv.vim b/vim/autoload/getenv.vim
new file mode 100644
index 00000000..3b5f4c1b
--- /dev/null
+++ b/vim/autoload/getenv.vim
@@ -0,0 +1,17 @@
+" Backport getenv() from v8.1.1305, except return an empty string rather than
+" v:null
+"
+" <https://github.com/vim/vim/releases/tag/v8.1.1305>
+"
+function! getenv#(name) abort
+
+ if a:name !~# '^[A-Z][A-Z0-9_]*$'
+ throw 'Illegal env var name'
+ endif
+ let value = ''
+ if exists('$'.a:name)
+ execute 'let value = $'.a:name
+ endif
+ return value
+
+endfunction
diff --git a/vim/autoload/html/timestamp.vim b/vim/autoload/html/timestamp.vim
index 9de19aa0..6d525afb 100644
--- a/vim/autoload/html/timestamp.vim
+++ b/vim/autoload/html/timestamp.vim
@@ -69,6 +69,6 @@ function! html#timestamp#Update() abort
" Apply the updated timestamp
let line = getline(lnum)
let line = substitute(line, s:pattern, update, '')
- call setline(lnum, line)
+ keepjumps call setline(lnum, line)
endfunction
diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim
index cd585af4..6d4874ca 100644
--- a/vim/autoload/mail.vim
+++ b/vim/autoload/mail.vim
@@ -1,7 +1,7 @@
" 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
@@ -61,7 +61,7 @@ function! mail#StrictQuote(start, end) abort
continue
endif
- " Normalise the quote with no spaces
+ " Normalize the quote with no spaces
let quote = substitute(quote, '[^>]', '', 'g')
" Re-set the line
diff --git a/vim/autoload/mail/header/field.vim b/vim/autoload/mail/header/field.vim
index e27d13c0..db38c09f 100644
--- a/vim/autoload/mail/header/field.vim
+++ b/vim/autoload/mail/header/field.vim
@@ -9,7 +9,7 @@ function! mail#header#field#Add(header, name, body) abort
endfunction
" Set a field in a header, replacing the first one with the same name (if
-" any), and and removing any others
+" any), and removing any others
"
function! mail#header#field#Set(header, name, body) abort
let fields = []
diff --git a/vim/autoload/option.vim b/vim/autoload/option.vim
index 5ff44ced..49fbf1a4 100644
--- a/vim/autoload/option.vim
+++ b/vim/autoload/option.vim
@@ -7,5 +7,11 @@ function! option#Split(expr, ...) abort
endif
let keepempty = a:0 ? a:1 : 0
let parts = split(a:expr, '\\\@<!,[, ]*', keepempty)
- return map(parts, 'substitute(v:val, ''\\,'', '','', ''g'')')
+ 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/path.vim b/vim/autoload/path.vim
deleted file mode 100644
index e230cab2..00000000
--- a/vim/autoload/path.vim
+++ /dev/null
@@ -1,14 +0,0 @@
-" Create all the directories needed for a path, with optional flag for
-" owner-only permissions
-function! path#Create(name, ...) abort
- if a:0 > 2
- echoerr 'Too many arguments'
- endif
- if isdirectory(a:name)
- return 1
- endif
- let name = a:name
- let path = 'p'
- let prot = a:0 == 1 && a:1 ? 0700 : 0755
- return mkdir(name, path, prot)
-endfunction
diff --git a/vim/autoload/put_date.vim b/vim/autoload/put_date.vim
deleted file mode 100644
index b0b0b548..00000000
--- a/vim/autoload/put_date.vim
+++ /dev/null
@@ -1,24 +0,0 @@
-" RFC2822 format string for strftime()
-let s:rfc_2822 = '%a, %d %b %Y %T %z'
-
-" Write a date to the buffer, UTC or local, in the specified format,
-" defaulting to RFC2822; formats are provided without the leading % signs
-" before each letter, like PHP date()
-"
-function! put_date#(line, utc, format) abort
- let line = a:line
- let utc = a:utc
- let format = strlen(a:format)
- \ ? substitute(a:format, '\a', '%&', 'g')
- \ : s:rfc_2822
- if utc
- if exists('$TZ')
- let tz = $TZ
- endif
- let $TZ = 'UTC'
- endif
- execute line.'put =strftime(format)'
- if exists('tz')
- let $TZ = tz
- endif
-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/xdg.vim b/vim/autoload/xdg.vim
new file mode 100644
index 00000000..c5737506
--- /dev/null
+++ b/vim/autoload/xdg.vim
@@ -0,0 +1,61 @@
+" <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',
+ \}
+
+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 = getenv#(name)
+ return value !=# ''
+ \ ? value
+ \ : s:defaults[name]
+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 s:Home('XDG_CACHE_HOME')
+endfunction
+
+function! xdg#ConfigHome() abort
+ return s:Home('XDG_CONFIG_HOME')
+endfunction
+
+function! xdg#DataHome() abort
+ return s:Home('XDG_DATA_HOME')
+endfunction
+
+function! xdg#ConfigDirs() abort
+ return s:Dirs('XDG_CONFIG_DIRS')
+endfunction
+
+function! xdg#DataDirs() abort
+ return s:Dirs('XDG_DATA_DIRS')
+endfunction
diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current
-Subproject 4ab61f5dfa9a2868c529c75a50219dac6619080
+Subproject d1b8db2fe6b06bd556c777c7bd9d4632f12a3a1
diff --git a/vim/bundle/detect_indent b/vim/bundle/detect_indent
new file mode 160000
+Subproject b41d085cdcaf1f957b2c219630f332023baba72
diff --git a/vim/bundle/paste_insert b/vim/bundle/paste_insert
-Subproject 0365dd11c050f885050cd6dd22405c81aba5f46
+Subproject 1ffcb96611315dd068b734d5aae7ff07fa2b3a2
diff --git a/vim/bundle/put_date b/vim/bundle/put_date
new file mode 160000
+Subproject 598090797c2cb3a4fe945d2eacd3eca42a0cfe5
diff --git a/vim/bundle/spellfile_local b/vim/bundle/spellfile_local
-Subproject 16dbdc90b39c1ebf43ca1881a493edc816d2d9f
+Subproject 8772445433cffa3722c441569ae82f5ade4938c
diff --git a/vim/bundle/squeeze_repeat_blanks b/vim/bundle/squeeze_repeat_blanks
-Subproject 8c849183f8723086e6b61a0644292bdb1ad99c1
+Subproject 27dd1b5858b4839b34249c106d2b3963a3da416
diff --git a/vim/bundle/undofileskip b/vim/bundle/undofileskip
new file mode 160000
+Subproject 1d0a5cf3aa1bf1f360862819d229d756958df32
diff --git a/vim/filetype.vim b/vim/filetype.vim
index 137d1cf5..4ecc7aab 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -107,6 +107,7 @@ augroup filetypedetect
\,.gitconfig
\,.gitmodules
\,gitconfig
+ \,~/.config/git/config
\ setfiletype gitconfig
" Git rebase manifests
autocmd BufNewFile,BufRead
@@ -170,6 +171,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
@@ -190,10 +196,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
@@ -208,7 +219,8 @@ augroup filetypedetect
" Mutt configuration files
autocmd BufNewFile,BufRead
\ Muttrc
- \,*/.muttrc.d/*.rc
+ \,*/.muttrc.d/?*.rc
+ \,*/muttrc.d/?*.rc
\,.muttrc
\,muttrc
\,/etc/Muttrc.d/*
@@ -244,6 +256,10 @@ augroup filetypedetect
\,/etc/shadow-
\,/etc/shadow.edit
\ setfiletype passwd
+ " Packet capture files
+ autocmd BufNewFile,BufRead
+ \ ?*.pcap
+ \ setfiletype pcap
" Perl 5 files
autocmd BufNewFile,BufRead
\ ?*.pl
@@ -270,6 +286,15 @@ 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
@@ -297,6 +322,10 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.rb
\ setfiletype ruby
+ " Samba config
+ autocmd BufNewFile,BufRead
+ \ smb.conf
+ \ setfiletype samba
" sed files
autocmd BufNewFile,BufRead
\ ?*.sed
@@ -365,6 +394,11 @@ augroup filetypedetect
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/*.*
@@ -395,7 +429,7 @@ augroup filetypedetect
autocmd BufNewFile,BufRead
\ ?*.tsv
\ setfiletype tsv
- " VimL files
+ " Vim script files
autocmd BufNewFile,BufRead
\ ?*.vim
\,.exrc
@@ -416,7 +450,7 @@ 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/*
@@ -455,8 +489,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/?*
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 3f41cf8d..ddd88e2c 100644
--- a/vim/ftplugin/markdown.vim
+++ b/vim/ftplugin/markdown.vim
@@ -56,7 +56,7 @@ xnoremap <buffer> <expr> <LocalLeader>Q
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q'
\ . '|xunmap <buffer> <LocalLeader>Q'
-" Autoformat headings
+" Automatically format headings
command -buffer -nargs=1 MarkdownHeading
\ call markdown#Heading(<f-args>)
nnoremap <buffer> <LocalLeader>=
diff --git a/vim/plugin/2html.vim b/vim/plugin/2html.vim
deleted file mode 100644
index 95dcbb6c..00000000
--- a/vim/plugin/2html.vim
+++ /dev/null
@@ -1 +0,0 @@
-let g:html_font = ['DejaVu Sans Mono', 'Ubuntu Mono', 'Consolas']
diff --git a/vim/plugin/fortune.vim b/vim/plugin/fortune.vim
deleted file mode 100644
index efc03467..00000000
--- a/vim/plugin/fortune.vim
+++ /dev/null
@@ -1,4 +0,0 @@
-command! -bar Fortune
- \ call fortune#()
-nnoremap <silent> <Plug>(Fortune)
- \ :<C-U>Fortune<CR>
diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim
deleted file mode 100644
index 7848e95f..00000000
--- a/vim/plugin/put_date.vim
+++ /dev/null
@@ -1,6 +0,0 @@
-if exists('loaded_put_date') || &compatible || !exists('*strftime')
- finish
-endif
-let loaded_put_date = 1
-command! -bang -bar -nargs=* -range PutDate
- \ call put_date#(<q-line1>, <q-bang> ==# '!', <q-args>)
diff --git a/vim/vimrc b/vim/vimrc
index 2328bb11..f276cb92 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -2,7 +2,7 @@
" Tom Ryder (tejr)’s Literate Vimrc
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
"
-" Last updated: Thu, 19 Dec 2019 17:07:46 +1300
+" Last updated: Wed, 10 Jun 2020 22:41:57 UTC
"
" │ And I was lifted up in heart, and thought
" │ Of all my late-shown prowess in the lists,
@@ -11,130 +11,186 @@
" │ 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
"
+" —Tennyson
+"
+" │ your vimrc is better than the bible
+"
+" —@polanco@mastodon.sdf.org
+" <https://mastodon.sdf.org/@polanco/104069285780040986>
+"
+
" This file is an attempt at something like a “literate vimrc”, in the
" tradition of Donald Knuth’s “literate programming”:
" <http://www.literateprogramming.com/>
"
-" The dotfiles project that comprises it is maintained here:
+" The dotfiles project as part of which it is maintained is here:
" <https://sanctum.geek.nz/cgit/dotfiles.git>
"
-" This is a long file, and comments abound within. Should this be bothersome,
-" one could execute this command in Vim itself to strip out all lines either
-" blank or comprising solely comments:
+" 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:
"
" :g/\m^$\|^\s*"/d
"
-" This file should be saved as ‘vimrc’—no leading period—in the user runtime
-" directory. On Unix-like operating systems, hereinafter referred to as
-" “*nix”, that directory is ‘~/.vim’; on Windows, it’s ‘~/vimfiles’.
-" Fortunately, those are the only two kinds of operating systems that exist,
-" anywhere in the world.
-"
-" It requires Vim v7.0.0 or newer, with the +eval feature, and the
-" 'compatible' option turned off, chiefly to allow line continuations. The
-" vimrc stub at ~/.vimrc (Unix) or ~/_vimrc (Windows) should check that these
-" conditions are met before loading this file with ‘:runtime vimrc’.
-"
-" All of this should survive a pass of the Vim script linter Vint with no
-" errors, warnings, or style problems: <https://github.com/Kuniwak/vint>
-"
-
-" We’ll begin by making sure that we and Vim are speaking the same language.
-" Since it’s been the future for a few years now, this file has characters
-" outside the ASCII character set, which prompts Vint to suggest declaring the
-" file encoding with a :scriptencoding command. The :help for that command
-" specifies that this should be done after 'encoding' is set, so we’ll do that
-" here, too.
-"
-" On *nix, I define the primary locale environment variable $LANG, almost
-" always specifying a multibyte locale. This informs Vim’s choice of internal
-" character encoding, but the default for the 'encoding' option in the absence
-" of a valid $LANG is ‘latin1’. Since this is almost never what I want, we’ll
-" manually choose the UTF-8 encoding for Unicode in the absence of any other
-" explicit specification.
-"
-if &encoding ==# 'latin1' && !exists('$LANG')
- set encoding=utf-8
+" 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.
+"
+" The Vim script linter Vint should raise no errors, warnings, or style
+" problems with this file. <https://github.com/Kuniwak/vint>
+"
+
+" 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:
+"
+" │ vim/vimrc:1:1: Use scriptencoding when multibyte char exists (see :help
+" │ :scriptencoding)
+"
+" Furthermore, the :help for :scriptencoding specifies that :scriptencoding
+" should be set *after* 'encoding'.
+"
+" 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.
+"
+" 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.
+"
+" <https://github.com/vim/vim/releases/tag/v8.1.0733>
+"
+if has#('multi_byte')
+ if &encoding ==# 'latin1' && !exists('$LANG')
+ set encoding=utf-8
+ endif
+ scriptencoding utf-8
endif
-scriptencoding utf-8
" 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. I’d like to do this as
-" accurately as possible, even with Vim’s unusual behavior around escaping of
-" these variables. One of the first things we’ll need to be able to do is
-" split the value of 'runtimepath' into its constituent path parts.
-"
-" Splitting the values of comma-separated options 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
+" 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
"
" We don’t, however, have to deal with backslashes before other backslashes,
-" nor before 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. Vim,
-" I love you, but you are really weird sometimes.
-"
-" We do all this with an autoloaded function option#Split().
-"
-" If an environment variable MYVIM exists, and it isn’t blank, apply its value
-" as the first value of 'runtimepath', after escaping it appropriately.
-" Otherwise, do it the other way around: the first path in the 'runtimepath'
-" list becomes MYVIM.
-"
-if exists('$MYVIM') && $MYVIM !=# ''
- execute 'set runtimepath^='.argument#Escape(option#item#Escape($MYVIM, 1))
-elseif &runtimepath !=# ''
- let $MYVIM = option#Split(&runtimepath)[0]
-endif
-
-" We need a command to reliably establish a full path, whether or not the
-" directories already exist. We create a wrapper for the autoloaded function
-" path#Create() with similar calling conventions to mkdir(), but with the ‘p’
-" value for the second parameter {prot} forced on. Calling it with a bang
-" like :CreatePath! creates a private directory (permissions 0700).
+" 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.
"
-command! -bang -bar -complete=dir -nargs=1 CreatePath
- \ call path#Create(expand(<q-args>), <q-bang> ==# '!')
-
-" Now that we have a way 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.
+" Vim, I do love you, but sometimes you're really weird.
+"
+" 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 &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:xdgcachehome = xdg#CacheHome()
+let s:xdgconfigdirs = xdg#ConfigDirs()
+let s:xdgconfighome = xdg#ConfigHome()
+let s:xdgdatadirs = xdg#DataDirs()
+let s:xdgdatahome = xdg#DataHome()
+
+" 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
+
" 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 own 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', but that’s still 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.
"
-execute 'set viminfo+='.argument#Escape('n'.$MYVIM.'/viminfo')
-CreatePath $MYVIM
+if s:xdgcachehome !=# ''
+ if !isdirectory(s:xdgcachehome)
+ call mkdir(s:xdgcachehome, 'p', 0700)
+ endif
+ execute 'set viminfo+='.option#Escape(
+ \ 'n'.s:xdgcachehome.'/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 stingy. Because I don’t
@@ -179,10 +235,14 @@ set history=10000
" 'backupfullname', 'swapfilefullname' would have been clearer.
"
set backup
-execute 'set backupdir^='.argument#Escape(option#item#Escape(
- \ $MYVIM.'/backup'.(has#('patch-8.1.251') ? '//' : ''),
- \))
-CreatePath! $MYVIM/backup
+if s:xdgcachehome !=# ''
+ if !isdirectory(s:xdgcachehome.'/backup')
+ call mkdir(s:xdgcachehome.'/backup', 'p', 0700)
+ endif
+ execute 'set backupdir^='.option#Escape(option#item#Escape(
+ \ s:xdgcachehome.'/backup'.(has#('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
@@ -215,31 +275,51 @@ endif
" 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 path#Create() to attempt to create the path, if needed.
+" option has supported that hint for much longer than 'backupdir' has.
"
-execute 'set directory^='
- \.argument#Escape(option#item#Escape($MYVIM.'/swap//'))
-CreatePath! $MYVIM/swap
+if s:xdgcachehome !=# ''
+ if !isdirectory(s:xdgcachehome.'/swap')
+ call mkdir(s:xdgcachehome.'/swap', 'p', 0700)
+ endif
+ execute 'set directory^='.option#Escape(option#item#Escape(
+ \ s:xdgcachehome.'/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')
+if s:xdgcachehome !=# '' && has#('persistent_undo')
set undofile
- execute 'set undodir^='
- \.argument#Escape(option#item#Escape($MYVIM.'/undo//'))
- CreatePath! $MYVIM/undo
+ if !isdirectory(s:xdgcachehome.'/undo')
+ call mkdir(s:xdgcachehome.'/undo', 'p', 0700)
+ endif
+ execute 'set undodir^='.option#Escape(option#item#Escape(
+ \ s:xdgcachehome.'/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:xdgcachehome !=# '' && has#('mksession')
+ if !isdirectory(s:xdgcachehome.'/view')
+ call mkdir(s:xdgcachehome.'/view', 'p', 0700)
+ endif
+ execute 'set viewdir='.option#Escape(option#item#Escape(
+ \ s:xdgcachehome.'/view'
+ \))
endif
" Now that we have a bit more confidence in our runtime environment, set up
@@ -250,7 +330,7 @@ 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.
+" an autloaded function backing it.
"
command! -bar ReloadFileType
\ call reload#FileType()
@@ -265,10 +345,6 @@ command! -bar ReloadFileType
" define the new command wrapper around an autoloaded function that itself
" issues 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!
-"
command! -bar ReloadVimrc
\ call reload#Vimrc()
@@ -285,8 +361,12 @@ augroup END
" 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
+autocmd vimrc BufWritePost $MYVIMRC
\ ReloadVimrc
+if $MYVIM !=# ''
+ autocmd vimrc BufWritePost $MYVIM/vimrc
+ \ doautocmd vimrc BufWritePost $MYVIMRC
+endif
" 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
@@ -296,8 +376,12 @@ autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc
" <https://github.com/vim/vim/releases/tag/v7.0.187>
"
if exists('##SourceCmd')
- autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc
+ autocmd vimrc SourceCmd $MYVIMRC
\ ReloadVimrc
+ if $MYVIM !=# ''
+ autocmd vimrc SourceCmd $MYVIM/vimrc
+ \ doautocmd vimrc SourceCmd $MYVIMRC
+ endif
endif
" For spelling, use New Zealand English by default, but later on we’ll
@@ -317,6 +401,17 @@ set spelllang=en_nz
"
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
" system word list. This makes the dictionary completion work consistently,
@@ -335,33 +430,38 @@ set spellcapcheck=[.?!]\\%(\ \ \\\|[\\n\\r\\t]\\)
" 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
-" expected Vim error code here, and if the MYVIM path offends, we just skip
-" the setting entirely, rather than throwing cryptic errors at the user. None
-" of the blacklisted characters are particularly wise characters to have in
-" paths, anyway, legal though they may be on Unix filesystems. We can’t work
-" around this one with 'isfname'; the blacklist is hard-coded.
+" 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.
+"
+" Extra checks for appending the 'dictionary' and 'thesaurus' paths 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 expected Vim
+" error code here, and if the path offends, we just skip the setting entirely,
+" rather than throwing cryptic errors at the user. None of the blacklisted
+" characters are particularly wise characters to have in paths, anyway, legal
+" though they may be on Unix filesystems. We can’t work around this one with
+" 'isfname'; the blacklist is hard-coded.
"
set dictionary^=/usr/share/dict/words
-let s:ref = $MYVIM.'/ref'
-try
- execute 'set dictionary^='
- \.argument#Escape(option#item#Escape(s:ref.'/dictionary.txt'))
- execute 'set thesaurus^='
- \.argument#Escape(option#item#Escape(s:ref.'/thesaurus.txt'))
-catch /^Vim\%((\a\+)\)\=:E474:/
-endtry
+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'')'
+ \), ','))
+ 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
" language-specific defaults.
@@ -479,7 +579,7 @@ set foldlevel=256
" 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
+" 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
@@ -860,9 +960,9 @@ endif
" 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.
+" 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>
"
@@ -873,7 +973,7 @@ autocmd vimrc ColorScheme *
" environment variable COLORFGBG or a response in v:termrbgresp that would set
" it specifically.
"
-if !exists('$COLORFGBG') && get(v:, 'termrbgresp', '') ==# ''
+if !exists('$COLORFGBG') && !get(v:, 'termrbgresp')
set background=dark
endif
@@ -906,7 +1006,7 @@ endif
" 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.
@@ -926,7 +1026,8 @@ endif
" alternate buffer. User nickspoons of #vim was incredulous that I had never
" used CTRL-^ and indeed did not know about it. I have since repented.
"
-nnoremap <Backspace> <C-^>
+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
@@ -937,8 +1038,8 @@ nnoremap <Backspace> <C-^>
"
nnoremap <expr> <Space>
\ line('w$') < line('$')
- \ ? "\<PageDown>"
- \ : ":\<C-U>next\<CR>"
+ \ ? "\<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
@@ -977,7 +1078,8 @@ nnoremap <expr> <Space>
" uselessness.
"
if plugin#Ready('insert_cancel')
- imap <C-C> <Plug>(InsertCancel)
+ imap <C-C>
+ \ <Plug>(InsertCancel)
endif
" I often can’t remember (or guess) digraph codes, and want to look up how to
@@ -1011,7 +1113,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
@@ -1034,14 +1137,16 @@ 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
" previous :substitute command doesn’t preserve the flags from that
@@ -1060,7 +1165,8 @@ sunmap &
"
" <https://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
@@ -1096,8 +1202,10 @@ nnoremap ]l
"
" <https://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
@@ -1118,7 +1226,8 @@ let maplocalleader = ','
" relying on mapping 'timeout'.
"
if maplocalleader ==# ','
- noremap ,, ,
+ noremap ,,
+ \ ,
sunmap ,,
endif
@@ -1188,7 +1297,7 @@ nnoremap <Leader>f
" 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.
"
nnoremap <Leader>z
@@ -1213,7 +1322,8 @@ nnoremap <Leader>u
"
"" 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
@@ -1237,7 +1347,8 @@ sunmap <Leader>L
" 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
@@ -1264,8 +1375,7 @@ nnoremap <Leader>D
\ :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 :CreatePath command created earlier.
+" relative to the current buffer.
"" Leader,g shows the current file’s fully expanded path
nnoremap <Leader>g
@@ -1275,7 +1385,7 @@ nnoremap <Leader>G
\ :<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>CreatePath %: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.
@@ -1339,7 +1449,8 @@ nnoremap <Leader>j
" <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)
+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:
@@ -1380,7 +1491,8 @@ onoremap <Leader>_
"" Leader,% or Leader,5 uses entire buffer as an object
onoremap <Leader>%
\ :<C-U>execute 'normal! 1GVG'<CR>
-omap <Leader>5 <Leader>%
+omap <Leader>5
+ \ <Leader>%
" This group defines some useful motions, including navigating by indent
" block using a custom plugin:
@@ -1389,12 +1501,15 @@ omap <Leader>5 <Leader>%
"
"" 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>\ `"
+noremap <Leader>\
+ \ `"
sunmap <Leader>\
" This group does both: useful motions on defined text objects.
@@ -1428,40 +1543,45 @@ nnoremap <Leader>?
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
-map <Leader>r <Plug>(ReplaceOperator)
+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 altenate filetype
-nmap <Leader># <Plug>(AlternateFileType)
-nmap <Leader>3 <Leader>#
-"" Leader,$/4 gives me my fortune
-nmap <Leader>$ <Plug>(Fortune)
-nmap <Leader>4 <Leader>$
+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)
+map <Leader>&
+ \ <Plug>(RegexEscape)
ounmap <Leader>&
sunmap <Leader>&
-map <Leader>7 <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 <silent> <Leader>*
- \ :<C-U>let @/ = expand('<cword>')<CR>:let &hlsearch = &hlsearch<CR>
-nmap <Leader>8 <Leader>*
+nnoremap <Leader>*
+ \ :<C-U>let @/ = expand('<cword>') <Bar> let &hlsearch = &hlsearch<CR>
+nmap <Leader>8
+ \ <Leader>*
"" Leader,` opens a scratch buffer, horizontally split
-nnoremap <silent> <Leader>`
+nnoremap <Leader>`
\ :<C-U>ScratchBuffer<CR>
"" Leader,~ opens a scratch buffer, vertically split
-nnoremap <silent> <Leader>~
+nnoremap <Leader>~
\ :<C-U>vertical ScratchBuffer<CR>
" And last, but definitely not least, I’m required by Vim fanatic law to
@@ -1478,17 +1598,24 @@ 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 THe
+ \ The
+inoreabbrev THere
+ \ There
" Here endeth the literate vimrc. Let us praise God.
"
diff --git a/vim/vimrc.stub b/vim/vimrc.stub
index d50cee55..f9ad4d4f 100644
--- a/vim/vimrc.stub
+++ b/vim/vimrc.stub
@@ -1,13 +1,16 @@
" 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.
+" calls for the same, that we’re running Vim v7.0.0 or newer, and that we
+" haven't been invoked as just plain `vi`. 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') && v:version >= 700
- runtime vimrc
- finish
+if !&compatible && !exists('$POSIXLY_CORRECT')
+ if v:version >=700 && v:progname !=# 'vi'
+ runtime vimrc
+ finish
+ endif
endif
" If we got this far, it means we’re running a tiny, 'compatible', and/or