aboutsummaryrefslogtreecommitdiff
path: root/vim/vimrc
diff options
context:
space:
mode:
Diffstat (limited to 'vim/vimrc')
-rw-r--r--vim/vimrc517
1 files changed, 314 insertions, 203 deletions
diff --git a/vim/vimrc b/vim/vimrc
index 2328bb11..470b4cb1 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: Mon, 01 Jun 2020 21:38:45 UTC
"
" │ And I was lifted up in heart, and thought
" │ Of all my late-shown prowess in the lists,
@@ -14,127 +14,178 @@
" │
" │ —Tennyson
"
+
" 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 +230,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 +270,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 +325,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 +340,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 +356,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 +371,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
@@ -335,33 +414,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 +563,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 +944,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 +957,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 +990,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 +1010,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 +1022,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 +1062,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 +1097,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 +1121,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 +1149,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 +1186,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 +1210,8 @@ let maplocalleader = ','
" relying on mapping 'timeout'.
"
if maplocalleader ==# ','
- noremap ,, ,
+ noremap ,,
+ \ ,
sunmap ,,
endif
@@ -1188,7 +1281,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 +1306,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 +1331,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 +1359,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 +1369,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 +1433,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 +1475,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 +1485,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 +1527,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 +1582,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.
"