From c66d1ccae80db91cc91d9a63c3d5900615cea379 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 16:39:29 +1200 Subject: Join some lines that don't really need to be split --- vim/vimrc | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 1dcd3eaa..eb835930 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -60,9 +60,7 @@ set cpoptions+=J set dictionary^=/usr/share/dict/words " Keep swap files in dedicated directory, named with full path -execute 'set directory^='.vimrc#EscapeSetPart( - \ $MYVIM.'/cache/swap//' - \ ) +execute 'set directory^='.vimrc#EscapeSetPart($MYVIM.'/cache/swap//') call vimrc#Establish(&directory) " If the environment didn't set an encoding, use UTF-8, not ASCII @@ -170,9 +168,7 @@ set splitright " Right of the current window, not left set synmaxcol=500 " Add thesaurus; install with `make install-vim-thesaurus` -execute 'set thesaurus^='.vimrc#EscapeSetPart( - \ $MYVIM.'/ref/thesaurus.txt' - \ ) +execute 'set thesaurus^='.vimrc#EscapeSetPart($MYVIM.'/ref/thesaurus.txt') " PuTTY is a fast terminal, but Vim doesn't know that yet if &term =~# '^putty' @@ -188,9 +184,7 @@ endif " Keep persistent undo files in dedicated directory, named with full path if has('persistent_undo') " v7.2.438 set undofile - execute 'set undodir^='.vimrc#EscapeSetPart( - \ $MYVIM.'/cache/undo//' - \ ) + execute 'set undodir^='.vimrc#EscapeSetPart($MYVIM.'/cache/undo//') call vimrc#Establish(&undodir) endif @@ -199,9 +193,7 @@ endif if exists('+viminfofile') " Use new option method if we can (v8.1.716) set viminfofile=$MYVIM/cache/viminfo else " Resort to clunkier method with 'viminfo' option flag - execute 'set viminfo+='.vimrc#EscapeSet( - \ 'n'.$MYVIM.'/cache/viminfo' - \ ) + execute 'set viminfo+='.vimrc#EscapeSet('n'.$MYVIM.'/cache/viminfo') endif " Let me move beyond buffer text in visual block mode -- cgit v1.2.3 From fa48f50f0669b3e1ce4f1aabb66942b0e2df2541 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 16:41:40 +1200 Subject: Strip trailing slashes before patch establishment --- vim/autoload/vimrc.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 57c2f0f4..65e13af7 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -15,7 +15,7 @@ endfunction " to create it if it doesn't. Strip double-trailing-slash hints. function! vimrc#Establish(string) abort let part = vimrc#SplitOption(a:string)[0] - let part = substitute(part, '//$', '', '') + let part = substitute(part, '/\+$', '', '') let dirname = expand(part) return isdirectory(dirname) \ || mkdir(dirname, 'p') -- cgit v1.2.3 From f724e28a3b92dd0f60a17207e299d1d80c81d3be Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:40:54 +1200 Subject: Flesh out comments and refactor vimrc auto funcs --- vim/autoload/vimrc.vim | 82 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index 65e13af7..eccdbf95 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -1,39 +1,73 @@ -" Escape a text value for :execute-based :set inclusion in an option +" Utility functions for use in .vim/vimrc only + +" Escape a text value for :execute-based :set inclusion as an option value function! vimrc#EscapeSet(string) abort + + " Escape all the characters that `:help option-backslash` warns us about return escape(a:string, '\ |"') + endfunction -" Escape a text value for inclusion as an element in a comma-separated list -" option. Yes, the comma being the sole inner escaped character here is -" correct. No, we shouldn't escape backslash itself. Yes, that means it's -" impossible to have the literal string '\,' in a part. +" Escape a text value for :execute-based :set inclusion as an element in +" a comma-separated option value function! vimrc#EscapeSetPart(string) abort + + " Message to future Tom: yes, the comma being the sole inner escaped + " character here is correct. No, we shouldn't escape backslash itself. + " Yes, that means it's impossible to have the literal string '\,' in a part. + " Yes, this reflects what Vim does internally. Read the source of + " copy_option_part() in vim/src/misc2.c to confirm. return vimrc#EscapeSet(escape(a:string, ',')) + endfunction " Expand the first path in an option string, check if it exists, and attempt " to create it if it doesn't. Strip double-trailing-slash hints. function! vimrc#Establish(string) abort + + " Get first part of the option string let part = vimrc#SplitOption(a:string)[0] + + " Remove any trailing slashes; neither expand() nor mkdir() seems bothered, + " at least on Unix, but let's be tidy anyway let part = substitute(part, '/\+$', '', '') + + " Expand the directory name to replace tildes with the home directory, but + " it still may not necessarily be an absolute path let dirname = expand(part) + + " Return either the confirmed presence of the directory, or failing that, + " the result of an attempt to create it return isdirectory(dirname) \ || mkdir(dirname, 'p') + endfunction " Check that we have a plugin available, and will be loading it function! vimrc#PluginReady(filename) abort - return globpath(&runtimepath, 'plugin/'.a:filename.'.vim') !=# '' + + " Return whether the given filename with a .vim extension is present in + " a subdirectory named 'plugin', and that the 'loadplugins' option is on, + " implying that Vim will at least attempt to load it + let path = 'plugin/'.a:filename.'.vim' + return globpath(&runtimepath, path) !=# '' \ && &loadplugins + endfunction -" Split a comma-separated option string into its constituent parts, imitating -" copy_option_part() in the Vim sources. This isn't perfect, but it should be -" more than good enough. A separator can be defined as: a comma that is not -" preceded by a backslash, and which is followed by any number of spaces -" and/or further commas. +" Split a comma-separated option string into its constituent parts function! vimrc#SplitOption(string) abort - return split(a:string, '\\\@ ver - \ || v:version == ver && has('patch'.patch) + return v:version > running + \ || v:version == running && has(patch) endfunction -- cgit v1.2.3 From 1558c26258df559f9702bcb826dd33e6a61d4edb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:42:59 +1200 Subject: Rename vimrc#Establish() to vimrc#Ensure() Per the suggestion of NickNameNick in #kiwicon. --- vim/autoload/vimrc.vim | 2 +- vim/vimrc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index eccdbf95..f5cad283 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -23,7 +23,7 @@ endfunction " Expand the first path in an option string, check if it exists, and attempt " to create it if it doesn't. Strip double-trailing-slash hints. -function! vimrc#Establish(string) abort +function! vimrc#Ensure(string) abort " Get first part of the option string let part = vimrc#SplitOption(a:string)[0] diff --git a/vim/vimrc b/vim/vimrc index eb835930..db83efe0 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -27,7 +27,7 @@ set backup execute 'set backupdir^='.vimrc#EscapeSetPart( \ $MYVIM.'/cache/backup'.(vimrc#Version('8.1.251') ? '//' : '') \ ) -call vimrc#Establish(&backupdir) +call vimrc#Ensure(&backupdir) " Add some *nix paths not to back up if has('unix') @@ -61,7 +61,7 @@ set dictionary^=/usr/share/dict/words " Keep swap files in dedicated directory, named with full path execute 'set directory^='.vimrc#EscapeSetPart($MYVIM.'/cache/swap//') -call vimrc#Establish(&directory) +call vimrc#Ensure(&directory) " If the environment didn't set an encoding, use UTF-8, not ASCII if !exists('$LANG') @@ -185,7 +185,7 @@ endif if has('persistent_undo') " v7.2.438 set undofile execute 'set undodir^='.vimrc#EscapeSetPart($MYVIM.'/cache/undo//') - call vimrc#Establish(&undodir) + call vimrc#Ensure(&undodir) endif " Keep the viminfo file in the home Vim directory, mostly to stop history -- cgit v1.2.3 From 8b3064c99a4f778a6087ff35d588ae3521ec7c25 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:45:15 +1200 Subject: Refactor 'backupskip' processing --- vim/vimrc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index db83efe0..e638bbd4 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -31,10 +31,27 @@ call vimrc#Ensure(&backupdir) " Add some *nix paths not to back up if has('unix') - set backupskip& " Reset to avoid duplicates (Vim bug?) - set backupskip+=/dev/shm/* " Shared memory RAM disk - set backupskip+=/usr/tmp/* " Hard-coded path for `sudo -e` 1/2 - set backupskip+=/var/tmp/* " Hard-coded path for `sudo -e` 2/2 + + " * /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] + " + let s:backupskip_patterns = [ + \ '/dev/shm/*' + \,'/usr/tmp/*' + \,'/var/tmp/*' + \ ] + + " Vim doesn't seem to check patterns added to 'backupskip' for uniqueness, + " so adding them repeatedly if this file is reloaded results in duplicates. + " This might be a bug in Vim. To work around this, we attempt to remove + " each pattern before we add it. + " + for s:pattern in reverse(s:backupskip_patterns) + execute 'set backupskip-='.vimrc#EscapeSetPart(s:pattern) + execute 'set backupskip^='.vimrc#EscapeSetPart(s:pattern) + endfor + endif " Indent wrapped lines -- cgit v1.2.3 From ac4f819f65ab48fa77eea31e877dcb846d85e917 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:46:34 +1200 Subject: Refactor 'runtimepath' chopping in vimrc --- vim/vimrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index e638bbd4..8e7035b7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -4,7 +4,8 @@ " Set an environment variable for the user runtime directory, if not already " set; use the first element of &runtimepath, rather like 'spellfile' if !exists('$MYVIM') && &runtimepath !=# '' - let $MYVIM = vimrc#SplitOption(&runtimepath)[0] + let s:runtimepath_paths = vimrc#SplitOption(&runtimepath) + let $MYVIM = s:runtimepath_paths[0] endif " The all-important default indent settings; filetypes to tweak -- cgit v1.2.3 From dc710e6c6e90148837c5b07d747426396c4c525a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:47:58 +1200 Subject: Refactor 'backupdir' processing in vimrc --- vim/vimrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 8e7035b7..f8ac71fc 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -25,9 +25,9 @@ set backspace+=start " Before the start of current insertion " Keep backup files in dedicated directory; add trailing double-slash to keep " full path in name, if Vim is new enough to support that set backup -execute 'set backupdir^='.vimrc#EscapeSetPart( - \ $MYVIM.'/cache/backup'.(vimrc#Version('8.1.251') ? '//' : '') - \ ) +let s:backup_full_path = vimrc#Version('8.1.251') +let s:backupdir = $MYVIM.'/cache/backup'.(s:backup_full_path ? '//' : '') +execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir) call vimrc#Ensure(&backupdir) " Add some *nix paths not to back up -- cgit v1.2.3 From 0d8f667c1ddb5afe8c071027d9c391e2e5a317d1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:48:25 +1200 Subject: Remove 'completeopt' settings I realised I don't actually want either of these. --- vim/vimrc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index f8ac71fc..427dab21 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -64,10 +64,6 @@ endif set comments= set commentstring= -" Add completion options -set completeopt+=longest " Insert longest common substring -set completeopt+=menuone " Show the menu even if only one match - " Give me a prompt instead of just rejecting risky :write, :saveas set confirm -- cgit v1.2.3 From 0c5b8e9aaa9fdf88fa4135c1dd94ae2aa3dd0cb2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:49:09 +1200 Subject: Refactor 'directory' processing in vimrc --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 427dab21..14362f6e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -73,8 +73,8 @@ set cpoptions+=J " Specify where to look for a dictionary even if 'spell' isn't on set dictionary^=/usr/share/dict/words -" Keep swap files in dedicated directory, named with full path -execute 'set directory^='.vimrc#EscapeSetPart($MYVIM.'/cache/swap//') +let s:directory = $MYVIM.'/cache/swap//' +execute 'set directory^='.vimrc#EscapeSetPart(s:directory) call vimrc#Ensure(&directory) " If the environment didn't set an encoding, use UTF-8, not ASCII -- cgit v1.2.3 From ee85c7916be3a0a7a90931446efeaada10eb130d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 19:49:39 +1200 Subject: Begin adding longer comments for a literate vimrc --- vim/vimrc | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 161 insertions(+), 22 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 14362f6e..71cc8a18 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,36 +1,120 @@ -" Tom Ryder (tejr)'s vimrc: -" Requires Vim 7.0 or newer with +eval. - -" Set an environment variable for the user runtime directory, if not already -" set; use the first element of &runtimepath, rather like 'spellfile' +" +" Tom Ryder (tejr)'s vimrc +" ------------------------ +" +" +" +" This is a 'literate vimrc', in the Donald Knuth tradition. It's long, and +" comments abound. +" +" This file should be saved as vimrc in the user runtime directory. (UNIX +" ~/.vim, Windows ~/vimfiles). It requires Vim 7.0 or newer with +eval, not +" running in &compatible mode. The vimrc stub (UNIX ~/.vimrc, Windows +" ~/_vimrc) that loads this file checks that these two conditions are met. +" +" > And I was lifted up in heart, and thought +" > Of all my late-shown prowess in the lists, +" > How my strong lance had beaten down the knights, +" > So many and famous names; and never yet +" > 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 +" + +" Set an environment variable MYVIM for the user runtime directory, if such +" a variable does not already exist in the environment, and there's a value in +" 'runtimepath' from which to glean a useable path. We'll use the path +" nominated in the MYVIM variable as the root of our 'backupdir', 'directory', +" 'undodir', and 'viminfofile' caches. +" +" 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 first runtime directory? It's a mystery, and that's why so +" is mankind. +" if !exists('$MYVIM') && &runtimepath !=# '' + + " We'll use the first path specified in 'runtimepath', rather like Vim + " itself does for spelling database files in the absence of a setting for + " 'spellfile'. + " let s:runtimepath_paths = vimrc#SplitOption(&runtimepath) let $MYVIM = s:runtimepath_paths[0] + endif -" The all-important default indent settings; filetypes to tweak +" Global indent settings go here. 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. +" +" In general, however, I prefer spaces to tabs as a default, 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. +" +" +" set autoindent " Use indent of previous line on new lines set expandtab " Use spaces instead of tabs set shiftwidth=4 " Indent with four spaces -" Make insert mode tab key add the same number of spaces as 'shiftwidth', use -" negative value to do this dynamically, if Vim is new enough to support it -let &softtabstop = vimrc#Version('7.3.693') ? -1 : &shiftwidth - -" Let me backspace over pretty much anything +" 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. +" +let s:negative_softtabstop = vimrc#Version('7.3.693') +let &softtabstop = s:negative_softtabstop ? -1 : &shiftwidth + +" 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 +" for deleting text, I feel the convenience outweighs that in this case. +" set backspace+=eol " Line breaks -set backspace+=indent " Spaces from 'autoindent' -set backspace+=start " Before the start of current insertion +set backspace+=indent " Leading whitespace characters created by 'autoindent' +set backspace+=start " Text before the start of the current insertion -" Keep backup files in dedicated directory; add trailing double-slash to keep -" full path in name, if Vim is new enough to support that +" Enable automatic backups of most file buffers. In practice, I don't need +" these backups very much if I'm using version control sensibly, but they have +" still saved my bacon a few times. set backup + +" Try to keep the aforementioned backup files in a dedicated cache directory, +" to stop them proliferating next to their prime locations, and thereby +" getting accidentally committed to Git repositories. +" +" If Vim is new enough (v8.1.251), add two trailing slashes to the path we're +" inserting, which prompts Vim to incorporate the full escaped path in the +" backup filename, avoiding collisions. +" +" As a historical note, other similar directory path list options supported +" this trailing slashes hint for a long time before 'backupdir' caught up to +" them. The 'directory' option for swapfiles 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.251. +" +" I think options named something like 'backuppath', 'swapfilepath', and +" 'undopath' would be much clearer. +" let s:backup_full_path = vimrc#Version('8.1.251') let s:backupdir = $MYVIM.'/cache/backup'.(s:backup_full_path ? '//' : '') execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir) + +" Create the first path in the 'backupdir' list, the one we just added, if it +" doesn't already exist. It isn't created automatically, which is by design. +" call vimrc#Ensure(&backupdir) -" Add some *nix paths not to back up +" Files in certain directories on UNIX-compatible filesystems should not be +" backed up for reasons of privacy, or an intentional ephemerality, or both. +" On the systems I use, this is particularly important if editing temporary +" files created by sudoedit(8). We add a few paths to the default value +" of 'backupskip' to prevent the creation of such undesired backup files. +" if has('unix') " * /dev/shm: RAM disk, default path for password-store's temporary files @@ -55,26 +139,81 @@ if has('unix') endif -" Indent wrapped lines -if exists('+breakindent') " v7.4.338 +" The visual structure of code provided by indents breaks down if a lot of the +" lines wrap. Ideally, most if not all lines would be kept below 80 +" characters, but in cases where this isn't possible, soft-wrapping longer +" lines when 'wrap' is on so that the indent is preserved in the following +" line mitigates this somewhat. +" +" This option wasn't added until v7.4.338, so we need to check it exists +" before we set it. +" +if exists('+breakindent') set breakindent endif -" Clear default 'comments' and 'commentstring', filetype to handle +" vi was often used for development in the C programming language. The +" default values for a lot of Vim's options still reflect this common use +" pattern. In this case, the 'comments' and 'commentstring' options reflect +" the C syntax for comments: +" +" /* +" * This is an ANSI C comment. +" */ +" +" Times change, however, and I don't get to work with C nearly as much as I'd +" like. The defaults no longer make sense, and so we blank the global values +" for these options, compelling filetype plugins to set them as they need +" instead. +" set comments= set commentstring= -" Give me a prompt instead of just rejecting risky :write, :saveas +" Rather than rejecting operations like :write or :saveas when 'readonly' is +" set, and other situations in which data might be lost or I'm acting against +" an option, Vim should give me a prompt to allow me to confirm that I know +" what I'm doing. +" set confirm -" Sentence objects are separated by two spaces +" After staunchly opposing it for years, I have converted to two-spacing. You +" can blame Steve Losh: +" +" +" +" 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 the reason I now also 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' +" command. +" set cpoptions+=J -" Specify where to look for a dictionary even if 'spell' isn't on +" For word completion in insert mode with CTRL-X CTRL-K, or if 'complete' +" includes the 'k' flag, this specifies the path to the system dictionary. +" This makes the dictionary completion work even if 'spell' isn't set. +" +" 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 with reference to the same resources. +" set dictionary^=/usr/share/dict/words +" 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. +" let s:directory = $MYVIM.'/cache/swap//' execute 'set directory^='.vimrc#EscapeSetPart(s:directory) + +" Create the first path in the 'directory' swapfile path list, the one we just +" added, if it doesn't already exist. It isn't created automatically, which +" is by design. +" call vimrc#Ensure(&directory) " If the environment didn't set an encoding, use UTF-8, not ASCII -- cgit v1.2.3 From b554c58a04ab371aa437203106b62f593a2c4ff9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:00:48 +1200 Subject: Group clearing of C-related defaults --- vim/vimrc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 71cc8a18..590d0176 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -161,13 +161,17 @@ endif " * This is an ANSI C comment. " */ " +" Similarly, the 'define' and 'include' options default to C preprocessor +" directives: +" +" #define FOO "bar" +" #include "baz.h" +" " Times change, however, and I don't get to work with C nearly as much as I'd -" like. The defaults no longer make sense, and so we blank the global values -" for these options, compelling filetype plugins to set them as they need -" instead. +" like; the defaults for these options no longer make sense, and so we blank +" them, compelling filetype plugins to set them as they need instead. " -set comments= -set commentstring= +set comments= commentstring= define= include= " Rather than rejecting operations like :write or :saveas when 'readonly' is " set, and other situations in which data might be lost or I'm acting against @@ -257,7 +261,6 @@ set hlsearch nohlsearch " Don't assume I'm editing C; let the filetype set this -set include= " Show search matches as I type my pattern set incsearch -- cgit v1.2.3 From c6e5751cd9ac26acfeabc341d7225e40475e1771 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:21:10 +1200 Subject: Add more literate vimrc comments --- vim/vimrc | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 590d0176..25588943 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -197,8 +197,9 @@ set confirm set cpoptions+=J " For word completion in insert mode with CTRL-X CTRL-K, or if 'complete' -" includes the 'k' flag, this specifies the path to the system dictionary. -" This makes the dictionary completion work even if 'spell' isn't set. +" includes the 'k' flag, this specifies the path to the system dictionary to +" find words. This makes the dictionary completion work consistently, even if +" 'spell' isn't set at that moment. " " 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 @@ -220,20 +221,54 @@ execute 'set directory^='.vimrc#EscapeSetPart(s:directory) " call vimrc#Ensure(&directory) -" If the environment didn't set an encoding, use UTF-8, not ASCII +" 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 is latin1, +" which is seldom what I want, and if I do want it, I'll specify it with LANG +" or possibly a manual :set command. UTF-8 makes much more sense as a default +" encoding if Vim can't glean what I want from LANG. +" if !exists('$LANG') set encoding=utf-8 endif -" Don't wait for a key after Escape in insert mode -if exists('+esckeys') " No such option in Neovim +" If Vim receives an Escape key code in insert mode, it shouldn't wait to see +" 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--". +" +" 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 +" insert mode anyway. It all works fine in the GUI, of course. +" +" There's no such option as 'esckeys' in Neovim, which I gather has completely +" overhauled its method of keyboard event handling, so we need to check +" whether the option exists before we try to set it. +" +if exists('+esckeys') set noesckeys endif -" Fold based on indent, but only when I ask -set foldlevelstart=99 +" By default, 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 structure significance. +" set foldmethod=indent +" That said, I don't want any folding to actually take place unless +" I specifically ask for it. I think of a Vim window with a file buffer +" loaded 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 in-depth code with very +" long functions or loops. +" +" Therefore, we set the depth level at which folds should automatically start +" as closed to a rather high number, per the documentation's recommendations. +" +set foldlevelstart=99 + " Automatic formatting options set formatoptions+=l " Don't break a long line in insert mode set formatoptions+=1 " Avoid breaking lines after one-letter words -- cgit v1.2.3 From c166e93c341c91eac95472213cee034ea161317d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:35:36 +1200 Subject: Reverse overzealous factoring out of variable --- vim/vimrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 25588943..a43c63e0 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -64,8 +64,7 @@ set shiftwidth=4 " Indent with four spaces " Vim is new enough to support it (v7.3.693), apply a negative value to do " this dynamically if 'shiftwidth' changes. " -let s:negative_softtabstop = vimrc#Version('7.3.693') -let &softtabstop = s:negative_softtabstop ? -1 : &shiftwidth +let &softtabstop = vimrc#Version('7.3.693') ? -1 : &shiftwidth " 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 -- cgit v1.2.3 From c294bc81d656c43d00e3d4a7d8dd9f6300b866cc Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:35:59 +1200 Subject: Adjust 'backupdir' path specification for clarity --- vim/vimrc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index a43c63e0..5cc14f01 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -96,11 +96,16 @@ set backup " people assumed it would work the same way, when in fact Vim simply ignored " it until v8.1.251. " -" I think options named something like 'backuppath', 'swapfilepath', and -" 'undopath' would be much clearer. +" I don't want to add the slashes to the option value in older versions of Vim +" where they don't do anything, so I check the version before I add them. " -let s:backup_full_path = vimrc#Version('8.1.251') -let s:backupdir = $MYVIM.'/cache/backup'.(s:backup_full_path ? '//' : '') +" It's all so awkward. Surely options named something like 'backupfullpath', +" 'swapfilefullpath', and 'undofullpath' would have been clearer. +" +let s:backupdir = $MYVIM.'/cache/backup' +if vimrc#Version('8.1.251') + let s:backupdir .= '//' +endif execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir) " Create the first path in the 'backupdir' list, the one we just added, if it -- cgit v1.2.3 From 0f68f8cda6d24a329b500d23197bb6404ec898fa Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:36:19 +1200 Subject: Sort 'backupskip' patterns before reversing They're already sorted, but it makes clearer what we're trying to do. --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 5cc14f01..0675a9d8 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -136,7 +136,7 @@ if has('unix') " This might be a bug in Vim. To work around this, we attempt to remove " each pattern before we add it. " - for s:pattern in reverse(s:backupskip_patterns) + for s:pattern in reverse(sort(s:backupskip_patterns)) execute 'set backupskip-='.vimrc#EscapeSetPart(s:pattern) execute 'set backupskip^='.vimrc#EscapeSetPart(s:pattern) endfor -- cgit v1.2.3 From 69dbdc47735e4a9b8e9ac686aafbaefdc1cab9e6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:36:49 +1200 Subject: Explain sort-reverse of 'backupskip' patterns --- vim/vimrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index 0675a9d8..74f336b7 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -136,6 +136,9 @@ if has('unix') " This might be a bug in Vim. To work around this, we attempt to remove " each pattern before we add it. " + " We sort and add them backwards only so that they're in alphabetical order + " in the final option! + " for s:pattern in reverse(sort(s:backupskip_patterns)) execute 'set backupskip-='.vimrc#EscapeSetPart(s:pattern) execute 'set backupskip^='.vimrc#EscapeSetPart(s:pattern) -- cgit v1.2.3 From de07d2bd03416a117d7454d48ddb27c8009979b7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:37:16 +1200 Subject: Separate 'directory' slashes into its own string --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 74f336b7..55ff8cea 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -219,7 +219,7 @@ set dictionary^=/usr/share/dict/words " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions. " -let s:directory = $MYVIM.'/cache/swap//' +let s:directory = $MYVIM.'/cache/swap'.'//' execute 'set directory^='.vimrc#EscapeSetPart(s:directory) " Create the first path in the 'directory' swapfile path list, the one we just -- cgit v1.2.3 From f05ec42405eb8bb6a6d92e85f3bdc4f81a1cc746 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:37:44 +1200 Subject: Document 'formatoptions' l and 1 flags --- vim/vimrc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 55ff8cea..8f06d787 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -276,9 +276,24 @@ set foldmethod=indent " set foldlevelstart=99 -" Automatic formatting options -set formatoptions+=l " Don't break a long line in insert mode -set formatoptions+=1 " Avoid breaking lines after one-letter words +" Automatic text wrapping options using flags in the 'formatoptions' option +" begin here. I allow filetypes to set 't' and 'c' to configure whether text +" or comments should be wrapped, and don't mess with it 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. +" +set formatoptions+=l + +" Don't wrap a line in such a way that a single-letter word like "I" or "a" is +" at the end of it. Typographically, as far as I can tell, this seems to be +" a stylistic preference rather than a rule like avoiding "widow" and "orphan" +" lines in typesetting. I think it generally looks better to have the short +" word start the line. +" +set formatoptions+=1 + if vimrc#Version('7.3.541') set formatoptions+=j " Delete comment leaders when joining lines endif -- cgit v1.2.3 From 90f9dbef9e984f1167b8a86815d391d07f70b889 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:38:46 +1200 Subject: Quote a filename --- vim/vimrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 8f06d787..a526c1f2 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -7,7 +7,7 @@ " This is a 'literate vimrc', in the Donald Knuth tradition. It's long, and " comments abound. " -" This file should be saved as vimrc in the user runtime directory. (UNIX +" This file should be saved as "vimrc" in the user runtime directory. (UNIX " ~/.vim, Windows ~/vimfiles). It requires Vim 7.0 or newer with +eval, not " running in &compatible mode. The vimrc stub (UNIX ~/.vimrc, Windows " ~/_vimrc) that loads this file checks that these two conditions are met. @@ -294,6 +294,7 @@ set formatoptions+=l " set formatoptions+=1 +" if vimrc#Version('7.3.541') set formatoptions+=j " Delete comment leaders when joining lines endif -- cgit v1.2.3 From 9908b32b2075f37ff1cdd4dcab8ad0e5f7033a0c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:39:08 +1200 Subject: Remove unneeded qualifier --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index a526c1f2..595a757f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -10,7 +10,7 @@ " This file should be saved as "vimrc" in the user runtime directory. (UNIX " ~/.vim, Windows ~/vimfiles). It requires Vim 7.0 or newer with +eval, not " running in &compatible mode. The vimrc stub (UNIX ~/.vimrc, Windows -" ~/_vimrc) that loads this file checks that these two conditions are met. +" ~/_vimrc) that loads this file checks that these conditions are met. " " > And I was lifted up in heart, and thought " > Of all my late-shown prowess in the lists, -- cgit v1.2.3 From 0d9d766ceb0c6111c28f67d11171c7f082b1de58 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:41:14 +1200 Subject: Explain the choice of a 'runtimepath' split func --- vim/vimrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 595a757f..45f06130 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -37,7 +37,9 @@ if !exists('$MYVIM') && &runtimepath !=# '' " We'll use the first path specified in 'runtimepath', rather like Vim " itself does for spelling database files in the absence of a setting for - " 'spellfile'. + " 'spellfile'. Splitting the values of an option like 'runtimepath' is + " a bit more complicated than it looks; we defer it to an autoloaded utility + " function for clarity. " let s:runtimepath_paths = vimrc#SplitOption(&runtimepath) let $MYVIM = s:runtimepath_paths[0] -- cgit v1.2.3 From e01cb1a45911965b2d992f3febd9a20feeb948b8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:42:13 +1200 Subject: Explain behaviour absent the 'dictionary' file --- vim/vimrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index 45f06130..02e7c8fc 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -214,6 +214,9 @@ set cpoptions+=J " a bit more intelligently to ensure that spell checking and dictionary " function consistently with reference to the same resources. " +" It's not an error if this file doesn't exist; indeed, on some systems I use, +" it doesn't. +" set dictionary^=/usr/share/dict/words " Keep swap files for file buffers in a dedicated directory, rather than the -- cgit v1.2.3 From fa10777639104aa29347b9fbca8f1dc599b49e86 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:45:25 +1200 Subject: Rework a sentence --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 02e7c8fc..4da094fd 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -83,8 +83,8 @@ set backspace+=start " Text before the start of the current insertion set backup " Try to keep the aforementioned backup files in a dedicated cache directory, -" to stop them proliferating next to their prime locations, and thereby -" getting accidentally committed to Git repositories. +" to stop them proliferating next to their prime locations and getting +" committed to version control repositories. " " If Vim is new enough (v8.1.251), add two trailing slashes to the path we're " inserting, which prompts Vim to incorporate the full escaped path in the -- cgit v1.2.3 From d7748a0d665ac099b498cc3f2b21215c601463d0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 20:55:50 +1200 Subject: Adjust layout and fully document vimrc reload hook --- vim/vimrc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 4da094fd..9495dee6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -46,6 +46,23 @@ if !exists('$MYVIM') && &runtimepath !=# '' endif +" Create a 'vimrc' automatic command hook group, if it already exists, and +" clear away any automatic command hooks already defined within it if it does, +" so that we don't end up collecting multiple copies of the hooks configured +" in the rest of this file if it's reloaded. +" +augroup vimrc + autocmd! +augroup END + +" If this file or the vimrc stub that calls it is written to by Vim, reload +" the stub vimrc and thereby the main vimrc, so that our changes apply +" immediately in the current editing session. This often makes broken changes +" immediately apparent. +" +autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc + \ source $MYVIMRC + " Global indent settings go here. 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 @@ -683,10 +700,3 @@ inoreabbrev wrnog wrong inoreabbrev Fielding Feilding inoreabbrev THe the inoreabbrev THere there - -" Reload this file when I save it, modified or nay -augroup vimrc - autocmd! - autocmd BufWritePost $MYVIMRC,$MYVIM/vimrc - \ source $MYVIMRC -augroup END -- cgit v1.2.3 From a4870dedbf0d548d7e2c4159c8eb889c1b8decdd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 21:00:22 +1200 Subject: Refactor 'backupskip' loop into one exec :set --- vim/vimrc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 9495dee6..56128ba1 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -159,8 +159,10 @@ if has('unix') " in the final option! " for s:pattern in reverse(sort(s:backupskip_patterns)) - execute 'set backupskip-='.vimrc#EscapeSetPart(s:pattern) - execute 'set backupskip^='.vimrc#EscapeSetPart(s:pattern) + let s:pattern_escaped = vimrc#EscapeSetPart(s:pattern) + execute 'set' + \.' backupskip-='.s:pattern_escaped + \.' backupskip^='.s:pattern_escaped endfor endif -- cgit v1.2.3 From f1abad71fe297aba1616d789440b48c6904af1b4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 21:02:41 +1200 Subject: s/UNIX/Unix/g --- vim/vimrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 56128ba1..d35ccafa 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -7,9 +7,9 @@ " This is a 'literate vimrc', in the Donald Knuth tradition. It's long, and " comments abound. " -" This file should be saved as "vimrc" in the user runtime directory. (UNIX +" This file should be saved as "vimrc" in the user runtime directory. (Unix " ~/.vim, Windows ~/vimfiles). It requires Vim 7.0 or newer with +eval, not -" running in &compatible mode. The vimrc stub (UNIX ~/.vimrc, Windows +" running in &compatible mode. The vimrc stub (Unix ~/.vimrc, Windows " ~/_vimrc) that loads this file checks that these conditions are met. " " > And I was lifted up in heart, and thought @@ -132,7 +132,7 @@ execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir) " call vimrc#Ensure(&backupdir) -" Files in certain directories on UNIX-compatible filesystems should not be +" Files in certain directories on Unix-compatible filesystems should not be " backed up for reasons of privacy, or an intentional ephemerality, or both. " On the systems I use, this is particularly important if editing temporary " files created by sudoedit(8). We add a few paths to the default value -- cgit v1.2.3 From 37722100c399be132a5eba5894015084b39c761f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 21:14:10 +1200 Subject: Complete documentation of 'formatoptions' choices --- vim/vimrc | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index d35ccafa..4edc1a96 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -303,7 +303,7 @@ set foldlevelstart=99 " Automatic text wrapping options using flags in the 'formatoptions' option " begin here. I allow filetypes to set 't' and 'c' to configure whether text " or comments should be wrapped, and don't mess with it 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. @@ -318,12 +318,40 @@ set formatoptions+=l " 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 redunant comment leaders cropping +" up. For example, with this set, in Vim, joining lines in this very comment +" with 'J' would remove the leading '"' characters that denote a comment. +" +" This option flag wasn't added until v7.3.541. Because we can't test for the +" availability of option flags directly, we instead do a version number check +" before attempting to add the flag. " if vimrc#Version('7.3.541') - set formatoptions+=j " Delete comment leaders when joining lines + set formatoptions+=j endif + +" Separating sentences with two spaces has an advantage in distinguishing +" between two different types of periods: periods that abbreviate longer +" words, as in "Mr. Moolenaar", and periods that terminate sentences, like +" this one. +" +" If we're using two-period spacing for sentences, Vim can interpret the +" different spacing to distinguish between the two types, and can avoid +" breaking a line just after an abbreviating period. That means the two words +" in "Mr. Moolenaar" should never be split apart, preventing confusion on the +" reader's part, and also preserving the semantics of the period for +" subsequent reformats. +" +" This 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. +" +" +" if vimrc#Version('8.1.728') - set formatoptions+=p " Don't break a single space after a period + set formatoptions+=p endif " Don't load GUI menus; set here before GUI starts or any filetype or syntax -- cgit v1.2.3 From 81c17d5551c399c9170ee06162aa0b4a7fbcde93 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 21:44:43 +1200 Subject: Drastically simplify $MYVIM handling It was a fun exercise, but it's a pretty perverse situation to set up. People generally don't put commas in their runtime directory names, and it's not too out of order simply to tell them not to do that if they do. This removes the need for two small utility functions. --- vim/autoload/vimrc.vim | 21 --------------- vim/vimrc | 73 +++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 58 deletions(-) diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim index f5cad283..b3a28062 100644 --- a/vim/autoload/vimrc.vim +++ b/vim/autoload/vimrc.vim @@ -1,26 +1,5 @@ " Utility functions for use in .vim/vimrc only -" Escape a text value for :execute-based :set inclusion as an option value -function! vimrc#EscapeSet(string) abort - - " Escape all the characters that `:help option-backslash` warns us about - return escape(a:string, '\ |"') - -endfunction - -" Escape a text value for :execute-based :set inclusion as an element in -" a comma-separated option value -function! vimrc#EscapeSetPart(string) abort - - " Message to future Tom: yes, the comma being the sole inner escaped - " character here is correct. No, we shouldn't escape backslash itself. - " Yes, that means it's impossible to have the literal string '\,' in a part. - " Yes, this reflects what Vim does internally. Read the source of - " copy_option_part() in vim/src/misc2.c to confirm. - return vimrc#EscapeSet(escape(a:string, ',')) - -endfunction - " Expand the first path in an option string, check if it exists, and attempt " to create it if it doesn't. Strip double-trailing-slash hints. function! vimrc#Ensure(string) abort diff --git a/vim/vimrc b/vim/vimrc index 4edc1a96..f3f901e8 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -33,17 +33,29 @@ " variable for the first runtime directory? It's a mystery, and that's why so " is mankind. " +" We'll use the first path specified in 'runtimepath', rather like Vim itself +" does for spelling database files in the absence of a setting for +" 'spellfile'. Splitting the values of an option like 'runtimepath' correctly +" is a bit more complicated than it seems; we defer that to an autoloaded +" utility function for clarity. +" if !exists('$MYVIM') && &runtimepath !=# '' + let $MYVIM = vimrc#SplitOption(&runtimepath)[0] +endif - " We'll use the first path specified in 'runtimepath', rather like Vim - " itself does for spelling database files in the absence of a setting for - " 'spellfile'. Splitting the values of an option like 'runtimepath' is - " a bit more complicated than it looks; we defer it to an autoloaded utility - " function for clarity. - " - let s:runtimepath_paths = vimrc#SplitOption(&runtimepath) - let $MYVIM = s:runtimepath_paths[0] - +" The path named in the MYVIM environment variable can't contain a comma +" anywhere, because its use in comma-separated option values will confuse Vim +" into thinking more than one directory is being specified for the option +" value, per normal :set semantics. If it does, we refuse to proceed. +" +" It's possible to work around this with some careful escaping, either at :set +" time with an :execute abstraction or with a separate environment variable +" for that particular context, but it's not really worth the extra complexity +" for such a niche situation. +" +if stridx($MYVIM, ',') != -1 + echoerr '$MYVIM contains a comma, refusing to proceed' + finish endif " Create a 'vimrc' automatic command hook group, if it already exists, and @@ -121,11 +133,11 @@ set backup " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. " -let s:backupdir = $MYVIM.'/cache/backup' if vimrc#Version('8.1.251') - let s:backupdir .= '//' + set backupdir^=$MYVIM/cache/backup// +else + set backupdir^=$MYVIM/cache/backup endif -execute 'set backupdir^='.vimrc#EscapeSetPart(s:backupdir) " Create the first path in the 'backupdir' list, the one we just added, if it " doesn't already exist. It isn't created automatically, which is by design. @@ -140,30 +152,18 @@ call vimrc#Ensure(&backupdir) " if has('unix') - " * /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] - " - let s:backupskip_patterns = [ - \ '/dev/shm/*' - \,'/usr/tmp/*' - \,'/var/tmp/*' - \ ] - " Vim doesn't seem to check patterns added to 'backupskip' for uniqueness, " so adding them repeatedly if this file is reloaded results in duplicates. - " This might be a bug in Vim. To work around this, we attempt to remove - " each pattern before we add it. + " This might be a bug in Vim. To work around this, we reset the path back + " to its default first. + set backupskip& + " - " We sort and add them backwards only so that they're in alphabetical order - " in the final option! + " * /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] " - for s:pattern in reverse(sort(s:backupskip_patterns)) - let s:pattern_escaped = vimrc#EscapeSetPart(s:pattern) - execute 'set' - \.' backupskip-='.s:pattern_escaped - \.' backupskip^='.s:pattern_escaped - endfor + set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/* endif @@ -243,8 +243,7 @@ set dictionary^=/usr/share/dict/words " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions. " -let s:directory = $MYVIM.'/cache/swap'.'//' -execute 'set directory^='.vimrc#EscapeSetPart(s:directory) +set directory^=$MYVIM/cache/swap " Create the first path in the 'directory' swapfile path list, the one we just " added, if it doesn't already exist. It isn't created automatically, which @@ -434,7 +433,7 @@ set splitright " Right of the current window, not left set synmaxcol=500 " Add thesaurus; install with `make install-vim-thesaurus` -execute 'set thesaurus^='.vimrc#EscapeSetPart($MYVIM.'/ref/thesaurus.txt') +set thesaurus^=$MYVIM/ref/thesaurus.txt " PuTTY is a fast terminal, but Vim doesn't know that yet if &term =~# '^putty' @@ -450,7 +449,7 @@ endif " Keep persistent undo files in dedicated directory, named with full path if has('persistent_undo') " v7.2.438 set undofile - execute 'set undodir^='.vimrc#EscapeSetPart($MYVIM.'/cache/undo//') + set undodir^=$MYVIM/cache/undo// call vimrc#Ensure(&undodir) endif @@ -459,7 +458,7 @@ endif if exists('+viminfofile') " Use new option method if we can (v8.1.716) set viminfofile=$MYVIM/cache/viminfo else " Resort to clunkier method with 'viminfo' option flag - execute 'set viminfo+='.vimrc#EscapeSet('n'.$MYVIM.'/cache/viminfo') + set viminfo+=n$MYVIM/cache/viminfo endif " Let me move beyond buffer text in visual block mode -- cgit v1.2.3 From c19a787ead803a8c87bc0fa62ad29c4c9408152d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 21:45:42 +1200 Subject: Edit some comments for clarity --- vim/vimrc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index f3f901e8..a5633921 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -7,10 +7,11 @@ " This is a 'literate vimrc', in the Donald Knuth tradition. It's long, and " comments abound. " -" This file should be saved as "vimrc" in the user runtime directory. (Unix -" ~/.vim, Windows ~/vimfiles). It requires Vim 7.0 or newer with +eval, not -" running in &compatible mode. The vimrc stub (Unix ~/.vimrc, Windows -" ~/_vimrc) that loads this file checks that these conditions are met. +" 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, not running in &compatible mode. +" The vimrc stub at ~/.vimrc on Unix or ~/_vimrc on Windows checks that these +" conditions are met before loading this file. " " > And I was lifted up in heart, and thought " > Of all my late-shown prowess in the lists, @@ -128,7 +129,8 @@ set backup " it until v8.1.251. " " I don't want to add the slashes to the option value in older versions of Vim -" where they don't do anything, so I check the version before I add them. +" where they don't do anything, so I check the version to see if I should add +" them. " " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. -- cgit v1.2.3 From 624bd993b589d84265e66654faf05bcb3c160f43 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 22:00:17 +1200 Subject: Factor out all my autoloaded functions I've changed my mind again; I want this file to be self-contained. --- vim/autoload/vimrc.vim | 82 -------------------------------------------------- vim/vimrc | 53 ++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 104 deletions(-) delete mode 100644 vim/autoload/vimrc.vim diff --git a/vim/autoload/vimrc.vim b/vim/autoload/vimrc.vim deleted file mode 100644 index b3a28062..00000000 --- a/vim/autoload/vimrc.vim +++ /dev/null @@ -1,82 +0,0 @@ -" Utility functions for use in .vim/vimrc only - -" Expand the first path in an option string, check if it exists, and attempt -" to create it if it doesn't. Strip double-trailing-slash hints. -function! vimrc#Ensure(string) abort - - " Get first part of the option string - let part = vimrc#SplitOption(a:string)[0] - - " Remove any trailing slashes; neither expand() nor mkdir() seems bothered, - " at least on Unix, but let's be tidy anyway - let part = substitute(part, '/\+$', '', '') - - " Expand the directory name to replace tildes with the home directory, but - " it still may not necessarily be an absolute path - let dirname = expand(part) - - " Return either the confirmed presence of the directory, or failing that, - " the result of an attempt to create it - return isdirectory(dirname) - \ || mkdir(dirname, 'p') - -endfunction - -" Check that we have a plugin available, and will be loading it -function! vimrc#PluginReady(filename) abort - - " Return whether the given filename with a .vim extension is present in - " a subdirectory named 'plugin', and that the 'loadplugins' option is on, - " implying that Vim will at least attempt to load it - let path = 'plugin/'.a:filename.'.vim' - return globpath(&runtimepath, path) !=# '' - \ && &loadplugins - -endfunction - -" Split a comma-separated option string into its constituent parts -function! vimrc#SplitOption(string) abort - - " A separator can be defined as: a comma that is not preceded by - " a backslash, and which is followed by any number of spaces and/or further - " commas. No, I don't have to deal with escaped backslashes; read the - " source of copy_option_part() in vim/src/misc2.c to see why. - let pattern - \ = '\\\@ running - \ || v:version == running && has(patch) - -endfunction diff --git a/vim/vimrc b/vim/vimrc index a5633921..8ef77a69 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -36,12 +36,17 @@ " " We'll use the first path specified in 'runtimepath', rather like Vim itself " does for spelling database files in the absence of a setting for -" 'spellfile'. Splitting the values of an option like 'runtimepath' correctly -" is a bit more complicated than it seems; we defer that to an autoloaded -" utility function for clarity. +" 'spellfile'. +" +" Splitting the values of an option like 'runtimepath' correctly +" is a bit more complicated than it seems. A separator can be defined as: +" a comma that is not preceded by a backslash, and which is followed by any +" number of spaces and/or further commas. No, I don't have to deal with +" escaped backslashes; read the source of copy_option_part() in +" vim/src/misc2.c to see why. " if !exists('$MYVIM') && &runtimepath !=# '' - let $MYVIM = vimrc#SplitOption(&runtimepath)[0] + let $MYVIM = split(&runtimepath, '\\\@ 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 @@ -120,6 +129,9 @@ set backup " inserting, which prompts Vim to incorporate the full escaped path in the " backup filename, avoiding collisions. " +" Create the first path in the 'backupdir' list, the one we just added, if it +" doesn't already exist. It isn't created automatically, which is by design. +" " As a historical note, other similar directory path list options supported " this trailing slashes hint for a long time before 'backupdir' caught up to " them. The 'directory' option for swapfiles has supported it at least as far @@ -135,16 +147,12 @@ set backup " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. " -if vimrc#Version('8.1.251') +if has('patch-8.1.251') set backupdir^=$MYVIM/cache/backup// else set backupdir^=$MYVIM/cache/backup endif - -" Create the first path in the 'backupdir' list, the one we just added, if it -" doesn't already exist. It isn't created automatically, which is by design. -" -call vimrc#Ensure(&backupdir) +call mkdir($MYVIM.'/cache/backup', 'p') " Files in certain directories on Unix-compatible filesystems should not be " backed up for reasons of privacy, or an intentional ephemerality, or both. @@ -245,13 +253,11 @@ set dictionary^=/usr/share/dict/words " trailing slashes to the path to prompt Vim to use the full escaped path in " its name, in order to avoid filename collisions. " -set directory^=$MYVIM/cache/swap - -" Create the first path in the 'directory' swapfile path list, the one we just -" added, if it doesn't already exist. It isn't created automatically, which -" is by design. +" Create the first directory after adding it, if it doesn't already exist. It +" isn't created automatically, by design. " -call vimrc#Ensure(&directory) +set directory^=$MYVIM/cache/swap// +call mkdir($MYVIM.'/cache/swap', 'p') " 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 @@ -329,7 +335,7 @@ set formatoptions+=1 " availability of option flags directly, we instead do a version number check " before attempting to add the flag. " -if vimrc#Version('7.3.541') +if v:version > 730 || v:version == 730 && has('patch541') set formatoptions+=j endif @@ -351,7 +357,7 @@ endif " " " -if vimrc#Version('8.1.728') +if has('patch-8.1.728') set formatoptions+=p endif @@ -452,7 +458,7 @@ endif if has('persistent_undo') " v7.2.438 set undofile set undodir^=$MYVIM/cache/undo// - call vimrc#Ensure(&undodir) + call mkdir($MYVIM.'/cache/undo', 'p') endif " Keep the viminfo file in the home Vim directory, mostly to stop history @@ -462,6 +468,7 @@ if exists('+viminfofile') " Use new option method if we can (v8.1.716) else " Resort to clunkier method with 'viminfo' option flag set viminfo+=n$MYVIM/cache/viminfo endif +call mkdir($MYVIM.'/cache', 'p') " Let me move beyond buffer text in visual block mode set virtualedit+=block @@ -502,7 +509,8 @@ catch endtry " Space bar scrolls down a page, :next at buffer's end if plugin available -if vimrc#PluginReady('scroll_next') +if globpath(&runtimepath, 'plugin/scroll_next.vim') + \ && &loadplugins nmap (ScrollNext) else nnoremap @@ -510,7 +518,8 @@ endif " Remap insert Ctrl-C to undo the escaped insert operation, but don't break " the key if the plugin isn't there -if vimrc#PluginReady('insert_cancel') +if globpath(&runtimepath, 'plugin/insert_cancel.vim') + \ && &loadplugins imap (InsertCancel) endif -- cgit v1.2.3 From b53eee63210b054a70287f239e324d9f7d610e5b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 22:27:29 +1200 Subject: More adjustment of $MYVIM comment documentation --- vim/vimrc | 65 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 8ef77a69..d66c94a1 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -23,30 +23,46 @@ " > --Tennyson " -" Set an environment variable MYVIM for the user runtime directory, if such -" a variable does not already exist in the environment, and there's a value in -" 'runtimepath' from which to glean a useable path. We'll use the path -" nominated in the MYVIM variable as the root of our 'backupdir', 'directory', -" 'undodir', and 'viminfofile' caches. +" The first thing we'll do is set an environment variable MYVIM for the user +" runtime directory, if such a variable does not already exist in the +" environment, and there's a value in 'runtimepath' from which to glean +" a useable path. 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 writeable location for Vim-related +" files. " " 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 first runtime directory? It's a mystery, and that's why so -" is mankind. -" -" We'll use the first path specified in 'runtimepath', rather like Vim itself -" does for spelling database files in the absence of a setting for -" 'spellfile'. -" -" Splitting the values of an option like 'runtimepath' correctly -" is a bit more complicated than it seems. A separator can be defined as: -" a comma that is not preceded by a backslash, and which is followed by any -" number of spaces and/or further commas. No, I don't have to deal with -" escaped backslashes; read the source of copy_option_part() in -" vim/src/misc2.c to see why. +" variable for the user's Vim runtime directory? It is a mystery. " if !exists('$MYVIM') && &runtimepath !=# '' + + " We'll use the first path specified in 'runtimepath' as a default value for + " the MYVIM environment variable. This is similar to what Vim itself does + " for the location of the spelling database files in the absence of + " a setting for 'spellfile'. + " + " Splitting the values of a comma-separated option like 'runtimepath' + " correctly is a bit more complicated than it seems. The list separator is + " more accurately defined as a comma that is not preceded by a backslash, and + " which is followed by any number of spaces and/or further commas. The + " pattern breaks down like this: + " + " \\ Literal backslash + " \@ Date: Sat, 8 Jun 2019 22:27:58 +1200 Subject: Move vimrc-reload-filetype back into vimrc I think this is a more sensible location for it. We'll see. --- vim/bundle/vimrc_reload_filetype | 1 - vim/vimrc | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) delete mode 160000 vim/bundle/vimrc_reload_filetype diff --git a/vim/bundle/vimrc_reload_filetype b/vim/bundle/vimrc_reload_filetype deleted file mode 160000 index 1a59433f..00000000 --- a/vim/bundle/vimrc_reload_filetype +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1a59433fa33f737264af73a7323ce669fa14a21a diff --git a/vim/vimrc b/vim/vimrc index d66c94a1..57b1c134 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -97,10 +97,39 @@ augroup END autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc \ source $MYVIMRC -" Global indent settings go here. 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. +" Similarly, if this file or the vimrc stub that calls it is sourced, whether +" because of the above hook, or the R mapping prescribed later in this +" file, add a hook that re-runs filetype detection and thereby ftplugin +" loading. This is chiefly so that any global options set in this file don't +" trample over needed buffer-local settings. +" +" If there's stuff in any of your ftplugins that doesn't cope well with being +" reloaded, and just assumes a single BufRead event, it might be necessary to +" rewrite those parts to be idempotent, or to add load guards around them so +" that they only run once. +" +" Note that the SourceCmd event wasn't added until Vim 7.0.187, so we need to +" check it exists first. +" +if exists('##SourceCmd') + + " We can't wrap this in a script-local function like I normally would, + " because then Vim will get upset that we're trying to redefine it the next + " time it loads. It's only four commands, anyway. + " + autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc + \ source + \|if exists('#filetypedetect#BufRead') + \| doautocmd filetypedetect BufRead + \|endif + +endif + +" Global indent and other whitespace-related settings go here. 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. " " In general, however, I prefer spaces to tabs as a default, and I like to use " four of them, for a more distinct visual structure. Should you happen to -- cgit v1.2.3 From e8a33c4c897da49027c742fd672d8d3d1c046aa8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 22:39:03 +1200 Subject: Refine detail on MYVIM comma termination --- vim/vimrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 57b1c134..7a0bc22e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -68,7 +68,8 @@ endif " The path named in the MYVIM environment variable can't contain a comma " anywhere, because its use in comma-separated option values will confuse Vim " into thinking more than one directory is being specified for the option -" value, per normal :set semantics. If it does, we refuse to proceed. +" value, per normal :set semantics. If there's a comma, we raise an error and +" end the script. " " It's possible to work around this with some careful escaping, either at :set " time with an :execute abstraction or with a separate environment variable -- cgit v1.2.3 From ba3fe4a848778f73dd70fe3558c5463798ba4d97 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 22:39:36 +1200 Subject: Remove repeated word --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 7a0bc22e..1641b36b 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -59,7 +59,7 @@ if !exists('$MYVIM') && &runtimepath !=# '' " copy_option_part() in vim/src/misc2.c to see why. " " Man, I wish the runtime path was just a List, or could be treated as one. - " Vim, I love you, but man, you are weird. + " Vim, I love you, but you are weird. " let $MYVIM = split(&runtimepath, '\\\@ Date: Sat, 8 Jun 2019 22:40:49 +1200 Subject: More detail on vimrc re-sourcing --- vim/vimrc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 1641b36b..c843e0a1 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -115,8 +115,12 @@ autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc if exists('##SourceCmd') " We can't wrap this in a script-local function like I normally would, - " because then Vim will get upset that we're trying to redefine it the next - " time it loads. It's only four commands, anyway. + " because without a load guard around it, Vim will get upset that we're + " trying to redefine that function the next time this script loads. + " + " So, we just inline the whole thing into the hook. It's only four + " commands, anyway, and I'd rather most if not all of the vimrc was reloaded + " when we source it. " autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc \ source -- cgit v1.2.3 From 48f72b37ace21d89c151bb98c8f9102a441bb1f7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:29:58 +1200 Subject: Even more agonising over directory creation --- vim/vimrc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index c843e0a1..c319c51b 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -61,7 +61,8 @@ if !exists('$MYVIM') && &runtimepath !=# '' " Man, I wish the runtime path was just a List, or could be treated as one. " Vim, I love you, but you are weird. " - let $MYVIM = split(&runtimepath, '\\\@ Date: Sat, 8 Jun 2019 23:32:34 +1200 Subject: Fix up a few more comments --- vim/vimrc | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index c319c51b..d81aa7f6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -152,8 +152,8 @@ endif " " set autoindent " Use indent of previous line on new lines -set expandtab " Use spaces instead of tabs -set shiftwidth=4 " Indent with four spaces +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 @@ -217,9 +217,9 @@ endif " Files in certain directories on Unix-compatible filesystems should not be " backed up for reasons of privacy, or an intentional ephemerality, or both. -" On the systems I use, this is particularly important if editing temporary -" files created by sudoedit(8). We add a few paths to the default value -" of 'backupskip' to prevent the creation of such undesired backup files. +" This is particularly important if editing temporary files created by +" sudoedit(8). We add a few paths to the default value of 'backupskip' here +" in order to prevent the creation of such undesired backup files. " if has('unix') @@ -241,7 +241,7 @@ endif " lines wrap. Ideally, most if not all lines would be kept below 80 " characters, but in cases where this isn't possible, soft-wrapping longer " lines when 'wrap' is on so that the indent is preserved in the following -" line mitigates this somewhat. +" line mitigates this breakdown somewhat. " " This option wasn't added until v7.4.338, so we need to check it exists " before we set it. @@ -250,8 +250,8 @@ if exists('+breakindent') set breakindent endif -" vi was often used for development in the C programming language. The -" default values for a lot of Vim's options still reflect this common use +" Traditional vi was often used for development in the C programming language. +" The default values for a lot of Vim's options still reflect this common use " pattern. In this case, the 'comments' and 'commentstring' options reflect " the C syntax for comments: " @@ -263,10 +263,11 @@ endif " directives: " " #define FOO "bar" +" " #include "baz.h" " " Times change, however, and I don't get to work with C nearly as much as I'd -" like; the defaults for these options no longer make sense, and so we blank +" like. The defaults for these options no longer make sense, and so we blank " them, compelling filetype plugins to set them as they need instead. " set comments= commentstring= define= include= @@ -349,19 +350,21 @@ if exists('+esckeys') set noesckeys endif -" By default, 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 structure significance. +" 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 structure +" significance. " set foldmethod=indent " That said, I don't want any folding to actually take place unless -" I specifically ask for it. I think of a Vim window with a file buffer -" loaded 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 in-depth code with very -" long functions or loops. +" I specifically ask for it. +" +" I think of a Vim window with a file buffer loaded 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 in-depth code with very long functions or loops. " " Therefore, we set the depth level at which folds should automatically start " as closed to a rather high number, per the documentation's recommendations. @@ -370,11 +373,12 @@ set foldlevelstart=99 " Automatic text wrapping options using flags in the 'formatoptions' option " begin here. I allow filetypes to set 't' and 'c' to configure whether text -" or comments should be wrapped, and don't mess with it here. +" or comments should be wrapped, 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. +" wrap it; I'll break it apart myself with a command like 'gq'. " set formatoptions+=l @@ -393,7 +397,7 @@ set formatoptions+=1 " with 'J' would remove the leading '"' characters that denote a comment. " " This option flag wasn't added until v7.3.541. Because we can't test for the -" availability of option flags directly, we instead do a version number check +" availability of option flags directly, we resort to a version number check " before attempting to add the flag. " if v:version > 730 || v:version == 730 && has('patch541') -- cgit v1.2.3 From c83bef424fa96cc86ce6849bbc1f59b27c6229c7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:32:44 +1200 Subject: Adjust a couple of stray lines --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index d81aa7f6..0ade2588 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -136,7 +136,6 @@ if exists('##SourceCmd') \|if exists('#filetypedetect#BufRead') \| doautocmd filetypedetect BufRead \|endif - endif " Global indent and other whitespace-related settings go here. Filetype @@ -227,6 +226,7 @@ if has('unix') " so adding them repeatedly if this file is reloaded results in duplicates. " This might be a bug in Vim. To work around this, we reset the path back " to its default first. + " set backupskip& " * /dev/shm: RAM disk, default path for password-store's temporary files -- cgit v1.2.3 From 34fa70b1b8a91327991af574509a0a2c0fd94133 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:33:21 +1200 Subject: Add more literate comments to vimrc --- vim/vimrc | 56 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 0ade2588..f49ea20d 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -426,32 +426,66 @@ if has('patch-8.1.728') set formatoptions+=p endif -" Don't load GUI menus; set here before GUI starts or any filetype or syntax -" logic is performed +" In an effort to avoid loading unnecessary files, we add a flag to the +" 'guioptions' option to prevent the menu.vim runtime file from being loaded. +" It doesn't do any harm, but I never use it, and it's easy to turn it off. +" +" The documentation for this flag in `:help 'go-M'` includes a note saying the +" flag should be set here, rather that in the GUI-specific gvimrc file, as one +" might otherwise think. +" if has('gui_running') set guioptions+=M endif -" Allow buffers to have changes without being displayed +" 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 be modified and not displayed. +" +" Despite this option being in almost every vimrc I read, I didn't personally +" need it for years into my Vim career, because I instinctively only closed +" windows onto buffers after the buffers within them were saved anyway. +" +" However, the option really is required for batch operations performed with +" commands like :argdo or :bufdo. After I started using those a bit more +" often, I realised I finally had a reason to turn this on, and so on it shall +" stay. +" set hidden -" Keep much more command and search history +" 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 hard disk space. +" set history=2000 -" Highlight completed searches; clear on reload +" Do highlight completed searches, but clear them away on vimrc reload. Later +" on in this file, CTRL-L in normal mode is remapped to stack on a :nohlsearch +" as well. +" set hlsearch nohlsearch -" Don't assume I'm editing C; let the filetype set this - -" Show search matches as I type my pattern +" Show search matches as I type my pattern, including scrolling the screen if +" necessary. This is somewhat jarring sometimes, particularly when the cursor +" runs so far away from home, but I think the benefits of being able to see +" instances of what I'm trying to match as I try to match it do outweight +" that. +" set incsearch -" Don't show a status line if there's only one window -" This is Vim's default, but not Neovim's +" If there's only one window, I don't need a statusline to appear beneath it. +" I very often edit only one file, and just open a :help buffer or two. This +" is the Vim default, but Neovim changed it, so we'll explicitly set it to the +" default here in case we're using Neovim. +" set laststatus=1 -" Don't redraw the screen during batch execution +" Don't waste cycles and bandwidth redrawing the screen during batch execution +" of macros. I think this does amount to the occasional :redraw needing to be +" in a script, but it's not too bad, and last I checked it really does speed +" things up, especially for linewise operations on really big data sets. +" set lazyredraw " Break lines at word boundaries -- cgit v1.2.3 From d56ce3f8759613423500b7f86107e4a13025f8b0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:34:14 +1200 Subject: Bump Vim 'history' to 10000, the maximum value --- vim/vimrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index f49ea20d..c275e039 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -455,9 +455,10 @@ set hidden " 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 hard disk space. +" let alone hard disk space. The maximum value for this option is documented +" as 10000, so let's just use that. " -set history=2000 +set history=10000 " Do highlight completed searches, but clear them away on vimrc reload. Later " on in this file, CTRL-L in normal mode is remapped to stack on a :nohlsearch -- cgit v1.2.3 From 7485391b8e68c6f696563ad8a79e68d9e1d9ec92 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:39:39 +1200 Subject: Correct type of plugin existence checks --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index c275e039..07f39b15 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -611,7 +611,7 @@ catch endtry " Space bar scrolls down a page, :next at buffer's end if plugin available -if globpath(&runtimepath, 'plugin/scroll_next.vim') +if globpath(&runtimepath, 'plugin/scroll_next.vim') !=# '' \ && &loadplugins nmap (ScrollNext) else @@ -620,7 +620,7 @@ endif " Remap insert Ctrl-C to undo the escaped insert operation, but don't break " the key if the plugin isn't there -if globpath(&runtimepath, 'plugin/insert_cancel.vim') +if globpath(&runtimepath, 'plugin/insert_cancel.vim') !=# '' \ && &loadplugins imap (InsertCancel) endif -- cgit v1.2.3 From 2323103d1e98126533c81bcaf5965c1f1c08008d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:40:26 +1200 Subject: Break a paragraph --- vim/vimrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 07f39b15..1f2042eb 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -45,8 +45,9 @@ if !exists('$MYVIM') && &runtimepath !=# '' " Splitting the values of a comma-separated option like 'runtimepath' " correctly is a bit more complicated than it seems. The list separator is " more accurately defined as a comma that is not preceded by a backslash, and - " which is followed by any number of spaces and/or further commas. The - " pattern breaks down like this: + " which is followed by any number of spaces and/or further commas. + " + " The pattern breaks down like this: " " \\ Literal backslash " \@ Date: Sat, 8 Jun 2019 23:41:27 +1200 Subject: Adjust split explanation --- vim/vimrc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 1f2042eb..3e3f54cc 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -47,7 +47,7 @@ if !exists('$MYVIM') && &runtimepath !=# '' " more accurately defined as a comma that is not preceded by a backslash, and " which is followed by any number of spaces and/or further commas. " - " The pattern breaks down like this: + " The pattern required for the split breaks down like this: " " \\ Literal backslash " \@ Date: Sat, 8 Jun 2019 23:42:06 +1200 Subject: Flesh out a comment --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 3e3f54cc..8ccfa18f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -86,7 +86,7 @@ endif " If we have a directory creation function, and the cache directory doesn't " already exist, create it. This will be where backup, swap, undo, and -" viminfo files are stored. +" viminfo files are stored, each in their own directories. " if exists('*mkdir') && !isdirectory($MYVIM.'/cache') call mkdir($MYVIM.'/cache', 'p', 0700) -- cgit v1.2.3 From d0db61f539bacafb5cb5e08b9574bce0e06264cb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 8 Jun 2019 23:48:25 +1200 Subject: Move and more thoroughly explain 'path' settings --- vim/vimrc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 8ccfa18f..ee685c6d 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -274,6 +274,12 @@ endif " set comments= commentstring= define= include= +" Similarly to the above, the default value for 'path' that lists directories +" in which project files and includes can be found adds /usr/include, which is +" another C default, so we'll get rid of that, too. +" +set path-=/usr/include + " Rather than rejecting operations like :write or :saveas when 'readonly' is " set, and other situations in which data might be lost or I'm acting against " an option, Vim should give me a prompt to allow me to confirm that I know @@ -511,9 +517,6 @@ set nomodeline " Treat numbers with a leading zero as decimal, not octal set nrformats-=octal -" Don't search /usr/include by default -set path-=/usr/include - " Disable command line display of file position if a system vimrc or Neovim " has switched it on set noruler -- cgit v1.2.3 From 163f8b1c8d40f6acbb3f83f358a6b2a8817d68d6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:08:18 +1200 Subject: Change heading underline --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index ee685c6d..5c9b2a37 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1,6 +1,6 @@ " " Tom Ryder (tejr)'s vimrc -" ------------------------ +" ======================== " " " -- cgit v1.2.3 From 7718e5d6ef29a9bf0d99851a97859ffdf99468bf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:09:05 +1200 Subject: Move 'runtimepath' manipulation to top of file --- vim/vimrc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 5c9b2a37..f84a66bc 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -23,13 +23,21 @@ " > --Tennyson " -" The first thing we'll do is set an environment variable MYVIM for the user -" runtime directory, if such a variable does not already exist in the -" environment, and there's a value in 'runtimepath' from which to glean -" a useable path. 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 writeable location for Vim-related -" files. +" We'll start by removing unwanted addenda to 'runtimepath' from Debian +" GNU/Linux's debian.vim, so that any Vim script installed at the system level +" is ignored, since we don't want it interfering with our personal setup. +" This doesn't raise an error if the paths aren't present, so we don't need to +" check if they're already there. +" +set runtimepath-=/var/lib/vim/addons runtimepath-=/var/lib/vim/addons/after + +" With 'runtimepath' cleaned up, the next thing we'll do is set an environment +" variable MYVIM for the user runtime directory, if such a variable does not +" already exist in the environment, and there's a value in 'runtimepath' from +" which to glean a useable path. 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 writeable +" location for Vim-related files. " " 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 @@ -521,10 +529,6 @@ set nrformats-=octal " has switched it on set noruler -" Remove Debian's 'runtimepath' addenda if present -set runtimepath-=/var/lib/vim/addons -set runtimepath-=/var/lib/vim/addons/after - " Make sessions usable set sessionoptions-=localoptions " No buffer options or mappings set sessionoptions-=options " No global options or mappings -- cgit v1.2.3 From a37492688b63b8ca0d091f19f7b12a4d5774ea09 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:10:04 +1200 Subject: Group 'showmatch' and 'matchtime' meaningfully --- vim/vimrc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index f84a66bc..0fd6dea9 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -516,8 +516,11 @@ set listchars+=extends:> " Unwrapped text to screen right set listchars+=precedes:< " Unwrapped text to screen left set listchars+=nbsp:+ " Non-breaking spaces -" Show matching brackets a bit more briefly -set matchtime=3 +" I like the brief jump to the matching brackets provided by the 'showmatch' +" option; the only change I want is for it to be a little quicker, so we'll +" adjust that to 0.3 seconds. +" +set showmatch matchtime=3 " Don't allow setting options via buffer content set nomodeline @@ -539,9 +542,6 @@ set shortmess+=I " Prefix wrapped rows with three dots set showbreak=... -" Jump to matching bracket when typed in insert mode -set showmatch - " New window positioning set splitbelow " Below the current window, not above set splitright " Right of the current window, not left -- cgit v1.2.3 From a3b40ca5c1086df59c688bba5f4896f572beec5f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:12:19 +1200 Subject: Adjust commentary around indent settings --- vim/vimrc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 0fd6dea9..bdee108d 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -148,18 +148,19 @@ if exists('##SourceCmd') \|endif endif -" Global indent and other whitespace-related settings go here. 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. " -" In general, however, I prefer spaces to tabs as a default, 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. +" 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. " " " +" 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 -- cgit v1.2.3 From 40930c55ad6e96be020054167a171f7795b5ad76 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:12:38 +1200 Subject: Move C resets further up --- vim/vimrc | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index bdee108d..13d74520 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -148,7 +148,39 @@ if exists('##SourceCmd') \|endif endif +" We'll start our options by modernising a little in adjusting some options +" with language-specific defaults. " +" Traditional vi was often used for development in the C programming language. +" The default values for a lot of Vim's options still reflect this common use +" pattern. In this case, the 'comments' and 'commentstring' options reflect +" the C syntax for comments: +" +" /* +" * This is an ANSI C comment. +" */ +" +" Similarly, the 'define' and 'include' options default to C preprocessor +" directives: +" +" #define FOO "bar" +" +" #include "baz.h" +" +" Times change, however, and I don't get to work with C nearly as much as I'd +" like. The defaults for these options no longer make sense, and so we blank +" them, compelling filetype plugins to set them as they need instead. +" +set comments= commentstring= define= include= + +" 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, +" its default value comprises /usr/include, which is another C default. Let's +" get rid of that, too. +" +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, @@ -261,34 +293,6 @@ if exists('+breakindent') set breakindent endif -" Traditional vi was often used for development in the C programming language. -" The default values for a lot of Vim's options still reflect this common use -" pattern. In this case, the 'comments' and 'commentstring' options reflect -" the C syntax for comments: -" -" /* -" * This is an ANSI C comment. -" */ -" -" Similarly, the 'define' and 'include' options default to C preprocessor -" directives: -" -" #define FOO "bar" -" -" #include "baz.h" -" -" Times change, however, and I don't get to work with C nearly as much as I'd -" like. The defaults for these options no longer make sense, and so we blank -" them, compelling filetype plugins to set them as they need instead. -" -set comments= commentstring= define= include= - -" Similarly to the above, the default value for 'path' that lists directories -" in which project files and includes can be found adds /usr/include, which is -" another C default, so we'll get rid of that, too. -" -set path-=/usr/include - " Rather than rejecting operations like :write or :saveas when 'readonly' is " set, and other situations in which data might be lost or I'm acting against " an option, Vim should give me a prompt to allow me to confirm that I know -- cgit v1.2.3 From dc7ece895b75c0479e05a0e552628217a287e3b0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:12:46 +1200 Subject: Develop commentary of 'modeline' awfulness --- vim/vimrc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 13d74520..81a0add5 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -527,7 +527,15 @@ set listchars+=nbsp:+ " Non-breaking spaces " set showmatch matchtime=3 -" Don't allow setting options via buffer content +" Don't let your editor's options be configured by content in arbitrary files! +" Down with modelines! Purge them from your files! Écrasez l'infâme! +" +" I think that modelines are Vim's worst misfeature, and that 'nomodeline' +" should be the default. It's enabled pretty bad security vulnerabilities +" over the years, and it's a lot more effective to use filetype detection, +" other automatic command hooks, or systems like .editorconfig to set +" variables specifically for a buffer or project. +" set nomodeline " Treat numbers with a leading zero as decimal, not octal -- cgit v1.2.3 From 63ef4b4e9644c2d12addc299c07e4b3cd898f16e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 9 Jun 2019 00:20:01 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index c6858be6..88b0abad 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v5.22.0 -Thu Jun 6 22:49:16 UTC 2019 +tejr dotfiles v5.23.0 +Sat Jun 8 12:20:01 UTC 2019 -- cgit v1.2.3