From 17eaf19e06f5e39fcc6fe79e2d4be5e7479d4550 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 10 Jun 2019 22:43:13 +1200 Subject: Update vim-cursorline-current to v2.0.0 --- vim/bundle/cursorline_current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current index bfb65858..7d7f94b6 160000 --- a/vim/bundle/cursorline_current +++ b/vim/bundle/cursorline_current @@ -1 +1 @@ -Subproject commit bfb65858ea696cf1ed5ad2c8ed6d2174c28a7801 +Subproject commit 7d7f94b61580eb18fcdb31e2122ca5584c0951a0 -- cgit v1.2.3 From bd2a2fb0de6db776acb98197a6066b9da3594846 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 10 Jun 2019 22:49:19 +1200 Subject: Update vim-cursorline-current to v2.0.1 --- vim/bundle/cursorline_current | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/cursorline_current b/vim/bundle/cursorline_current index 7d7f94b6..a4261e15 160000 --- a/vim/bundle/cursorline_current +++ b/vim/bundle/cursorline_current @@ -1 +1 @@ -Subproject commit 7d7f94b61580eb18fcdb31e2122ca5584c0951a0 +Subproject commit a4261e155c850d4cf8a2624b7a155d69b1bd0421 -- cgit v1.2.3 From d249084db5d90f006ac73b441c24a977bcf2e4b4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:07:47 +1200 Subject: Lots more progress on documentating literate vimrc --- vim/vimrc | 549 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 350 insertions(+), 199 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index d044ff74..013786f6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -988,11 +988,9 @@ endtry " * Avoid shadowing any of Vim's existing functionality. If possible, extend " or supplement what Vim does, rather than replacing it. " - -" We'll start with the non-leader mappings. Ideally there shouldn't be too +" We'll start with the non-leader mappings. Ideally, there shouldn't be too " many of these. " - " I like using the space bar to scroll down a page, so I can lazily tap it to " read documents, and I find its default behaviour of moving right one " character to be useless. @@ -1101,322 +1099,475 @@ endif imap \ (DigraphSearch) -" Stack Ctrl-L to clear search highlight, make it work in insert mode too +" I end up hitting CTRL-L to clear or redraw the screen in interactive shells +" and tools like Mutt and Vim pretty often. It feels natural to me to stack +" issuing a :nohlsearch command to stop highlighting searches on top of this. +" +" This gets by far the most use in normal mode, but I'd like it to work in +" visual and insert mode, too, where it's occasionally useful, especially on +" things like mobile phone terminal emulators that can be choppy and require +" a lot of redrawing. +" +" For each of these, we end the mapping with a CTRL-L in normal mode, thereby +" extending rather than replacing Vim's normal behaviour. +" nnoremap \ :nohlsearch + +" We use :vnoremap rather than :xnoremap and thereby make the mapping apply to +" select mode as well, because CTRL-L doesn't reflect a printable character, +" and so we may as well, even though I never use select mode directly. +" vnoremap \ :nohlsearchgv + +" The insert mode mapping uses CTRL-O to issue a single normal normal-mode +" command, but twice: once to issue the :nohlsearch command, and then once to +" issue an unmapped normal-mode CTRL-L. +" inoremap \ :nohlsearch -" Remap normal/visual & and g& to preserve substitution flags +" By default, the very-useful normal mode command '&' that repeats the +" previous :substitute command doesn't preserve the flags from that +" substitution. I'd prefer it to do so, like the :&& command does, and it's +" easily remapped for both normal and visual mode, so let's just do it. +" nnoremap & \ :&& xnoremap & \ :&& -nnoremap g& - \ :%&& -" Map g: as a 'colon operator' +" I really like using the '!' command in normal mode as an operator to filter +" text through a shell command. It always bugged me a little that there +" didn't seem to be an analogue for a motion to filter text through an +" internal command like :sort, so I wrote one. +" nmap g: \ (ColonOperator) -" Cycle through argument list +" I used Tim Pope's unimpaired.vim plugin for ages, and I liked some of these +" bracket pair mappings, so I've carried a few of the simpler ones over. All +" of these can be prefixed with a count if needed, too. I use all of them +" pretty regularly, even though cycling through lists to look for something +" can be a bit wasteful. +" + +" Argument list nnoremap [a \ :previous nnoremap ]a \ :next -" Cycle through buffers +" Buffers nnoremap [b \ :bprevious nnoremap ]b \ :bnext -" Cycle through quickfix list items +" Quickfix list nnoremap [c \ :cprevious nnoremap ]c \ :cnext -" Cycle through location list items +" Location list nnoremap [l \ :lprevious nnoremap ]l \ :lnext -" Insert blank lines around current line +" Here's another mapping I particularly liked from unimpaired.vim here; insert +" blank lines from normal mode, using a custom plugin of mine called +" put_blank_lines.vim. These use operator functions so that they're +" repeatable without repeat.vim. They accept count prefixes, too. +" nmap [ \ (PutBlankLinesAbove) nmap ] \ (PutBlankLinesBelow) -" Set leader keys +" We're on to the leader maps, now. It's difficult to know what order to put +" these in; I originally had them in alphabetical order, but it seems more +" useful now to group the by the category of their function, albeit roughly. +" +" First of all, let's set the leader keys; backslash happens to be the +" default, but I like to make my choice explicit here. +" +" As of 2019, I'm still not certain that comma is the best choice for my local +" leader. I use it all the time for this purpose, and it works well, but +" I don't much like that it shadows a useful function in the fFtT;, group, and +" wonder if I would use it more if I hadn't shadowed it. +" let mapleader = '\' let maplocalleader = ',' -" Leader,a toggles 'formatoptions' 'a' flag using a plugin -nnoremap a - \ :ToggleFlagLocal formatoptions a - -" Leader,b toggles settings friendly to copying and pasting -nmap b - \ (CopyLinebreakToggle) +" Let's start with some simple ones; these ones all just toggle a boolean +" option, and print its new value. They're dirt simple to specify, and don't +" require any plugins. +" +" These are sometimes applicable in visual mode, and sometimes not. We'll +" start with the ones that only make sense as normal mode maps. Interesting, +" a visual mode mapping for 'cursorline' toggling doesn't work at all; +" 'cursorline' is always off when in any visual mode, including block mode, +" where it actually might have been really handy. -" Leader,c toggles 'cursorline'; no visual mode map as it doesn't work +"" Leader,TAB toggles automatic indentation based on the previous line +nnoremap + \ :setlocal autoindent! autoindent? +"" Leader,c toggles highlighted cursor row; doesn't work in visual mode nnoremap c \ :setlocal cursorline! cursorline? -" Leader,C toggles 'cursorcolumn'; works in visual mode +"" Leader,h toggles highlighting search results +nnoremap h + \ :set hlsearch! hlsearch? +"" Leader,i toggles showing matches as I enter my pattern +nnoremap i + \ :set incsearch! incsearch? +"" Leader,s toggles spell checking +nnoremap s + \ :setlocal spell! spell? + +" The next group of option-toggling maps are much the same as the previous +" group, except they also include analogous maps for visual mode, defined as +" recursive maps into normal mode that conclude with re-selecting the text. + +"" Leader,C toggles highlighted cursor column; works in visual mode nnoremap C \ :setlocal cursorcolumn! cursorcolumn? -xnoremap C - \ :setlocal cursorcolumn! cursorcolumn?gv +xmap C + \ Cgv +"" Leader,l toggles showing tab, end-of-line, and trailing white space +nnoremap l + \ :setlocal list! list? +xmap l + \ lgv +"" Leader,n toggles line number display +nnoremap n + \ :setlocal number! number? +xmap n + \ ngv +"" Leader,N toggles position display in bottom right +nnoremap N + \ :set ruler! ruler? +xmap N + \ Ngv +"" Leader,p toggles paste mode +nnoremap p + \ :set paste! paste? +xmap p + \ pgv +"" Leader,w toggles soft wrapping +nnoremap w + \ :setlocal wrap! wrap? +xmap w + \ wgv -" Insert an RFC2822-compliant date string into the buffer -command! -range PutDate - \ put =strftime('%a, %d %b %Y %T %z') +" This next one just shows option state of the 'formatoptions' affecting how +" text is automatically formatted; it doesn't change its value. + +"" Leader,f shows the current 'formatoptions' at a glance +nnoremap f + \ :setlocal formatoptions? + +" I often have to switch between US English and NZ English. The latter is +" almost exactly the same as UK English in most locales, although we use +" dollars rather than pounds. This is mostly so I remember things like +" excluding or including the 'u' in words like 'favourite', depending on the +" target audience. I generally use US English for international audiences. + +"" Leader,u sets US English spelling language +nnoremap u + \ :setlocal spelllang=en_us +"" Leader,z sets NZ English spelling language +nnoremap z + \ :setlocal spelllang=en_nz + +" The next mapping is another option toggler, but it's more complicated; it +" uses a simple plugin of mine called copy_linebreak.vim to manage several +" options at once, related to the 'wrap' option that soft-wraps text. +" +" It's designed for usage in terminal emulators and multiplexers to +" temporarily make the buffer text suitable for copying in such a way that the +" wrapping and any associated soft formatting won't pervert the text, +" including 'breakindent', 'linebreak', and 'showbreak' artifacts. +" +" This is really handy for quick selections of small regions of text. For +" larger blocks of text or for programatically manipulating the text as it +" leaves the buffer, it makes more sense to use :! commands. +" + +"" Leader,b toggles settings friendly to copying and pasting +nmap b + \ (CopyLinebreakToggle) + +" The above mappings show that mappings for toggling boolean options are +" simple, but there isn't a way to toggle single flags within option strings, +" so I wrote a plugin called toggle_flags.vim to provide :ToggleFlag and +" :ToggleFlagLocal commands. The first argument is the name of an option, and +" the second is the flag within it that should be toggled on or off. + +"" Leader,a toggles 'formatoptions' 'a' auto-flowing flag +nnoremap a + \ :ToggleFlagLocal formatoptions a +"" Leader,L toggles 'colorcolumn' showing the first column beyond 'textwidth' +nnoremap L + \ :ToggleFlagLocal colorcolumn +1 +xmap L + \ Lgv + +" These mappings are for managing filetypes. The first one uses the +" :FileTypeReload command that was defined much earlier in this file.for +" a vimrc reload hook. + +"" Leader,F reloads filetype plugins +nnoremap F + \ :FileTypeReload +"" Leader,t shows current filetype +nnoremap t + \ :setlocal filetype? +"" Leader,T clears filetype +nnoremap T + \ :setlocal filetype= " Set up a quick command-function pair to run a command with the UTC timezone, -" in this case, for my date-printing mappings. Is there a nicer way to do -" this? I couldn't find one. +" in this case, for my date-printing mappings. To do this, we define two new +" commands, one of which uses a script-local function. +" +" While this is a tidy way to abstract the operation for the map, I don't like +" the function implementation much at all. It works OK in stable versions of +" Vim, but changing an environment variable just long enough to affect the +" outcome of a command as a side effect seems a bit gross. +" +" Worse, the whole thing presently seems to be broken in v8.1.1487; the +" timezone first chosen seems to 'stick' permanently, and the mapping each +" produce timestamps in that zone. I haven't worked out why this happens yet. +" Using the new getenv() and setenv() functions does not seem to fix it. It +" works fine in Debian GNU/Linux's packaged v8.0.x. + +" First, of all, we define a :PutDate command that inserts a line into the buffer with +" an RFC-2822 date string, using the system strftime() implementation. This +" might be useful outside of the vimrc, too; we allow it to accept a range +" which defaults to the current line. " -" This presently seems to be broken in v8.1.1487; the timezone first chosen -" seems to 'stick' permanently. I haven't worked out why yet. Using the new -" getenv() and setenv() functions does not seem to fix it. It works fine in -" Debian GNU/Linux's packaged v8.0.x. +command! -range PutDate + \ put =strftime('%a, %d %b %Y %T %z') + +" Next, we define a :UTC command wrapper, implemented with a script-local +" function of the same name. We use expand('$TZ') to ensure we're getting the +" value of the current timezone from the environment, and cache that in +" a local variable just long enough to manipulate the environment into using +" UTC for a command, in our case, the newly-defined :PutDate command. " function! s:UTC(command) abort let tz = expand('$TZ') let $TZ = 'UTC' | execute a:command | let $TZ = tz endfunction + +" The :UTC command itself completes another command name, and accepts one +" required argument, which it passes in quoted form to the helper function. +" command! -complete=command -nargs=1 UTC \ call s:UTC() -" Leader,d inserts the local date (RFC 2822) +" And finally, we define the maps that actually use the commands. + +"" Leader,d inserts the local date (RFC 2822) nnoremap d \ :PutDate -" Leader,D inserts the UTC date (RFC 2822) +"" Leader,D inserts the UTC date (RFC 2822) nnoremap D \ :UTC PutDate -" Leader,e forces a buffer to be editable -nnoremap e - \ :setlocal modifiable noreadonly - -" Leader,f shows the current 'formatoptions' at a glance -nnoremap f - \ :setlocal formatoptions? - -" Leader,F reloads filetype plugins -nnoremap F - \ :FileTypeReload +" This group contains mappings that are to do with file and path management +" relative to the current buffer. -" Leader,g shows the current file's fully expanded path +"" Leader,g shows the current file's fully expanded path nnoremap g \ :echo expand('%:p') -" Leader,G changes directory to the current file's location +"" Leader,G changes directory to the current file's location nnoremap G \ :cd %:hpwd +"" Leader,P creates the path to the current file +nnoremap P + \ :call mkdir(expand('%:h'), 'p') -" Leader,h toggles highlighting search results -nnoremap h - \ :set hlsearch! hlsearch? +" This group contains mappings that show information about Vim's internals: +" marks, registers, variables, and the like. -" Leader,H shows command history +"" Leader,H shows command history nnoremap H \ :history : - -" Leader,i toggles showing matches as I enter my pattern -nnoremap i - \ :set incsearch! incsearch? - -" Leader,j jumps to buffers ("jetpack") -nnoremap j - \ :buffers:buffer - -" Leader,k shows my marks +"" Leader,k shows my marks nnoremap k \ :marks - -" Leader,l toggles showing tab, end-of-line, and trailing white space -nnoremap l - \ :setlocal list! list? -xnoremap l - \ :setlocal list! list?gv - -" Leader,L toggles 'colorcolumn' showing 'textwidth' -nnoremap L - \ :ToggleFlagLocal colorcolumn +1 -xnoremap L - \ :ToggleFlagLocal colorcolumn +1gv - -" Leader,m shows normal maps +"" Leader,m shows normal maps nnoremap m \ :map -" Leader,M shows buffer-local normal maps +"" Leader,M shows buffer-local normal maps nnoremap M \ :map - -" Leader,n toggles line number display -nnoremap n - \ :setlocal number! number? -xnoremap n - \ :setlocal number! number?gv -" Leader,N toggles position display in bottom right -nnoremap N - \ :set ruler! ruler? -xnoremap N - \ :set ruler! ruler?gv - -" Leader,o opens a line below in paste mode -nmap o - \ (PasteOpenBelow) -" Leader,O opens a line above in paste mode -nmap O - \ (PasteOpenAbove) - -" Leader,p toggles paste mode -nnoremap p - \ :set paste! paste? - -" Leader,P creates the path to the current file -nnoremap P - \ :call mkdir(expand('%:h'), 'p') - -" Leader,q formats the current paragraph -nnoremap q - \ gqap - -" Leader,r acts as a replacement operator -nmap r - \ (ReplaceOperator) -xmap r - \ (ReplaceOperator) - -" Leader,R reloads ~/.vimrc -nnoremap R - \ :source $MYVIMRC - -" Leader,s toggles spell checking -nnoremap s - \ :setlocal spell! spell? - -" Leader,S shows loaded scripts +"" Leader,S shows loaded scripts nnoremap S \ :scriptnames - -" Leader,t shows current filetype -nnoremap t - \ :setlocal filetype? -" Leader,T clears filetype -nnoremap T - \ :setlocal filetype= - -" Leader,u sets US English spelling (compare Leader,z) -nnoremap u - \ :setlocal spelllang=en_us - -" Leader,v shows all global variables +"" Leader,v shows all global variables nnoremap v \ :let g: v: -" Leader,V shows all local variables +"" Leader,V shows all local variables nnoremap V \ :let b: t: w: +"" Leader,y shows all registers +nnoremap y + \ :registers -" Leader,w toggles wrapping -nnoremap w - \ :setlocal wrap! wrap? -xnoremap w - \ :setlocal wrap! wrap?gv +" This group contains mappings concerned with buffer navigation and +" management. I use the "jetpack" buffer jumper one like crazy; I really like +" it. I got it from one of bairui's "Vim and Vigor" comics: +" +" + +"" Leader,DEL deletes the current buffer +nnoremap + \ :bdelete +"" Leader,INS edits a new buffer +nnoremap + \ :enew +"" Leader,e forces a buffer to be editable, even a :help one +nnoremap e + \ :setlocal modifiable noreadonly +"" Leader,E locks a buffer, reversible with e +nnoremap e + \ :setlocal nomodifiable readonly +"" Leader,j jumps to buffers ("jetpack") +nnoremap j + \ :buffers:buffer + +" Filtering and batch operations to clean up buffer text -" Leader,x strips trailing whitespace via a custom plugin +"" Leader,x strips trailing whitespace via a custom plugin nnoremap x \ :StripTrailingWhitespace xnoremap x \ :StripTrailingWhitespace - -" Leader,X squeezes repeated blank lines via a custom plugin +"" Leader,X squeezes repeated blank lines via a custom plugin nnoremap X \ :SqueezeRepeatBlanks xnoremap X \ :SqueezeRepeatBlanks - -" Leader,y shows all registers -nnoremap y - \ :registers - -" Leader,z sets NZ English spelling (compare Leader,u) -nnoremap z - \ :setlocal spelllang=en_nz - -" Leader,= runs the whole buffer through =, preserving position +"" Leader,= runs the whole buffer through =, preserving position nnoremap = \ :KeepPosition normal! 1G=G -" Leader,+ runs the whole buffer through gq, preserving position +"" Leader,+ runs the whole buffer through gq, preserving position nnoremap + \ :KeepPosition normal! 1GgqG -" Leader,. runs the configured make program into the location list -nnoremap . - \ :lmake! - -" Leader,< and Leader,> adjust indent of last edit; good for pasting -nnoremap - \ :'[,'] -nnoremap > - \ :'[,']> +" This group defines a few :onoremap commands to make my own text objects. +" I should probably make some more of these, as they've proven to be +" terrifically handy. -" Leader,_ uses last changed or yanked text as an object +"" Leader,_ uses last changed or yanked text as an object onoremap _ \ :normal! `[v`] - -" Leader,% uses entire buffer as an object +"" Leader,% uses entire buffer as an object onoremap % \ :normal! 1GVG -" Leader,{ and Leader,} move to lines with non-space chars before current column +" This group defines some useful motions. + +"" Leader,{ and Leader,} move to lines with non-space chars before current column map { \ (VerticalRegionUp) sunmap { map } \ (VerticalRegionDown) sunmap } +"" Leader,\ jumps to the last edit position mark: think "Now, where was I?" +nnoremap \ + \ `" +xnoremap \ + \ `" + +" This group does both: useful motions on defined text objects. -" Leader,/ types :vimgrep for me ready to enter a search pattern +"" Leader,< and Leader,> adjust indent of last edit; good for pasting +nnoremap + \ :'[,'] +nnoremap > + \ :'[,']> + +" This group is for directory tree or help search convenience mappings. + +"" Leader,/ types :vimgrep for me ready to enter a search pattern nnoremap / \ :vimgrep /\c/j ** -" Leader,? types :lhelpgrep for me ready to enter a search pattern +"" Leader,? types :lhelpgrep for me ready to enter a search pattern nnoremap ? \ :lhelpgrep \c -" Leader,* escapes regex metacharacters +" This group contains miscellaneous mappings for which I couldn't find any +" other place. The plugin mappings probably require their own documentation +" comment block, but my hands are getting tired from all this typing. + +"" Leader,. runs the configured make program into the location list +nnoremap . + \ :lmake! +"" Leader,o opens a line below in paste mode +nmap o + \ (PasteOpenBelow) +"" Leader,O opens a line above in paste mode +nmap O + \ (PasteOpenAbove) +"" Leader,q formats the current paragraph +nnoremap q + \ gqap +"" Leader,r acts as a replacement operator +nmap r + \ (ReplaceOperator) +xmap r + \ (ReplaceOperator) +"" Leader,* escapes regex metacharacters nmap * \ (RegexEscape) xmap * \ (RegexEscape) -" Leader,\ jumps to the last edit position mark, like g;, but works as a motion -" "Now, where was I?" (tap-tap) -nnoremap \ - \ `" -xnoremap \ - \ `" - -" Leader,DEL deletes the current buffer -nnoremap - \ :bdelete -" Leader,INS edits a new buffer -nnoremap - \ :enew +" And last, but definitely not least, I'm required by Vim fanatic law to +" include a mapping that reloads my whole configuration. Doing this triggers +" the #vimrc#SourceCmd hooks defined much earlier in the file so that +" filetypes get reloaded afterwards, so I don't need to follow R with +" a F. -" Leader,TAB toggles 'autoindent' -nnoremap - \ :setlocal autoindent! autoindent? - -" Some useful abbreviations -inoreabbrev tr@ tom@sanctum.geek.nz -inoreabbrev tr/ +"" Leader,R reloads ~/.vimrc +nnoremap R + \ :source $MYVIMRC -" THe things I almsot always type wrnog -inoreabbrev almsot almost -inoreabbrev wrnog wrong -inoreabbrev Fielding Feilding -inoreabbrev THe The -inoreabbrev THere There +" I'll close this file with a few abbreviations. Perhaps of everything in +" here, I'm least confident that these should be in here, but they've proven +" pretty useful. First, some 'deliberate' abbreviations for stuff I type +" a lot: +" +inoreabbrev tr@ + \ tom@sanctum.geek.nz +inoreabbrev tr/ + \ + +" And then, just fix some typographical and spelling errors for me +" automatically. +" +inoreabbrev almsot + \ almost +inoreabbrev wrnog + \ wrong +inoreabbrev Fielding + \ Feilding +inoreabbrev THe + \ The +inoreabbrev THere + \ There + +" Here endeth the literate vimrc. +" +" > Consequently, it is soon recognised that they write for the sake of +" > filling up the paper, and this is the case sometimes with the best +" > authors; for example, in parts of Lessing’s Dramaturgie, and even in many +" > of Jean Paul’s romances. As soon as this is perceived the book should be +" > thrown away, for time is precious. +" > -- Schopenhauer +" -- cgit v1.2.3 From 1a184d420e565fdcf8bfd4496fb65e63c480c521 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:40:50 +1200 Subject: Inline a few non-command-line mappings and abbrevs --- vim/vimrc | 109 +++++++++++++++++++++----------------------------------------- 1 file changed, 37 insertions(+), 72 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 013786f6..29479a1a 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1012,13 +1012,10 @@ endtry " " I always wanted you to go into space, man. " -if globpath(&runtimepath, 'plugin/scroll_next.vim') !=# '' - \ && &loadplugins - nmap - \ (ScrollNext) +if &loadplugins && globpath(&runtimepath, 'plugin/scroll_next.vim') !=# '' + nmap (ScrollNext) else - nnoremap - \ + nnoremap endif " I hate CTRL-C in insert mode, which ends the insert session without firing @@ -1058,10 +1055,8 @@ endif " If the plugin isn't available, I just abandon CTRL-C to continue its " uselessness. " -if globpath(&runtimepath, 'plugin/insert_cancel.vim') !=# '' - \ && &loadplugins - imap - \ (InsertCancel) +if &loadplugins && globpath(&runtimepath, 'plugin/insert_cancel.vim') !=# '' + imap (InsertCancel) endif " I often don't remember or can't guess digraph codes very well, and want to @@ -1096,8 +1091,7 @@ endif " checking that the plugin's available before we map to it; it'll just quietly " do nothing. " -imap - \ (DigraphSearch) +imap (DigraphSearch) " I end up hitting CTRL-L to clear or redraw the screen in interactive shells " and tools like Mutt and Vim pretty often. It feels natural to me to stack @@ -1143,8 +1137,7 @@ xnoremap & " didn't seem to be an analogue for a motion to filter text through an " internal command like :sort, so I wrote one. " -nmap g: - \ (ColonOperator) +nmap g: (ColonOperator) " I used Tim Pope's unimpaired.vim plugin for ages, and I liked some of these " bracket pair mappings, so I've carried a few of the simpler ones over. All @@ -1179,10 +1172,8 @@ nnoremap ]l " put_blank_lines.vim. These use operator functions so that they're " repeatable without repeat.vim. They accept count prefixes, too. " -nmap [ - \ (PutBlankLinesAbove) -nmap ] - \ (PutBlankLinesBelow) +nmap [ (PutBlankLinesAbove) +nmap ] (PutBlankLinesBelow) " We're on to the leader maps, now. It's difficult to know what order to put " these in; I originally had them in alphabetical order, but it seems more @@ -1232,33 +1223,27 @@ nnoremap s "" Leader,C toggles highlighted cursor column; works in visual mode nnoremap C \ :setlocal cursorcolumn! cursorcolumn? -xmap C - \ Cgv +xmap C Cgv "" Leader,l toggles showing tab, end-of-line, and trailing white space nnoremap l \ :setlocal list! list? -xmap l - \ lgv +xmap l lgv "" Leader,n toggles line number display nnoremap n \ :setlocal number! number? -xmap n - \ ngv +xmap n ngv "" Leader,N toggles position display in bottom right nnoremap N \ :set ruler! ruler? -xmap N - \ Ngv +xmap N Ngv "" Leader,p toggles paste mode nnoremap p \ :set paste! paste? -xmap p - \ pgv +xmap p pgv "" Leader,w toggles soft wrapping nnoremap w \ :setlocal wrap! wrap? -xmap w - \ wgv +xmap w wgv " This next one just shows option state of the 'formatoptions' affecting how " text is automatically formatted; it doesn't change its value. @@ -1295,8 +1280,7 @@ nnoremap z " "" Leader,b toggles settings friendly to copying and pasting -nmap b - \ (CopyLinebreakToggle) +nmap b (CopyLinebreakToggle) " The above mappings show that mappings for toggling boolean options are " simple, but there isn't a way to toggle single flags within option strings, @@ -1310,8 +1294,7 @@ nnoremap a "" Leader,L toggles 'colorcolumn' showing the first column beyond 'textwidth' nnoremap L \ :ToggleFlagLocal colorcolumn +1 -xmap L - \ Lgv +xmap L Lgv " These mappings are for managing filetypes. The first one uses the " :FileTypeReload command that was defined much earlier in this file.for @@ -1385,9 +1368,9 @@ nnoremap g "" Leader,G changes directory to the current file's location nnoremap G \ :cd %:hpwd -"" Leader,P creates the path to the current file +"" Leader,P creates the path to the current file if it doesn't exist nnoremap P - \ :call mkdir(expand('%:h'), 'p') + \ :EnsureDir %:h " This group contains mappings that show information about Vim's internals: " marks, registers, variables, and the like. @@ -1472,17 +1455,13 @@ onoremap % " This group defines some useful motions. "" Leader,{ and Leader,} move to lines with non-space chars before current column -map { - \ (VerticalRegionUp) +map { (VerticalRegionUp) sunmap { -map } - \ (VerticalRegionDown) +map } (VerticalRegionDown) sunmap } "" Leader,\ jumps to the last edit position mark: think "Now, where was I?" -nnoremap \ - \ `" -xnoremap \ - \ `" +nnoremap \ `" +xnoremap \ `" " This group does both: useful motions on defined text objects. @@ -1509,24 +1488,17 @@ nnoremap ? nnoremap . \ :lmake! "" Leader,o opens a line below in paste mode -nmap o - \ (PasteOpenBelow) +nmap o (PasteOpenBelow) "" Leader,O opens a line above in paste mode -nmap O - \ (PasteOpenAbove) +nmap O (PasteOpenAbove) "" Leader,q formats the current paragraph -nnoremap q - \ gqap +nnoremap q gqap "" Leader,r acts as a replacement operator -nmap r - \ (ReplaceOperator) -xmap r - \ (ReplaceOperator) +nmap r (ReplaceOperator) +xmap r (ReplaceOperator) "" Leader,* escapes regex metacharacters -nmap * - \ (RegexEscape) -xmap * - \ (RegexEscape) +nmap * (RegexEscape) +xmap * (RegexEscape) " And last, but definitely not least, I'm required by Vim fanatic law to " include a mapping that reloads my whole configuration. Doing this triggers @@ -1543,24 +1515,17 @@ nnoremap R " pretty useful. First, some 'deliberate' abbreviations for stuff I type " a lot: " -inoreabbrev tr@ - \ tom@sanctum.geek.nz -inoreabbrev tr/ - \ +inoreabbrev tr@ tom@sanctum.geek.nz +inoreabbrev tr/ " And then, just fix some typographical and spelling errors for me " automatically. " -inoreabbrev almsot - \ almost -inoreabbrev wrnog - \ wrong -inoreabbrev Fielding - \ Feilding -inoreabbrev THe - \ The -inoreabbrev THere - \ There +inoreabbrev almsot almost +inoreabbrev wrnog wrong +inoreabbrev Fielding Feilding +inoreabbrev THe The +inoreabbrev THere There " Here endeth the literate vimrc. " -- cgit v1.2.3 From 07ffdf4fc7bb747bbccdb912e015a7e9d1ad0de2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:46:04 +1200 Subject: Move :PutDate and :UTC implementations into plugin --- vim/plugin/put_date.vim | 11 +++++++++++ vim/plugin/utc.vim | 31 +++++++++++++++++++++++++++++++ vim/vimrc | 43 ++----------------------------------------- 3 files changed, 44 insertions(+), 41 deletions(-) create mode 100644 vim/plugin/put_date.vim create mode 100644 vim/plugin/utc.vim diff --git a/vim/plugin/put_date.vim b/vim/plugin/put_date.vim new file mode 100644 index 00000000..29cf886e --- /dev/null +++ b/vim/plugin/put_date.vim @@ -0,0 +1,11 @@ +if exists('loaded_put_date') + finish +endif +let loaded_put_date = 1 + +" Define a :PutDate command that inserts a line into the buffer with an +" RFC-2822 date string, using the system strftime() implementation. Allow it +" to accept a range which defaults to the current line. +" +command! -range PutDate + \ put =strftime('%a, %d %b %Y %T %z') diff --git a/vim/plugin/utc.vim b/vim/plugin/utc.vim new file mode 100644 index 00000000..39eebad8 --- /dev/null +++ b/vim/plugin/utc.vim @@ -0,0 +1,31 @@ +if exists('loaded_utc') + finish +endif +let loaded_utc = 1 + +" Define a :UTC command wrapper, implemented with a script-local function of +" the same name. Use expand('$TZ') to ensure we're getting the value of the +" current timezone from the environment, and cache that in a local variable +" just long enough to manipulate the environment into using UTC for a command. +" +" While this is a tidy way to abstract the operation for the map, I don't like +" the function implementation much at all. It works OK in stable versions of +" Vim, but changing an environment variable just long enough to affect the +" outcome of a command as a side effect seems a bit gross. +" +" Worse, the whole thing presently seems to be broken in v8.1.1487; the +" timezone first chosen seems to 'stick' permanently, and the mapping each +" produce timestamps in that zone. I haven't worked out why this happens yet. +" Using the new getenv() and setenv() functions does not seem to fix it. It +" works fine in Debian GNU/Linux's packaged v8.0.x. + +function! s:UTC(command) abort + let tz = expand('$TZ') + let $TZ = 'UTC' | execute a:command | let $TZ = tz +endfunction + +" The :UTC command itself completes another command name, and accepts one +" required argument, which it passes in quoted form to the helper function. +" +command! -complete=command -nargs=1 UTC + \ call s:UTC() diff --git a/vim/vimrc b/vim/vimrc index 29479a1a..cc317820 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1310,47 +1310,8 @@ nnoremap t nnoremap T \ :setlocal filetype= -" Set up a quick command-function pair to run a command with the UTC timezone, -" in this case, for my date-printing mappings. To do this, we define two new -" commands, one of which uses a script-local function. -" -" While this is a tidy way to abstract the operation for the map, I don't like -" the function implementation much at all. It works OK in stable versions of -" Vim, but changing an environment variable just long enough to affect the -" outcome of a command as a side effect seems a bit gross. -" -" Worse, the whole thing presently seems to be broken in v8.1.1487; the -" timezone first chosen seems to 'stick' permanently, and the mapping each -" produce timestamps in that zone. I haven't worked out why this happens yet. -" Using the new getenv() and setenv() functions does not seem to fix it. It -" works fine in Debian GNU/Linux's packaged v8.0.x. - -" First, of all, we define a :PutDate command that inserts a line into the buffer with -" an RFC-2822 date string, using the system strftime() implementation. This -" might be useful outside of the vimrc, too; we allow it to accept a range -" which defaults to the current line. -" -command! -range PutDate - \ put =strftime('%a, %d %b %Y %T %z') - -" Next, we define a :UTC command wrapper, implemented with a script-local -" function of the same name. We use expand('$TZ') to ensure we're getting the -" value of the current timezone from the environment, and cache that in -" a local variable just long enough to manipulate the environment into using -" UTC for a command, in our case, the newly-defined :PutDate command. -" -function! s:UTC(command) abort - let tz = expand('$TZ') - let $TZ = 'UTC' | execute a:command | let $TZ = tz -endfunction - -" The :UTC command itself completes another command name, and accepts one -" required argument, which it passes in quoted form to the helper function. -" -command! -complete=command -nargs=1 UTC - \ call s:UTC() - -" And finally, we define the maps that actually use the commands. +" These mappings use my put_date.vim and utc.vim plugins for date insertion +" into the buffer. "" Leader,d inserts the local date (RFC 2822) nnoremap d -- cgit v1.2.3 From 3aedec1242fdab4f7a8aa664ebd25e81c302e406 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:47:32 +1200 Subject: Correct E map definition --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index cc317820..ba5d002c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1377,7 +1377,7 @@ nnoremap nnoremap e \ :setlocal modifiable noreadonly "" Leader,E locks a buffer, reversible with e -nnoremap e +nnoremap E \ :setlocal nomodifiable readonly "" Leader,j jumps to buffers ("jetpack") nnoremap j -- cgit v1.2.3 From 0ed9d81d707e9820dd92971eebbc6b0bafd43236 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:48:31 +1200 Subject: Remove bang from endfunction --- vim/plugin/spellfile_local.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index 583df986..e2ca8716 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -21,6 +21,6 @@ function! AddLocalSpellfile() abort \ ], '.') . '.add' setlocal spellfile< execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile -endfunction! +endfunction autocmd vimrc BufRead * \ call AddLocalSpellfile() | nnoremap zG 2zg -- cgit v1.2.3 From 2bf5da6cb888ee9e3870b0ef89e1fcfb0f0bbcaf Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:51:34 +1200 Subject: Trim Schopenhauer quote --- vim/vimrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index ba5d002c..7db066dc 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1492,8 +1492,7 @@ inoreabbrev THere There " " > Consequently, it is soon recognised that they write for the sake of " > filling up the paper, and this is the case sometimes with the best -" > authors; for example, in parts of Lessing’s Dramaturgie, and even in many -" > of Jean Paul’s romances. As soon as this is perceived the book should be -" > thrown away, for time is precious. +" > authors... as soon as this is perceived the book should be thrown away, +" > for time is precious. " > -- Schopenhauer " -- cgit v1.2.3 From 3076013c219097fcb7d619cd59058ddfc9eee483 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:55:26 +1200 Subject: Remove a comment line --- vim/vimrc | 1 - 1 file changed, 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 7db066dc..1178954c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1144,7 +1144,6 @@ nmap g: (ColonOperator) " of these can be prefixed with a count if needed, too. I use all of them " pretty regularly, even though cycling through lists to look for something " can be a bit wasteful. -" " Argument list nnoremap [a -- cgit v1.2.3 From 0e6a7173c57594e48e16415cad908706fc1986f0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 00:55:32 +1200 Subject: Make map display mapping reflect comment --- vim/vimrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 1178954c..32a96909 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -1343,10 +1343,10 @@ nnoremap k \ :marks "" Leader,m shows normal maps nnoremap m - \ :map + \ :nmap "" Leader,M shows buffer-local normal maps nnoremap M - \ :map + \ :nmap "" Leader,S shows loaded scripts nnoremap S \ :scriptnames -- cgit v1.2.3 From e3701ae3a97c425a6e805680a786c6b68786082d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:41:15 +1200 Subject: Check MYVIM is not blank in spellfile plugin --- vim/plugin/spellfile_local.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index e2ca8716..302854f4 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -1,4 +1,4 @@ -if exists('loaded_spellfile_local') +if exists('loaded_spellfile_local') || $MYVIM ==# '' finish endif let loaded_spellfile_local = 1 -- cgit v1.2.3 From e5accd86dee3530361525686531db9cf9e04fbe3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:42:43 +1200 Subject: Rearrange blocks in vimrc --- vim/vimrc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 32a96909..7dddad82 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -165,16 +165,6 @@ if $MYVIM !=# '' EnsureDir $MYVIM endif -" Create a 'vimrc' automatic command hook group, if it doesn't already exist, -" and clear away any automatic command hooks already defined within it if it -" does. This way, we don't end up collecting multiple copies of the hooks -" configured in the rest of this file if it's reloaded. I don't want to make -" the :augroup span the entire file, though. -" -augroup vimrc - autocmd! -augroup END - " 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 @@ -190,6 +180,16 @@ command! FileTypeReload \| doautocmd filetypedetect BufRead \|endif +" Create a 'vimrc' automatic command hook group, if it doesn't already exist, +" and clear away any automatic command hooks already defined within it if it +" does. This way, we don't end up collecting multiple copies of the hooks +" configured in the rest of this file if it's reloaded. I don't want to make +" the :augroup span the entire file, though. +" +augroup vimrc + autocmd! +augroup END + " Now we'll use that new :FileTypeReload command as part of an automatic " command hook that runs whenever this vimrc is sourced. " -- cgit v1.2.3 From fe0e62f71d89d3f39bba516f9cbddce9db16401e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:48:21 +1200 Subject: Factor out :FileTypeReload into a function --- vim/vimrc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 7dddad82..67f0bae8 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -175,10 +175,13 @@ endif " FileTypeReload, which just re-runs BufRead events for filetype detection if " they've been loaded. " +function! s:FileTypeReload() abort + if exists('did_load_filetypes') + doautocmd filetypedetect BufRead + endif +endfunction command! FileTypeReload - \ if exists('did_load_filetypes') - \| doautocmd filetypedetect BufRead - \|endif + \ call s:FileTypeReload() " Create a 'vimrc' automatic command hook group, if it doesn't already exist, " and clear away any automatic command hooks already defined within it if it -- cgit v1.2.3 From 31662311f9f8f65dd63be05c1474e5d3df77fa95 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:49:09 +1200 Subject: Move spellfile local mapping into function --- vim/plugin/spellfile_local.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index 302854f4..6e04babf 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -21,6 +21,7 @@ function! AddLocalSpellfile() abort \ ], '.') . '.add' setlocal spellfile< execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile + nnoremap zG 2zg endfunction autocmd vimrc BufRead * - \ call AddLocalSpellfile() | nnoremap zG 2zg + \ call AddLocalSpellFile() -- cgit v1.2.3 From d280a6d093cddeeb3c36cd9af7080cde85797a04 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:50:54 +1200 Subject: Factor our :AddLocalSpellFile command --- vim/plugin/spellfile_local.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index 6e04babf..b5db4518 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -24,4 +24,6 @@ function! AddLocalSpellfile() abort nnoremap zG 2zg endfunction autocmd vimrc BufRead * + +command! AddLocalSpellFile \ call AddLocalSpellFile() -- cgit v1.2.3 From 90ffd5eb85cf4c46db27f8cc4bb6df3d088fe81d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 09:51:15 +1200 Subject: Use dedicated augroup for local spellfile --- vim/plugin/spellfile_local.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index b5db4518..285618f8 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -23,7 +23,11 @@ function! AddLocalSpellfile() abort execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile nnoremap zG 2zg endfunction -autocmd vimrc BufRead * command! AddLocalSpellFile \ call AddLocalSpellFile() + +augroup spellfile_local + autocmd BufRead * + \ AddLocalSpellfile +augroup END -- cgit v1.2.3 From 40f378c7655e307954726ebd12bf22683c295a57 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:22:31 +1200 Subject: Correct case errors in local spell file names --- vim/plugin/spellfile_local.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index 285618f8..b6acd7b3 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -11,9 +11,9 @@ let spellfile = join([ \ ], '.') . '.add' execute 'set spellfile=$MYVIM/cache/spell/'.spellfile -EnsureDir $MYVIM/cache/spell/local +Establish $MYVIM/cache/spell/local -function! AddLocalSpellfile() abort +function! AddLocalSpellFile() abort let spellfile = join([ \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'), \ substitute(v:lang, '_.*', '', ''), @@ -29,5 +29,5 @@ command! AddLocalSpellFile augroup spellfile_local autocmd BufRead * - \ AddLocalSpellfile + \ AddLocalSpellFile augroup END -- cgit v1.2.3 From 6ffacb16a3cd02460bb72136aa4fbb946c510f08 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:28:46 +1200 Subject: Alter MYVIM semantics: don't allow outside setting Not that it's a bad idea, just that I don't need it yet. --- vim/plugin/spellfile_local.vim | 2 +- vim/vimrc | 79 ++++++++++++++++-------------------------- 2 files changed, 31 insertions(+), 50 deletions(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index b6acd7b3..9cb97624 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -1,4 +1,4 @@ -if exists('loaded_spellfile_local') || $MYVIM ==# '' +if exists('loaded_spellfile_local') finish endif let loaded_spellfile_local = 1 diff --git a/vim/vimrc b/vim/vimrc index 67f0bae8..2998d9d6 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -82,9 +82,8 @@ scriptencoding utf-8 " " Vim, I love you, but you are so weird. " -let runtimepath = split(&runtimepath, '\\\@ 0 - let $MYVIM = runtimepath[0] +if !exists('$MYVIM') + let $MYVIM = split(&runtimepath, '\\\@ 0 - \ && $MYVIM !=# runtimepath[0] - set runtimepath^=$MYVIM + finish endif " We're going to be creating a few directories, and the code to do so in @@ -161,9 +153,7 @@ command! -complete=dir -nargs=1 EnsureDir " exist, let's apply it for the first time, in making sure that the MYVIM " directory exists, if it's been set. " -if $MYVIM !=# '' - EnsureDir $MYVIM -endif +EnsureDir $MYVIM " 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 @@ -239,10 +229,8 @@ endif " a nicer way to set it with a 'viminfofile' option, but there's no particular " reason to use it until it's in a few more stable versions. " -if $MYVIM !=# '' - EnsureDir $MYVIM/cache - set viminfo+=n$MYVIM/cache/viminfo -endif +EnsureDir $MYVIM/cache +set viminfo+=n$MYVIM/cache/viminfo " Speaking of recorded data in viminfo files, the command and search history " count default limit of 50 is pretty restrictive. Because I don't think I'm @@ -345,13 +333,11 @@ set backup " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. " -if $MYVIM !=# '' - EnsureDir $MYVIM/cache/backup - if has('patch-8.1.251') - set backupdir^=$MYVIM/cache/backup// - else - set backupdir^=$MYVIM/cache/backup - endif +EnsureDir $MYVIM/cache/backup +if has('patch-8.1.251') + set backupdir^=$MYVIM/cache/backup// +else + set backupdir^=$MYVIM/cache/backup endif " Files in certain directories on Unix-compatible filesystems should not be @@ -435,10 +421,8 @@ set confirm " its name, in order to avoid filename collisions. Create that path if " needed, too. " -if $MYVIM !=# '' - EnsureDir $MYVIM/cache/swap - set directory^=$MYVIM/cache/swap// -endif +EnsureDir $MYVIM/cache/swap +set directory^=$MYVIM/cache/swap// " 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 @@ -758,10 +742,8 @@ if has('persistent_undo') " Vim to use the full path of the original file in its undo file cache's " name. " - if $MYVIM !=# '' - EnsureDir $MYVIM/cache/undo - set undodir^=$MYVIM/cache/undo// - endif + EnsureDir $MYVIM/cache/undo + set undodir^=$MYVIM/cache/undo// " Turn the persistent undo features on, regardless of whether we have " a cache directory for them as a result of the logic above. The files @@ -887,17 +869,16 @@ endif " first two metadata lines from thesaurus.txt, as Vim appeared to interpret " them as part of the body data. " -" The checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM -" need to be stricter than the ones for 'backupdir', because the P_NDNAME -" property is assigned to them, which enforces a character blacklist in the -" option value. We check for the same set of blacklist characters here, and -" if the MYVIM path offends, we just skip the setting entirely, rather than -" throwing cryptic errors at the user. None of them are particularly wise -" characters to have in paths, anyway, legal though they may be on Unix -" filesystems. +" Extra checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM +" need to be made, because the P_NDNAME property is assigned to them, which +" enforces a character blacklist in the option value. We check for the same +" set of blacklist characters here, and if the MYVIM path offends, we just +" skip the setting entirely, rather than throwing cryptic errors at the user. +" None of them are particularly wise characters to have in paths, anyway, +" legal though they may be on Unix filesystems. " set dictionary^=/usr/share/dict/words -if $MYVIM !=# '' && $MYVIM !~# '[*?[|;&<>\r\n]' +if $MYVIM !~# '[*?[|;&<>\r\n]' set dictionary^=$MYVIM/ref/dictionary.txt set thesaurus^=$MYVIM/ref/thesaurus.txt endif -- cgit v1.2.3 From 17471e9b834c956a02b1535f39426cc8f56a0e2a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:29:36 +1200 Subject: Rearrange vimrc autocmds --- vim/vimrc | 79 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 2998d9d6..64943525 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -170,49 +170,58 @@ function! s:FileTypeReload() abort doautocmd filetypedetect BufRead endif endfunction + +" The command accepts no arguments, and has no range. It just calls the +" function; that's all. It's also used by the F mapping defined later +" in this file. +" command! FileTypeReload \ call s:FileTypeReload() -" Create a 'vimrc' automatic command hook group, if it doesn't already exist, -" and clear away any automatic command hooks already defined within it if it -" does. This way, we don't end up collecting multiple copies of the hooks -" configured in the rest of this file if it's reloaded. I don't want to make -" the :augroup span the entire file, though. +" Create a 'vimrc' automatic command hook group, if it doesn't already exist; +" this group should only be used for command hooks related to this vimrc +" itself. " augroup vimrc + + " Clear away any automatic command hooks already defined within it if it + " does. This way, we don't end up collecting multiple copies of the hooks + " configured in the rest of this file if it's reloaded. + " autocmd! -augroup END -" Now we'll use that new :FileTypeReload command as part of an automatic -" command hook that runs whenever this vimrc is sourced. -" -" If there's stuff in any of your filetype plugins 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 we reload the stub ~/.vimrc or ~/_vimrc file when either it or -" this main file is saved, using :doautocmd abstraction. Note also that the -" SourceCmd event wasn't added until Vim 7.0.187, so we need to check it -" exists first. -" -if exists('##SourceCmd') - autocmd vimrc SourceCmd $MYVIMRC,$MYVIM/vimrc - \ source | FileTypeReload -endif + " Now we'll use that new :FileTypeReload command as part of an automatic + " command hook that runs whenever this vimrc is sourced. + " + " If there's stuff in any of your filetype plugins 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 we reload the stub ~/.vimrc or ~/_vimrc file when either it or + " this main file is saved, using :doautocmd abstraction. Note also that the + " SourceCmd event wasn't added until Vim 7.0.187, so we need to check it + " exists first. + " + if exists('##SourceCmd') + autocmd SourceCmd $MYVIMRC,$MYVIM/vimrc + \ source | FileTypeReload + endif -" If this file or the vimrc stub that calls it is written to by Vim, we'd like -" to 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. We can lean on the SourceCmd hook we just -" established to do this; in fact, we'll only establish this hook if we can do -" so, because otherwise filetype plugins won't reload, and options like -" 'shiftwidth' might be set incorrectly. -" -if exists('#vimrc#SourceCmd') - autocmd vimrc BufWritePost $MYVIMRC,$MYVIM/vimrc - \ doautocmd vimrc SourceCmd -endif + " If this file or the vimrc stub that calls it is written to by Vim, we'd like + " to 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. We can lean on the SourceCmd hook we just + " established to do this; in fact, we'll only establish this hook if we can do + " so, because otherwise filetype plugins won't reload, and options like + " 'shiftwidth' might be set incorrectly. + " + if exists('#vimrc#SourceCmd') + autocmd BufWritePost $MYVIMRC,$MYVIM/vimrc + \ doautocmd vimrc SourceCmd + endif + +augroup END " Keep the viminfo file in a cache subdirectory of the user runtime directory, " creating that subdirectory first if necessary. -- cgit v1.2.3 From 3392ff345e730c40a2575694242451b5e470ea51 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:29:53 +1200 Subject: Rearrange 'backupskip' changes logic --- vim/vimrc | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 64943525..8e77afa5 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -349,6 +349,14 @@ else set backupdir^=$MYVIM/cache/backup endif +" Vim doesn't seem to check patterns added to 'backupskip' for uniqueness, +" so adding them repeatedly if this file is reloaded results in duplicates, +" due to the absence of the P_NODUP flag for its definition in src/option.c. +" This is likely a bug in Vim. For the moment, to work around the problem, +" we reset the path back to its default first. +" +set backupskip& + " Files in certain directories on Unix-compatible filesystems should not be " backed up for reasons of privacy, or an intentional ephemerality, or both. " This is particularly important if editing temporary files created by @@ -356,22 +364,12 @@ endif " value of 'backupskip' in order to prevent the creation of such undesired " backup files. " +" * /dev/shm: RAM disk, default path for password-store's temporary files +" * /usr/tmp: Hard-coded path for sudoedit(8) [1/2] +" * /var/tmp: Hard-coded path for sudoedit(8) [2/2] +" if has('unix') - - " Vim doesn't seem to check patterns added to 'backupskip' for uniqueness, - " so adding them repeatedly if this file is reloaded results in duplicates, - " due to the absence of the P_NODUP flag for its definition in src/option.c. - " This is likely a bug in Vim. For the moment, to work around the problem, - " we reset the path back to its default first. - " - set backupskip& - - " * /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] - " set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/* - endif " Relax traditional vi's harsh standards over what regions of the buffer can -- cgit v1.2.3 From a5eda5c5256bd4883d973d33f78b054de61141d2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:30:08 +1200 Subject: Rename EnsureDir to Establish I just like this name better. --- vim/plugin/spellfile_local.vim | 2 +- vim/vimrc | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/vim/plugin/spellfile_local.vim b/vim/plugin/spellfile_local.vim index 9cb97624..0ded3fc1 100644 --- a/vim/plugin/spellfile_local.vim +++ b/vim/plugin/spellfile_local.vim @@ -3,7 +3,7 @@ if exists('loaded_spellfile_local') endif let loaded_spellfile_local = 1 -EnsureDir $MYVIM/cache/spell +Establish $MYVIM/cache/spell let spellfile = join([ \ substitute(v:lang, '_.*', '', ''), diff --git a/vim/vimrc b/vim/vimrc index 8e77afa5..9a2a425f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -135,25 +135,25 @@ endif " final one, since every directory we want to create in this file should be " locked down in this way. " -function! s:EnsureDir(path) abort +function! s:Establish(path) abort let path = expand(a:path) return isdirectory(path) \ || exists('*mkdir') && mkdir(path, 'p', 0700) endfunction -" Now we define the :EnsureDir command for user-level access to the -" s:EnsureDir() function. We set the tab completion to provide directory +" Now we define the :Establish command for user-level access to the +" s:Establish() function. We set the tab completion to provide directory " names as candidates, and specify that there must be only one argument, which " we'll provide as a quoted parameter to the function. " -command! -complete=dir -nargs=1 EnsureDir - \ call s:EnsureDir() +command! -complete=dir -nargs=1 Establish + \ call s:Establish() " Now that we have a clean means to create directories if they don't already " exist, let's apply it for the first time, in making sure that the MYVIM " directory exists, if it's been set. " -EnsureDir $MYVIM +Establish $MYVIM " 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 @@ -238,7 +238,7 @@ augroup END " a nicer way to set it with a 'viminfofile' option, but there's no particular " reason to use it until it's in a few more stable versions. " -EnsureDir $MYVIM/cache +Establish $MYVIM/cache set viminfo+=n$MYVIM/cache/viminfo " Speaking of recorded data in viminfo files, the command and search history @@ -342,7 +342,7 @@ set backup " It's all so awkward. Surely options named something like 'backupfullpath', " 'swapfilefullpath', and 'undofullpath' would have been clearer. " -EnsureDir $MYVIM/cache/backup +Establish $MYVIM/cache/backup if has('patch-8.1.251') set backupdir^=$MYVIM/cache/backup// else @@ -428,7 +428,7 @@ set confirm " its name, in order to avoid filename collisions. Create that path if " needed, too. " -EnsureDir $MYVIM/cache/swap +Establish $MYVIM/cache/swap set directory^=$MYVIM/cache/swap// " If Vim receives an Escape key code in insert mode, it shouldn't wait to see @@ -749,7 +749,7 @@ if has('persistent_undo') " Vim to use the full path of the original file in its undo file cache's " name. " - EnsureDir $MYVIM/cache/undo + Establish $MYVIM/cache/undo set undodir^=$MYVIM/cache/undo// " Turn the persistent undo features on, regardless of whether we have @@ -1321,7 +1321,7 @@ nnoremap G \ :cd %:hpwd "" Leader,P creates the path to the current file if it doesn't exist nnoremap P - \ :EnsureDir %:h + \ :Establish %:h " This group contains mappings that show information about Vim's internals: " marks, registers, variables, and the like. -- cgit v1.2.3 From 76411bb57bac085c1ab99434af674f14914cdeac Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:33:23 +1200 Subject: Improve and correct comments on $MYVIM --- vim/vimrc | 126 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 9a2a425f..6765892b 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -53,7 +53,9 @@ scriptencoding utf-8 " 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. +" location for Vim-related files. Having it available as an environment +" variable makes assignments with :set more convenient, without requiring +" :execute wrappers. " " I think the absence of a variable like this is a glaring omission from Vim. " We have VIM, VIMRUNTIME, and MYVIMRC, so why is there not an environment @@ -78,7 +80,10 @@ scriptencoding utf-8 " [, ]* Any number of commas and spaces " " We don't have to deal with escaped backslashes; read the source of -" copy_option_part() in vim/src/misc2.c to see why. +" copy_option_part() in vim/src/misc2.c to see why. As an edge case, if +" &runtimepath is blank, $MYVIM will be set to the empty string, which will +" throw an error in the next block, due to the way that split() works by +" default. " " Vim, I love you, but you are so weird. " @@ -89,7 +94,9 @@ endif " We need to check the MYVIM environment variable's value to ensure it's not " going to cause problems for the rest of this file. " -" Firstly, if the path specified in the MYVIM environment variable contains +" Firstly, it can't be empty. +" +" Secondly, if the path specified in the MYVIM environment variable contains " a comma, its use in comma-separated option values will confuse Vim into " thinking more than one directory is being specified, per normal :set " semantics. It's possible to work around this with some careful escaping, @@ -97,13 +104,14 @@ endif " environment variable for that particular context, but it's not really worth " the extra complexity for such a niche situation. " -" Secondly, some versions of Vim prior to v7.2.0 exhibit bizarre behaviour -" with escaping with the backslash character on the command line, so on these -" older versions of Vim, forbid that character. I haven't found the exact -" patch level that this was fixed yet, nor the true reason for the bug. +" Thirdly, some versions of Vim prior to v7.2.0 exhibit bizarre behaviour with +" escaping with the backslash character on the command line, so on these older +" versions of Vim, forbid that character. I haven't found the exact patch +" level that this was fixed yet, nor the true reason for the bug. " -" If either of these conditions are meant, throw an explanatory error and stop -" reading this file. +" If any of those conditions are meant, throw an explanatory error and stop +" reading this file. Most of the file doesn't depend on $MYVIM, but there's +" no point catering to these edge cases. " if $MYVIM ==# '' echoerr 'Blank user runtime path' @@ -116,44 +124,13 @@ elseif $MYVIM =~# '\\' && v:version < 702 finish endif -" We're going to be creating a few directories, and the code to do so in -" a compatible way is surprisingly verbose, because we need to check the -" mkdir() function is actually available, and also whether the directory -" concerned already exists, even if we specify the special 'p' value for its -" optional {path} argument. -" -" This is because the meaning of mkdir(..., 'p') is not the same as `mkdir -p` -" in shell script, or at least, it isn't in versions of Vim before v8.0.1708. -" Even with the magic 'p' sauce, these versions throw errors if the directory -" already exists, despite what someone familiar with `mkdir -p`'s behaviour in -" shell script might expect. -" -" So, let's wrap all that nonsense in a script-local function, and then -" abstract that away too with a user command, to keep the semantics of the -" :set operations nice and clean. We'll make all the directories we create -" have restrictive permissions, too, with a {prot} argument of 0700 for the -" final one, since every directory we want to create in this file should be -" locked down in this way. -" -function! s:Establish(path) abort - let path = expand(a:path) - return isdirectory(path) - \ || exists('*mkdir') && mkdir(path, 'p', 0700) -endfunction - -" Now we define the :Establish command for user-level access to the -" s:Establish() function. We set the tab completion to provide directory -" names as candidates, and specify that there must be only one argument, which -" we'll provide as a quoted parameter to the function. -" -command! -complete=dir -nargs=1 Establish - \ call s:Establish() - -" Now that we have a clean means to create directories if they don't already -" exist, let's apply it for the first time, in making sure that the MYVIM -" directory exists, if it's been set. +" Use all of the filetype detection, plugin, and indent support available. +" I define my own filetype.vim and scripts.vim files for filetype detection, +" in a similar but not identical form to the stock runtime files. I also +" define my own ftplugin and indent files for some types, sometimes replacing +" and sometimes supplementing the runtime files. " -Establish $MYVIM +filetype plugin indent on " 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 @@ -193,15 +170,13 @@ augroup vimrc " Now we'll use that new :FileTypeReload command as part of an automatic " command hook that runs whenever this vimrc is sourced. " - " If there's stuff in any of your filetype plugins that doesn't cope well with - " being reloaded, and just assumes a single BufRead event, it might be + " If there's stuff in any of the filetype plugins 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 we reload the stub ~/.vimrc or ~/_vimrc file when either it or - " this main file is saved, using :doautocmd abstraction. Note also that the - " SourceCmd event wasn't added until Vim 7.0.187, so we need to check it - " exists first. + " Note that the SourceCmd event wasn't added until Vim 7.0.187, so we need + " to check it exists first. " if exists('##SourceCmd') autocmd SourceCmd $MYVIMRC,$MYVIM/vimrc @@ -223,6 +198,45 @@ augroup vimrc augroup END +" We're going to be creating a few directories now, and the code to do so in +" a compatible way is surprisingly verbose, because as well as expanding what +" we were provided as an argument, we need to check the mkdir() function is +" actually available. +" +" We also need to check whether the directory concerned already exists, even +" if we specify the special 'p' value for its optional {path} argument. This +" is because the meaning of mkdir(..., 'p') is not the same as `mkdir -p` in +" shell script, or at least, it isn't in versions of Vim before v8.0.1708. +" Even with the magic 'p' sauce, these versions throw errors if the directory +" already exists, despite what someone familiar with `mkdir -p`'s behaviour in +" shell script might expect. +" +" So, let's wrap all that nonsense in a script-local function, and then +" abstract that away too with a user command, to keep the semantics of the +" :set operations nice and clean. We'll make all the directories we create +" have restrictive permissions, too, with a {prot} argument of 0700 for the +" final one, since every directory we want to create in this file should be +" locked down in this way. +" +function! s:Establish(path) abort + let path = expand(a:path) + return isdirectory(path) + \ || exists('*mkdir') && mkdir(path, 'p', 0700) +endfunction + +" Now we define the :Establish command for user-level access to the +" s:Establish() function. We set the tab completion to provide directory +" names as candidates, and specify that there must be only one argument, which +" we'll provide as a quoted parameter to the function. +" +command! -complete=dir -nargs=1 Establish + \ call s:Establish() + +" Now that we have a clean means to create directories if they don't already +" exist, let's apply it for the first time to the user runtime directory. +" +Establish $MYVIM + " Keep the viminfo file in a cache subdirectory of the user runtime directory, " creating that subdirectory first if necessary. " @@ -890,14 +904,6 @@ if $MYVIM !~# '[*?[|;&<>\r\n]' set thesaurus^=$MYVIM/ref/thesaurus.txt endif -" Use all of the filetype detection, plugin, and indent support available. -" I define my own filetype.vim and scripts.vim files for filetype detection, -" in a similar but not identical form to the stock runtime files. I also -" define my own ftplugin and indent files for some types, sometimes replacing -" and sometimes supplementing the runtime files. -" -filetype plugin indent on - " Enable syntax highlighting, but only if it's not already on, to save " reloading the syntax files unnecessarily. " -- cgit v1.2.3 From e9b9b299664c90a884d9d296d0452e15e40e520a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:43:59 +1200 Subject: More rearranging --- vim/vimrc | 276 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index 6765892b..8aa53791 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -51,7 +51,7 @@ scriptencoding utf-8 " 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 +" variable as the root of our 'nackupdir', 'directory', 'undodir', and " 'viminfofile' caches, and anywhere else we need a sensible writeable " location for Vim-related files. Having it available as an environment " variable makes assignments with :set more convenient, without requiring @@ -265,66 +265,6 @@ set viminfo+=n$MYVIM/cache/viminfo " set history=10000 -" Next, we'll modernise a little in adjusting some options with old -" 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, -" 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 - -" 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. -" -if v:version > 730 || v:version == 730 && has('patch693') - set softtabstop=-1 -else - let &softtabstop = &shiftwidth -endif - " 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. We're not done here yet, though; it @@ -386,6 +326,143 @@ if has('unix') set backupskip^=/dev/shm/*,/usr/tmp/*,/var/tmp/* endif +" Keep swap files for file buffers in a dedicated directory, rather than the +" default of writing them to the same directory as the buffer file. Add two +" trailing slashes to the path to prompt Vim to use the full escaped path in +" its name, in order to avoid filename collisions. Create that path if +" needed, too. +" +Establish $MYVIM/cache/swap +set directory^=$MYVIM/cache/swap// + +" Keep tracked undo history for files permanently, in a dedicated cache +" directory, so that the u/:undo and CTRL-R/:redo commands will work between +" Vim invocations. +" +" Support for persistent undo file caches was not added until v7.2.438, so we +" need to check for the feature's presence before we enable it. +" +if has('persistent_undo') + + " This has the same structure as 'backupdir' and 'directory'; if we have + " a user runtime directory, create a sub-subdirectory within it dedicated to + " the undo files cache. Note also the trailing double-slash as a signal to + " Vim to use the full path of the original file in its undo file cache's + " name. + " + Establish $MYVIM/cache/undo + set undodir^=$MYVIM/cache/undo// + + " Turn the persistent undo features on, regardless of whether we have + " a cache directory for them as a result of the logic above. The files + " might sprinkle around the filesystem annoyingly, but that's still better + " than losing the history completely. + " + set undofile + +endif + +" For word completion in insert mode with CTRL-X CTRL-K, or if 'complete' +" includes the 'k' flag, the 'dictionary' option specifies the path to the +" system word list. This makes the dictionary completion work consistently, +" even if 'spell' isn't set at the time to coax it into using 'spellfile'. +" +" It's not an error if the system directory file added first doesn't exist; +" it's just a common location that often yields a workable word list, and does +" so on all of my main machines. +" +" At some point, I may end up having to set this option along with 'spellfile' +" a bit more intelligently to ensure that spell checking and dictionary +" function consistently, and with reference to the same resources. For the +" moment, I've just added another entry referring to a directory in the user +" runtime directory, but I don't have anything distinct to put there yet. +" +" In much the same way, we add an expected path to a thesaurus, for completion +" with CTRL-X CTRL-T in insert mode, or with 't' added to 'completeopt'. The +" thesaurus data isn't installed as part of the default `install-vim` target +" in tejr's dotfiles, but it can be retrieved and installed with +" `install-vim-thesaurus`. +" +" I got the thesaurus itself from the link in the :help for 'thesaurus' in +" v8.1.1487. It's from WordNet and MyThes-1. I maintain a mirror on my own +" website that the Makefile recipe attempts to retrieve. I had to remove the +" first two metadata lines from thesaurus.txt, as Vim appeared to interpret +" them as part of the body data. +" +" Extra checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM +" need to be made, because the P_NDNAME property is assigned to them, which +" enforces a character blacklist in the option value. We check for the same +" set of blacklist characters here, and if the MYVIM path offends, we just +" skip the setting entirely, rather than throwing cryptic errors at the user. +" None of them are particularly wise characters to have in paths, anyway, +" legal though they may be on Unix filesystems. +" +set dictionary^=/usr/share/dict/words +if $MYVIM !~# '[*?[|;&<>\r\n]' + set dictionary^=$MYVIM/ref/dictionary.txt + set thesaurus^=$MYVIM/ref/thesaurus.txt +endif + +" Next, we'll modernise a little in adjusting some options with old +" 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, +" 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 + +" 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. +" +if v:version > 730 || v:version == 730 && has('patch693') + set softtabstop=-1 +else + let &softtabstop = &shiftwidth +endif + " Relax traditional vi's harsh standards over what regions of the buffer can " be removed with backspace in insert mode. While this admittedly allows bad " habits to continue, since insert mode by definition is not really intended @@ -436,15 +513,6 @@ endif " set confirm -" 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. Create that path if -" needed, too. -" -Establish $MYVIM/cache/swap -set directory^=$MYVIM/cache/swap// - " 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. @@ -748,33 +816,6 @@ if exists('+ttymouse') set ttymouse= endif -" Keep tracked undo history for files permanently, in a dedicated cache -" directory, so that the u/:undo and CTRL-R/:redo commands will work between -" Vim invocations. -" -" Support for persistent undo file caches was not added until v7.2.438, so we -" need to check for the feature's presence before we enable it. -" -if has('persistent_undo') - - " This has the same structure as 'backupdir' and 'directory'; if we have - " a user runtime directory, create a sub-subdirectory within it dedicated to - " the undo files cache. Note also the trailing double-slash as a signal to - " Vim to use the full path of the original file in its undo file cache's - " name. - " - Establish $MYVIM/cache/undo - set undodir^=$MYVIM/cache/undo// - - " Turn the persistent undo features on, regardless of whether we have - " a cache directory for them as a result of the logic above. The files - " might sprinkle around the filesystem annoyingly, but that's still better - " than losing the history completely. - " - set undofile - -endif - " While using virtual block mode, allow me to navigate to any column of the " buffer window; don't confine the boundaries of the block to the coordinates " of characters that actually exist in the buffer text. While working with @@ -863,47 +904,6 @@ if exists('+wildignorecase') set wildignorecase endif -" For word completion in insert mode with CTRL-X CTRL-K, or if 'complete' -" includes the 'k' flag, the 'dictionary' option specifies the path to the -" system word list. This makes the dictionary completion work consistently, -" even if 'spell' isn't set at the time to coax it into using 'spellfile'. -" -" It's not an error if the system directory file added first doesn't exist; -" it's just a common location that often yields a workable word list, and does -" so on all of my main machines. -" -" At some point, I may end up having to set this option along with 'spellfile' -" a bit more intelligently to ensure that spell checking and dictionary -" function consistently, and with reference to the same resources. For the -" moment, I've just added another entry referring to a directory in the user -" runtime directory, but I don't have anything distinct to put there yet. -" -" In much the same way, we add an expected path to a thesaurus, for completion -" with CTRL-X CTRL-T in insert mode, or with 't' added to 'completeopt'. The -" thesaurus data isn't installed as part of the default `install-vim` target -" in tejr's dotfiles, but it can be retrieved and installed with -" `install-vim-thesaurus`. -" -" I got the thesaurus itself from the link in the :help for 'thesaurus' in -" v8.1.1487. It's from WordNet and MyThes-1. I maintain a mirror on my own -" website that the Makefile recipe attempts to retrieve. I had to remove the -" first two metadata lines from thesaurus.txt, as Vim appeared to interpret -" them as part of the body data. -" -" Extra checks for appending the 'dictionary' and 'thesaurus' paths in MYVIM -" need to be made, because the P_NDNAME property is assigned to them, which -" enforces a character blacklist in the option value. We check for the same -" set of blacklist characters here, and if the MYVIM path offends, we just -" skip the setting entirely, rather than throwing cryptic errors at the user. -" None of them are particularly wise characters to have in paths, anyway, -" legal though they may be on Unix filesystems. -" -set dictionary^=/usr/share/dict/words -if $MYVIM !~# '[*?[|;&<>\r\n]' - set dictionary^=$MYVIM/ref/dictionary.txt - set thesaurus^=$MYVIM/ref/thesaurus.txt -endif - " Enable syntax highlighting, but only if it's not already on, to save " reloading the syntax files unnecessarily. " -- cgit v1.2.3 From 4eca3f935fb89df9fa9aa3f18dd0ee800656ae07 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 11 Jun 2019 10:45:19 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 9fb49ae9..909b9eae 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v5.36.0 -Mon Jun 10 06:54:50 UTC 2019 +tejr dotfiles v5.37.0 +Mon Jun 10 22:45:19 UTC 2019 -- cgit v1.2.3