From b86c058803dc2705cf912dc63e216c7f7a41b0c8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 19:29:04 +1300 Subject: Refactor toggle_option_flag.vim Got carried away and rewrote a lot of this all in one hit. * Show single-line error messages with an s:Error() function * Flag early errors on nonexistent options * Test for the flag both before and after trying to toggle it to use as the basis for error reporting and return value, in a new s:Has() function --- vim/plugin/toggle_option_flag.vim | 81 ++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/vim/plugin/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim index 1d4b11ce..dcc26cce 100644 --- a/vim/plugin/toggle_option_flag.vim +++ b/vim/plugin/toggle_option_flag.vim @@ -12,19 +12,16 @@ if exists('g:loaded_toggle_option_flag') endif let g:loaded_toggle_option_flag = 1 -" Internal function to do the toggling -function! s:Toggle(option, flag, local) - - " Check for weird options, we don't want to :execute anything funny - if a:option =~# '\m\L' - echoerr 'Illegal option name' - return - endif +" Show an error-highlighted message and beep, but without a real :echoerr +function! s:Error(message) + execute 'normal! \' + echohl ErrorMsg + echomsg a:message + echohl None +endfunction - " Choose which set command to use - let l:set = a:local - \ ? 'setlocal' - \ : 'set' +" Test whether an option currently has a flag as part of its value +function! s:Has(option, flag) " Horrible :execute to get the option's current setting into a variable " (I couldn't get {curly braces} indirection to work) @@ -33,29 +30,67 @@ function! s:Toggle(option, flag, local) " If the flag we're toggling is longer than one character, this must by " necessity be a delimited option. I think all of those in VimL are - " comma-separated. Extend the flag and current setting so that they'll still - " match at the start and end. Otherwise, use them as-is. + " comma-separated. Extend the flag and value so that they'll still match at + " the start and end. Otherwise, use them as-is. if strlen(a:flag) > 1 let l:search_flag = ',' . a:flag . ',' - let l:search_current = ',' . l:current . ',' + let l:search_value = ',' . l:current . ',' else let l:search_flag = a:flag - let l:search_current = l:current + let l:search_value = l:current endif + " Return whether + return stridx(l:search_value, l:search_flag) > -1 + +endfunction + +" Internal function to do the toggling +function! s:Toggle(option, flag, local) + + " Check for spurious option strings, we don't want to :execute anything funny + if a:option =~# '\m\L' + call s:Error('Illegal option name') + return 0 + endif + + " Check the option actually exists + if !exists('&' . a:option) + call s:Error('No such option: ' . a:option) + return 0 + endif + + " Choose which set command to use + let l:set = a:local + \ ? 'setlocal' + \ : 'set' + + " Find whether the flag is set before the change + let l:before = s:Has(a:option, a:flag) + " Assign -= or += as the operation to run based on whether the flag already " appears in the option value or not - let l:operation = stridx(l:search_current, l:search_flag) > -1 + let l:operation = l:before \ ? '-=' \ : '+=' - " Build the command strings to set and then show the value - let l:cmd_set = l:set . ' ' . a:option . l:operation . escape(a:flag, '\ ') - let l:cmd_show = l:set . ' ' . a:option . '?' + " Try to set the option; suppress errors, we'll check our work + silent! execute l:set + \ . ' ' + \ . a:option . l:operation . escape(a:flag, '\ ') + + " Find whether the flag is set after the change + let l:after = s:Has(a:option, a:flag) + + " If we made a difference, report the new value; if we didn't, admit it + if l:before != l:after + execute l:set . ' ' . a:option . '?' + else + call s:Error('Unable to toggle '.a:option.' flag '.a:flag) + endif - " Run the set and show command strings - execute l:cmd_set - execute l:cmd_show + " Return value is whether we made a change + return l:before != l:after endfunction -- cgit v1.2.3 From 8363000da205b1317bd399dd91ab9810a7532b98 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 19:32:07 +1300 Subject: Simplify 'formatoptions' config We'll let toggle_option_flags.vim raise the errors, and we won't bother with the version number testing. --- vim/config/format.vim | 73 +++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 55 deletions(-) diff --git a/vim/config/format.vim b/vim/config/format.vim index 1f24ee56..e266f42a 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -1,65 +1,28 @@ -" All of this variable logic requires 'eval', and I can't just short-circuit -" it due to a quirk in the way vim-tiny evaluates these expressions -if has('eval') +" Try to set the 'j' flag for 'formatoptions', to automatically delete comment +" leaders when joining lines +silent! set formatoptions+=j - " Figure out if we have the 'j' flag for 'formatoptions', to automatically - " delete comment leaders when joining lines; keep it in a script variable - let s:formatoptions_has_j = v:version > 703 - \ || v:version == 703 && has('patch541') +" Use toggle_option_flag.vim plugin to bind quick toggle actions for some +" 'formatoptions' flags +if has('user_commands') - " If we do have 'j', default to setting it - if s:formatoptions_has_j - set formatoptions+=j - endif - - " - " Use toggle_option_flag.vim plugin to bind quick toggle actions for some - " 'formatoptions' flags; both of the above, plus: - " - " c - Automatically wrap comments at 'textwidth' (which I allow the filetypes - " to set for me) - " t - Automatically wrap text at 'textwidth' (as above) - " - " We need user-defined commands to do this. - " - if !has('user_commands') - finish - endif + " a: Reformat paragraphs to 'textwidth' on all insert or delete operations + nnoremap + \ a + \ :ToggleOptionFlagLocal formatoptions a - " 'c' and 't' have both been around since at least 6.1 + " c: Reformat comments to 'textwidth' nnoremap \ c \ :ToggleOptionFlagLocal formatoptions c + + " j: Delete comment leaders when joining lines + nnoremap + \ j + \ :ToggleOptionFlagLocal formatoptions j + + " t: Reformat non-comment text to 'textwidth' nnoremap \ t \ :ToggleOptionFlagLocal formatoptions t - - " Figure out if we have the 'a' flag for 'formatoptions', to reapply - " 'textwidth' wrapping to the current paragraph on every insertion or - " deletion; keep in a script variable - let s:formatoptions_has_a = v:version > 610 - \ || v:version == 610 && has('patch142') - - " 'a' needs testing - if s:formatoptions_has_a - nnoremap - \ a - \ :ToggleOptionFlagLocal formatoptions a - else - nnoremap - \ a - \ :echoerr 'No formatoptions a-flag' - endif - - " 'j' needs testing - if s:formatoptions_has_j - nnoremap - \ j - \ :ToggleOptionFlagLocal formatoptions j - else - nnoremap - \ j - \ :echoerr 'No formatoptions j-flag' - endif - endif -- cgit v1.2.3 From b773d3324f108c292e00fc51cc07df90d10b7007 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 19:51:21 +1300 Subject: Use consistent comment layout for Vim plugins --- vim/plugin/command_typos.vim | 7 ++++--- vim/plugin/copy_linebreak.vim | 6 +++--- vim/plugin/fixed_join.vim | 4 ++-- vim/plugin/strip_trailing_whitespace.vim | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim index adf2d0eb..60245a30 100644 --- a/vim/plugin/command_typos.vim +++ b/vim/plugin/command_typos.vim @@ -1,7 +1,8 @@ " -" Tolerate typos like :Wq, :Q, or :Qa and do what I mean, including any -" arguments or modifiers; I fat-finger these commands a lot because I type -" them so rapidly, and they don't correspond to any other commands I use +" command_typos.vim: Tolerate typos like :Wq, :Q, or :Qa and do what I mean, +" including any arguments or modifiers; I fat-finger these commands a lot +" because I type them so rapidly, and they don't correspond to any other +" commands I use " " Author: Tom Ryder " License: Same as Vim itself diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index faeb1617..40f03393 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -1,7 +1,7 @@ " -" Bind a user-defined key sequence to turn off linebreak and toggle the -" showbreak characters and breakindent mode on and off, for convenience of -" copying multiple lines from terminal emulators. +" copy_linebreak.vim: Bind a user-defined key sequence to turn off linebreak +" and toggle the showbreak characters and breakindent mode on and off, for +" convenience of copying multiple lines from terminal emulators. " " Author: Tom Ryder " License: Same as Vim itself diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 18f563f3..4c7c7ed4 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -1,6 +1,6 @@ " -" User-defined key mapping to keep cursor in place when joining lines in -" normal mode +" fixed_join.vim: User-defined key mapping to keep cursor in place when +" joining lines in normal mode. " " Author: Tom Ryder " License: Same as Vim itself diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index d5f5624a..9fb2e65b 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,5 +1,6 @@ " -" User-defined key mapping to strip trailing whitespace in the whole document +" strip_trailing_whitespace.vim: User-defined key mapping to strip trailing +" whitespace in the whole document. " " Author: Tom Ryder " License: Same as Vim itself -- cgit v1.2.3 From b074e1d55a5acaeaaf6402a87e0cb45de16a8911 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 23:31:50 +1300 Subject: Break bash/bashrc.d/completion.bash inline lists Break the sometimes long list of target keywords after the `complete` builtin and its options into newline-separated lists. This should make reading these lists a little easier, and also confuses Vim's syntax highlighting somewhat less. --- bash/bashrc.d/completion.bash | 85 +++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash index 51de24b8..eaf6c5f5 100644 --- a/bash/bashrc.d/completion.bash +++ b/bash/bashrc.d/completion.bash @@ -4,53 +4,100 @@ # If COMP_WORDBREAKS has a value, strip all colons from it; this allows # completing filenames correctly, since a colon is not a shell metacharacter: # (E13) -[[ -n $COMP_WORDBREAKS ]] && COMP_WORDBREAKS=${COMP_WORDBREAKS//:} +if [[ -n $COMP_WORDBREAKS ]] ; then + COMP_WORDBREAKS=${COMP_WORDBREAKS//:} +fi # If ~/.hosts exists, use that as the host completion file rather than # /etc/hosts, so I can populate the list myself -[[ -f $HOME/.hosts ]] && HOSTFILE=$HOME/.hosts +if [[ -f $HOME/.hosts ]] ; then + HOSTFILE=$HOME/.hosts +fi # Aliases -complete -A alias unalias +complete -A alias \ + unalias # Bash builtins -complete -A builtin builtin -complete -A enabled disable -complete -A disabled enable +complete -A builtin \ + builtin +complete -A enabled \ + disable +complete -A disabled \ + enable # Bash options -complete -A setopt set +complete -A setopt \ + set # Commands -complete -A command alias command complete compopt coproc exec if hash time \ - type until while +complete -A command \ + alias \ + command \ + complete \ + compopt \ + coproc \ + exec \ + if \ + hash \ + time \ + type \ + until \ + while # Directories -complete -A directory cd pushd mkdir rmdir +complete -A directory \ + cd \ + pushd \ + mkdir \ + rmdir # Functions and variables -complete -A function function -complete -A function -A variable declare export local readonly typeset unset -complete -A variable for getopts let read select +complete -A function \ + function +complete -A function -A variable \ + declare \ + export \ + local \ + readonly \ + typeset \ + unset +complete -A variable \ + for \ + getopts \ + let \ + read \ + select # Help topics complete -A helptopic help # Jobspecs -complete -P '%' -A job disown fg jobs -complete -P '%' -A stopped bg +complete -P '%' -A job \ + disown \ + fg \ + jobs +complete -P '%' -A stopped \ + bg # Readline bindings -complete -A binding bind +complete -A binding \ + bind # Shell options -complete -A shopt shopt +complete -A shopt \ + shopt # Signal names -complete -A signal trap +complete -A signal \ + trap # The `mapfile` builtin in Bash >= 4.0 -((BASH_VERSINFO[0] >= 4)) && complete -A arrayvar mapfile readarray +if ((BASH_VERSINFO[0] >= 4)) ; then + complete -A arrayvar \ + mapfile \ + readarray +fi # If we have dynamic completion loading (Bash>=4.0), use it if ((BASH_VERSINFO[0] >= 4)) ; then -- cgit v1.2.3 From 05a5347ee0bcb634fe706c3f522769a35fe245fb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 6 Nov 2017 23:34:36 +1300 Subject: Add "do", "then" keywords to Bash completion The Bash keywords "do" and "then" will be followed by another command. Adding them to this list means that pressing tab after "if foo ; then b" will complete for all command names beginning with "b". I was actually a little surprised that this worked, but there isn't really any reason to be; they're shell words just like everything else, not metasyntactic characters or anything like that. --- bash/bashrc.d/completion.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash index eaf6c5f5..eb01dda2 100644 --- a/bash/bashrc.d/completion.bash +++ b/bash/bashrc.d/completion.bash @@ -37,9 +37,11 @@ complete -A command \ complete \ compopt \ coproc \ + do \ exec \ if \ hash \ + then \ time \ type \ until \ -- cgit v1.2.3 From c0e1371d3bdb9749d39c63e86a3678eb434d4ccb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 09:30:05 +1300 Subject: Add :StripTrailingWhitespace command This is optional; if the user's Vim doesn't have the 'user_commands' feature, the command will just quietly not be created. --- vim/doc/strip_trailing_whitespace.txt | 3 +++ vim/plugin/strip_trailing_whitespace.vim | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/vim/doc/strip_trailing_whitespace.txt b/vim/doc/strip_trailing_whitespace.txt index 670877c9..d50fbfb7 100644 --- a/vim/doc/strip_trailing_whitespace.txt +++ b/vim/doc/strip_trailing_whitespace.txt @@ -7,6 +7,9 @@ This plugin is the author's approach to stripping trailing whitespace from an entire buffer, including empty lines at the end, without making command noise and without moving the cursor from its current position. +If also provides a :StripTrailingWhitespace command if you have +user_commands, +but this is not required. + This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun off into a separate distribution as it solidifies and this documentation improves. diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 9fb2e65b..1264a11f 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,6 +1,6 @@ " -" strip_trailing_whitespace.vim: User-defined key mapping to strip trailing -" whitespace in the whole document. +" strip_trailing_whitespace.vim: User-defined key mapping and optional command +" to strip trailing whitespace in the whole document. " " Author: Tom Ryder " License: Same as Vim itself @@ -67,3 +67,10 @@ endfunction noremap \ StripTrailingWhitespace \ :call StripTrailingWhitespace() + +" Define a user command too, if we can +if has('user_commands') + command -nargs=0 + \ StripTrailingWhiteSpace + \ call StripTrailingWhitespace() +endif -- cgit v1.2.3 From d2669e7190e3db3123589bfcd3ba15a2e4c5243b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 09:34:21 +1300 Subject: Add :FixedJoin command This is optiona; if the user's Vim doesn't have the 'user_commands' feature, the command will just quietly not be created. --- vim/doc/fixed_join.txt | 5 ++++- vim/plugin/fixed_join.vim | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vim/doc/fixed_join.txt b/vim/doc/fixed_join.txt index 0ee957d0..df0df251 100644 --- a/vim/doc/fixed_join.txt +++ b/vim/doc/fixed_join.txt @@ -1,4 +1,4 @@ -*fixed_join.txt* Mapping to join lines in normal mode without moving cursor +*fixed_join.txt* Join lines in normal mode without moving cursor Author: Tom Ryder License: Same terms as Vim itself (see |license|) @@ -6,6 +6,9 @@ License: Same terms as Vim itself (see |license|) This plugin provides a mapping target FixedJoin to create a binding for a user to join lines in normal mode without the cursor jumping around. +If also provides a :FixedJoin command if you have +user_commands, but this is +not required. + This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun off into a separate distribution as it solidifies and this documentation improves. diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 4c7c7ed4..2c9e1d92 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -1,6 +1,6 @@ " -" fixed_join.vim: User-defined key mapping to keep cursor in place when -" joining lines in normal mode. +" fixed_join.vim: User-defined key mapping and optional command to keep cursor +" in place when joining lines in normal mode. " " Author: Tom Ryder " License: Same as Vim itself @@ -31,3 +31,10 @@ endfunction noremap \ FixedJoin \ :call FixedJoin() + +" Create a command as well in case it's useful +if has('user_commands') + command -nargs=0 + \ FixedJoin + \ call FixedJoin() +endif -- cgit v1.2.3 From 44bd9a85728ec1eb6b4049b31e98ccdad9a8b02b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 10:07:03 +1300 Subject: Give copy_linebreak.vim enable/disable funcs, maps Add s:CopylinebreakDisable() and s:CopylinebreakEnable functions, and mapping targets for each of them, just to be thorough. --- vim/doc/copy_linebreak.txt | 14 +++++++---- vim/plugin/copy_linebreak.vim | 56 ++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/vim/doc/copy_linebreak.txt b/vim/doc/copy_linebreak.txt index c8463386..285d92ea 100644 --- a/vim/doc/copy_linebreak.txt +++ b/vim/doc/copy_linebreak.txt @@ -3,10 +3,16 @@ Author: Tom Ryder License: Same terms as Vim itself (see |license|) -This plugin provides a mapping target CopyLinebreak to create a binding -for a user to quickly toggle |'linebreak'|-related settings when |'wrap'| is -enabled, to switch between human-readable output and a format friendly for -copy-pasting with terminal emulators or screen/tmux. +This plugin provides mapping targets for a user to set, unset, or toggle +|'linebreak'|-related settings when |'wrap'| is enabled, to switch between +human-readable output and a format friendly for copy-pasting with terminal +emulators or screen/tmux. + +Mappings: + + CopyLinebreakEnable + CopyLinebreakDisable + CopyLinebreakToggle This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun off into a separate distribution as it solidifies and this documentation diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index 40f03393..cc0cc741 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -1,7 +1,6 @@ " -" copy_linebreak.vim: Bind a user-defined key sequence to turn off linebreak -" and toggle the showbreak characters and breakindent mode on and off, for -" convenience of copying multiple lines from terminal emulators. +" copy_linebreak.vim: Bind user-defined key sequences to toggle a group of +" options that make text wrapped with 'wrap' copy-paste friendly. " " Author: Tom Ryder " License: Same as Vim itself @@ -13,29 +12,42 @@ if exists('g:loaded_copy_linebreak') endif let g:loaded_copy_linebreak = 1 -" Define function -function! s:CopyLinebreak() +" Enable copy-friendly linebreak options +function! s:CopyLinebreakEnable() + setlocal nolinebreak linebreak? + setlocal showbreak= + if exists('&breakindent') + setlocal nobreakindent + endif +endfunction - " If linebreak is on, turn it off - if &l:linebreak - setlocal nolinebreak linebreak? - setlocal showbreak= - if exists('&breakindent') - setlocal nobreakindent - endif +" Disable copy-friendly linebreak options +function! s:CopyLinebreakDisable() + setlocal linebreak linebreak? + setlocal showbreak< + if exists('&breakindent') + setlocal breakindent< + endif +endfunction - " If it's off, turn it on +" Toggle copy-friendly linebreak options, using the current setting for the +" 'linebreak' option as the pivot +function! s:CopyLinebreakToggle() + if &linebreak + call CopyLinebreakEnable() else - setlocal linebreak linebreak? - setlocal showbreak< - if exists('&breakindent') - setlocal breakindent - endif + call CopyLinebreakDisable() endif - endfunction -" Provide mapping proxy to the function just defined +" Provide mappings to the function just defined +noremap + \ CopyLinebreakEnable + \ :call CopyLinebreakEnable() noremap - \ CopyLinebreak - \ :call CopyLinebreak() + \ CopyLinebreakDisable + \ :call CopyLinebreakDisable() +noremap + \ CopyLinebreakToggle + \ :call CopyLinebreakToggle() +endif -- cgit v1.2.3 From 3b64f6c61d3e2a04cf3f5f6f24b84635947344d5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 10:07:56 +1300 Subject: Add commands to copy_linebreak.vim Just to be thorough; if +user_commands are available, offer :CopyLinebreakEnable, :CopyLinebreakDisable, and :CopyLinebreakToggle commands. --- vim/doc/copy_linebreak.txt | 6 ++++++ vim/plugin/copy_linebreak.vim | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/vim/doc/copy_linebreak.txt b/vim/doc/copy_linebreak.txt index 285d92ea..15e4b1b0 100644 --- a/vim/doc/copy_linebreak.txt +++ b/vim/doc/copy_linebreak.txt @@ -14,6 +14,12 @@ Mappings: CopyLinebreakDisable CopyLinebreakToggle +Commands: + + :CopyLinebreakEnable + :CopyLinebreakDisable + :CopyLinebreakToggle + This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun off into a separate distribution as it solidifies and this documentation improves. diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index cc0cc741..2b5f7243 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -1,6 +1,7 @@ " " copy_linebreak.vim: Bind user-defined key sequences to toggle a group of -" options that make text wrapped with 'wrap' copy-paste friendly. +" options that make text wrapped with 'wrap' copy-paste friendly. Also creates +" user commands if it can. " " Author: Tom Ryder " License: Same as Vim itself @@ -50,4 +51,16 @@ noremap noremap \ CopyLinebreakToggle \ :call CopyLinebreakToggle() + +" Provide user commands if we can +if has('user_commands') + command -nargs=0 + \ CopyLinebreakEnable + \ call CopyLinebreakEnable + command -nargs=0 + \ CopyLinebreakDisable + \ call CopyLinebreakDisable + command -nargs=0 + \ CopyLinebreakToggle + \ call CopyLinebreakToggle endif -- cgit v1.2.3 From 64e0b1beef8ed360fba4f1cb405c371cc7213c00 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 10:09:02 +1300 Subject: Update b mapping to use new mapping name The name of this mapping was changed in commit 44bd9a8. --- vim/config/wrap.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim index a3fccbba..51e9ea89 100644 --- a/vim/config/wrap.vim +++ b/vim/config/wrap.vim @@ -31,6 +31,6 @@ if has('linebreak') endif " \b toggles copy-pasteable linebreak settings - nmap b CopyLinebreak + nmap b CopyLinebreakToggle endif -- cgit v1.2.3 From e85e3a2549fdbc2c3391ec92d4c179642d05bffb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 11:45:50 +1300 Subject: Add \p Vim binding to show filetype --- vim/config/file.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vim/config/file.vim b/vim/config/file.vim index 4bf1f86b..a0c99f6c 100644 --- a/vim/config/file.vim +++ b/vim/config/file.vim @@ -3,6 +3,11 @@ if has('autocmd') filetype plugin indent on endif +" Bind \p to show filetype +nnoremap + \ p + \ :set filetype? + " Use all ancestors of current directory for :find if has('file_in_path') set path=** -- cgit v1.2.3 From 09b83b6e25431fe9f3122916156f97fb0cfc2b5b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 11:43:02 +1300 Subject: Use b:undo variables correctly Setting or adding to b:undo_indent and b:undo_ftplugin variables, which I only learned about just now, allows me to avoid the _GLOBAL.vim hack and remove some files from both vim/indent/ and vim/ftplugin/. These variables aren't subjected to :execute automatically in anything older than Vim 7.0, but I don't think that's too much of a concern as the only real reason they're needed are for changing filetypes in the same buffer, which doesn't happen that often anyway. --- vim/ftplugin/mail.vim | 7 +++++++ vim/ftplugin/markdown.vim | 11 +++++++++++ vim/ftplugin/sh.vim | 7 +++++++ vim/ftplugin/text.vim | 11 +++++++++++ vim/indent/_GLOBAL.vim | 12 ------------ vim/indent/c.vim | 2 -- vim/indent/csv.vim | 10 +++++++--- vim/indent/html.vim | 2 -- vim/indent/perl.vim | 2 -- vim/indent/php.vim | 3 --- vim/indent/sh.vim | 2 -- vim/indent/tsv.vim | 10 +++++++--- vim/indent/vim.vim | 10 +++++++--- 13 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 vim/ftplugin/markdown.vim create mode 100644 vim/ftplugin/text.vim delete mode 100644 vim/indent/_GLOBAL.vim delete mode 100644 vim/indent/c.vim delete mode 100644 vim/indent/html.vim delete mode 100644 vim/indent/perl.vim delete mode 100644 vim/indent/sh.vim diff --git a/vim/ftplugin/mail.vim b/vim/ftplugin/mail.vim index 35432b96..236f25ff 100644 --- a/vim/ftplugin/mail.vim +++ b/vim/ftplugin/mail.vim @@ -1,2 +1,9 @@ " Use trailing whitespace to denote continued paragraph setlocal formatoptions+=w + +" Undo +if !exists('b:undo_ftplugin') + let b:undo_ftplugin = '' +endif +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal formatoptions<' diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim new file mode 100644 index 00000000..15333202 --- /dev/null +++ b/vim/ftplugin/markdown.vim @@ -0,0 +1,11 @@ +" Spellcheck documents by default +if has('syntax') + setlocal spell + + " Undo + if !exists('b:undo_ftplugin') + let b:undo_ftplugin = '' + endif + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal spell<' +endif diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 8990f0fa..85251aa1 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -48,3 +48,10 @@ endif nnoremap \ l \ :execute b:lint + +" Undo +if !exists('b:undo_ftplugin') + let b:undo_ftplugin = '' +endif +let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal keywordprg<' diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim new file mode 100644 index 00000000..15333202 --- /dev/null +++ b/vim/ftplugin/text.vim @@ -0,0 +1,11 @@ +" Spellcheck documents by default +if has('syntax') + setlocal spell + + " Undo + if !exists('b:undo_ftplugin') + let b:undo_ftplugin = '' + endif + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal spell<' +endif diff --git a/vim/indent/_GLOBAL.vim b/vim/indent/_GLOBAL.vim deleted file mode 100644 index d0bdea26..00000000 --- a/vim/indent/_GLOBAL.vim +++ /dev/null @@ -1,12 +0,0 @@ -" Source this file (probably with :runtime) to explicitly set local indent -" settings for a buffer back to the global settings, in case it was changed -" by a prior filetype (e.g. VimL). -setlocal autoindent< -setlocal expandtab< - -" Unfortunately, older versions of Vim (6.2 is known) accept neither the -" `option<` nor `option=` syntax for resetting these numeric values, so we do -" it this clunkier way. -execute 'setlocal shiftwidth=' . &g:shiftwidth -execute 'setlocal softtabstop=' . &g:softtabstop -execute 'setlocal tabstop=' . &g:tabstop diff --git a/vim/indent/c.vim b/vim/indent/c.vim deleted file mode 100644 index fd1b26af..00000000 --- a/vim/indent/c.vim +++ /dev/null @@ -1,2 +0,0 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index 8f98d915..24ef53ce 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -1,6 +1,10 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim - " Manual indenting and literal tabs for CSVs setlocal noautoindent setlocal noexpandtab + +" Undo +if !exists('b:undo_indent') + let b:undo_indent = '' +endif +let b:undo_indent = b:undo_indent + \ . '|setlocal autoindent< expandtab<' diff --git a/vim/indent/html.vim b/vim/indent/html.vim deleted file mode 100644 index fd1b26af..00000000 --- a/vim/indent/html.vim +++ /dev/null @@ -1,2 +0,0 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim deleted file mode 100644 index fd1b26af..00000000 --- a/vim/indent/perl.vim +++ /dev/null @@ -1,2 +0,0 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim diff --git a/vim/indent/php.vim b/vim/indent/php.vim index 025bf3f1..d0fb1f8f 100644 --- a/vim/indent/php.vim +++ b/vim/indent/php.vim @@ -1,6 +1,3 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim - " Lie to the php.vim indent file and tell it that it's already loaded itself, " to stop it processing its ridiculous expression-based indenting that never " seems to do what I want. Just plain autoindent is fine. diff --git a/vim/indent/sh.vim b/vim/indent/sh.vim deleted file mode 100644 index fd1b26af..00000000 --- a/vim/indent/sh.vim +++ /dev/null @@ -1,2 +0,0 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index a38e53e8..161fbbe3 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -1,6 +1,10 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim - " Manual indenting and literal tabs for TSVs setlocal noautoindent setlocal noexpandtab + +" Undo +if !exists('b:undo_indent') + let b:undo_indent = '' +endif +let b:undo_indent = b:undo_indent + \ . '|setlocal autoindent< expandtab<' diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim index 3b038349..f9a8f211 100644 --- a/vim/indent/vim.vim +++ b/vim/indent/vim.vim @@ -1,7 +1,11 @@ -" Restore local indent settings to the global values -runtime indent/_GLOBAL.vim - " Observe VimL conventions for two-space indents setlocal shiftwidth=2 setlocal softtabstop=2 setlocal tabstop=2 + +" Undo +if !exists('b:undo_indent') + let b:undo_indent = '' +endif +let b:undo_indent = b:undo_indent + \ . '|setlocal shiftwidth< softtabstop< tabstop<' -- cgit v1.2.3 From dc0ab08ed472c4db827360bfc9f5959e675a6c8a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 10:21:25 +1300 Subject: Add leader bindings for date stamping \d adds local time, \D adds UTC time. --- vim/config/command.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vim/config/command.vim b/vim/config/command.vim index f339635f..09ee0f40 100644 --- a/vim/config/command.vim +++ b/vim/config/command.vim @@ -25,3 +25,12 @@ set shellpipe=> if exists('+shellslash') set shellslash endif + +" \d inserts the current local date from date(1) +nnoremap + \ d + \ :read !date +" \D inserts the current UTC date from date(1) +nnoremap + \ D + \ :read !date -u -- cgit v1.2.3 From 35dbef982a4040158aee506873825c5d2f8db4f6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 10:10:44 +1300 Subject: Bind f to show current 'formatoptions' I think this option has become overloaded in recent versions and that these would make more sense and be more manageable as separate but interacting options. --- vim/config/format.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vim/config/format.vim b/vim/config/format.vim index e266f42a..e1da2d0b 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -2,6 +2,11 @@ " leaders when joining lines silent! set formatoptions+=j +" Show the current formatoptions at a glance +noremap + \ f + \ :setlocal formatoptions? + " Use toggle_option_flag.vim plugin to bind quick toggle actions for some " 'formatoptions' flags if has('user_commands') -- cgit v1.2.3 From 61d05839a42b56c0759264b493f98d5a516affc4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 13:38:10 +1300 Subject: Add user_ftplugin.vim and user_indent.vim plugins This reverts commit 09b83b6 and replaces it with a working version. Because of the order in which the autocmd hooks run, the attempted method of adding unloading instructions for my custom ftplugin and indent rules to the b:undo_ftplugin and b:undo_indent doesn't actually work. This is because the custom rules for both groups from ~/.vim are sourced *first*, before their core versions, so the changes the custom rules made to b:undo_ftplugin and b:undo_indent are simply clobbered by the core version when it loads itself. Therefore we need to arrange for two things: 1. A custom variable needs to be checked and executed when the filetype changes to revert the changes for the custom ftplugin or indent rules. 2. That execution needs to take place *first* when the filetype changes. I wrote two simple plugins with very similar code that are designed to run as a user's custom ftplugin.vim and indent.vim implementations, running before their brethren in the Vim core, and setting up an autocmd hook to :execute b:undo_user_ftplugin and b:undo_user_indent plugin respectively. This seemed to work well, so I've implemented it. It involves adding a shim to ~/.vim/indent.vim and ~/.vim/ftplugin.vim to "preload" the plugin when the `filetype indent plugin on` call is made. I've added that to the relevant Makefile targets. --- Makefile | 2 ++ vim/doc/user_ftplugin.txt | 27 +++++++++++++++++++++++++++ vim/doc/user_indent.txt | 27 +++++++++++++++++++++++++++ vim/ftplugin.vim | 1 + vim/ftplugin/mail.vim | 9 ++------- vim/ftplugin/markdown.vim | 9 ++------- vim/ftplugin/sh.vim | 9 ++------- vim/ftplugin/text.vim | 9 ++------- vim/indent.vim | 1 + vim/indent/csv.vim | 9 ++------- vim/indent/tsv.vim | 9 ++------- vim/indent/vim.vim | 10 +++++----- vim/plugin/user_ftplugin.vim | 24 ++++++++++++++++++++++++ vim/plugin/user_indent.vim | 24 ++++++++++++++++++++++++ 14 files changed, 123 insertions(+), 47 deletions(-) create mode 100644 vim/doc/user_ftplugin.txt create mode 100644 vim/doc/user_indent.txt create mode 100644 vim/ftplugin.vim create mode 100644 vim/indent.vim create mode 100644 vim/plugin/user_ftplugin.vim create mode 100644 vim/plugin/user_indent.vim diff --git a/Makefile b/Makefile index 5b14d8dd..196f3ed5 100644 --- a/Makefile +++ b/Makefile @@ -516,10 +516,12 @@ install-vim-ftdetect: install-vim-ftplugin: mkdir -p -- $(HOME)/.vim/ftplugin + cp -p -- vim/ftplugin.vim $(HOME)/.vim/ftplugin.vim cp -p -- vim/ftplugin/*.vim $(HOME)/.vim/ftplugin install-vim-indent: mkdir -p -- $(HOME)/.vim/indent + cp -p -- vim/indent.vim $(HOME)/.vim/indent.vim cp -p -- vim/indent/*.vim $(HOME)/.vim/indent install-vim-plugin: diff --git a/vim/doc/user_ftplugin.txt b/vim/doc/user_ftplugin.txt new file mode 100644 index 00000000..7aebdb84 --- /dev/null +++ b/vim/doc/user_ftplugin.txt @@ -0,0 +1,27 @@ +*user_ftplugin.txt* "Undo" for local ftplugin files + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to |FileType| to run before the one that the +core ftplugin.vim sets, to allow setting a b:undo_user_ftplugin variable with +code to |:execute| when the filetype is next changed, in much the same way that +the core files in Vim >= 7.0x support a b:|undo_ftplugin| variable. + +This will only work if it's loaded *before* ftplugin.vim so that the autocmd +hooks run in the right order. There are a couple of ways to do this: + +1. Create your own ~/.vim/ftplugin.vim with the following contents: + + silent! runtime plugin/user_ftplugin.vim + + This will then be sourced before the core ftplugin.vim runs. This is the + suggested method. + +2. Run the same line in your ~/.vimrc before your `filetype ftplugin on` line. + +See also: user_indent.vim. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. diff --git a/vim/doc/user_indent.txt b/vim/doc/user_indent.txt new file mode 100644 index 00000000..ff71d575 --- /dev/null +++ b/vim/doc/user_indent.txt @@ -0,0 +1,27 @@ +*user_indent.txt* "Undo" for local indent files + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to |FileType| to run before the one that the +core indent.vim sets, to allow setting a b:undo_user_indent variable with +code to |:execute| when the filetype is next changed, in much the same way that +the core files in Vim >= 7.0x support a b:|undo_indent| variable. + +This will only work if it's loaded *before* indent.vim so that the autocmd +hooks run in the right order. There are a couple of ways to do this: + +1. Create your own ~/.vim/indent.vim with the following contents: + + silent! runtime plugin/user_indent.vim + + This will then be sourced before the core indent.vim runs. This is the + suggested method. + +2. Run the same line in your ~/.vimrc before your `filetype indent on` line. + +See also: user_ftplugin.vim. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. diff --git a/vim/ftplugin.vim b/vim/ftplugin.vim new file mode 100644 index 00000000..21665dad --- /dev/null +++ b/vim/ftplugin.vim @@ -0,0 +1 @@ +silent! runtime plugin/user_ftplugin.vim diff --git a/vim/ftplugin/mail.vim b/vim/ftplugin/mail.vim index 236f25ff..d4840bfd 100644 --- a/vim/ftplugin/mail.vim +++ b/vim/ftplugin/mail.vim @@ -1,9 +1,4 @@ " Use trailing whitespace to denote continued paragraph setlocal formatoptions+=w - -" Undo -if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' -endif -let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal formatoptions<' +let b:undo_user_ftplugin + \ = 'setlocal formatoptions<' diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim index 15333202..ab27c2f7 100644 --- a/vim/ftplugin/markdown.vim +++ b/vim/ftplugin/markdown.vim @@ -1,11 +1,6 @@ " Spellcheck documents by default if has('syntax') setlocal spell - - " Undo - if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' - endif - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal spell<' + let b:undo_user_ftplugin + \ = 'setlocal spell<' endif diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim index 85251aa1..21d494e3 100644 --- a/vim/ftplugin/sh.vim +++ b/vim/ftplugin/sh.vim @@ -23,6 +23,8 @@ endif " Use han(1df) as a man(1) wrapper for Bash files if available if exists('b:is_bash') && executable('han') setlocal keywordprg=han + let b:undo_user_indent + \ = 'setlocal keywordprg<' endif " Map checker based on shell family @@ -48,10 +50,3 @@ endif nnoremap \ l \ :execute b:lint - -" Undo -if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' -endif -let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal keywordprg<' diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim index 15333202..ab27c2f7 100644 --- a/vim/ftplugin/text.vim +++ b/vim/ftplugin/text.vim @@ -1,11 +1,6 @@ " Spellcheck documents by default if has('syntax') setlocal spell - - " Undo - if !exists('b:undo_ftplugin') - let b:undo_ftplugin = '' - endif - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal spell<' + let b:undo_user_ftplugin + \ = 'setlocal spell<' endif diff --git a/vim/indent.vim b/vim/indent.vim new file mode 100644 index 00000000..baedf89b --- /dev/null +++ b/vim/indent.vim @@ -0,0 +1 @@ +silent! runtime plugin/user_indent.vim diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim index 24ef53ce..682bc3a8 100644 --- a/vim/indent/csv.vim +++ b/vim/indent/csv.vim @@ -1,10 +1,5 @@ " Manual indenting and literal tabs for CSVs setlocal noautoindent setlocal noexpandtab - -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' -endif -let b:undo_indent = b:undo_indent - \ . '|setlocal autoindent< expandtab<' +let b:undo_user_indent + \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim index 161fbbe3..951b3e60 100644 --- a/vim/indent/tsv.vim +++ b/vim/indent/tsv.vim @@ -1,10 +1,5 @@ " Manual indenting and literal tabs for TSVs setlocal noautoindent setlocal noexpandtab - -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' -endif -let b:undo_indent = b:undo_indent - \ . '|setlocal autoindent< expandtab<' +let b:undo_user_indent + \ = 'setlocal autoindent< expandtab<' diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim index f9a8f211..047a353d 100644 --- a/vim/indent/vim.vim +++ b/vim/indent/vim.vim @@ -3,9 +3,9 @@ setlocal shiftwidth=2 setlocal softtabstop=2 setlocal tabstop=2 -" Undo -if !exists('b:undo_indent') - let b:undo_indent = '' +" Ancient Vim can't use the '<' suffix syntax for resetting local integer +" options +if v:version > 700 + let b:undo_user_indent + \ = 'setlocal shiftwidth< softtabstop< tabstop<' endif -let b:undo_indent = b:undo_indent - \ . '|setlocal shiftwidth< softtabstop< tabstop<' diff --git a/vim/plugin/user_ftplugin.vim b/vim/plugin/user_ftplugin.vim new file mode 100644 index 00000000..d9739bda --- /dev/null +++ b/vim/plugin/user_ftplugin.vim @@ -0,0 +1,24 @@ +" +" user_ftplugin.vim: When switching filetypes, look for a b:undo_user_ftplugin +" variable and use it in much the same way the core's ftplugin.vim does +" b:undo_ftplugin in Vim >= 7.0. This allows you to undo your own ftplugin +" files the same way you can the core ones. +" +if exists('g:loaded_user_ftplugin') + \ || !has('autocmd') + \ || &compatible + finish +endif +let g:loaded_user_ftplugin = 1 + +function! s:LoadUserFtplugin() + if exists('b:undo_user_ftplugin') + execute b:undo_user_ftplugin + unlet b:undo_user_ftplugin + endif +endfunction + +augroup user_ftplugin + autocmd! + autocmd FileType * call s:LoadUserFtplugin() +augroup END diff --git a/vim/plugin/user_indent.vim b/vim/plugin/user_indent.vim new file mode 100644 index 00000000..01596bdb --- /dev/null +++ b/vim/plugin/user_indent.vim @@ -0,0 +1,24 @@ +" +" user_indent.vim: When switching filetypes, look for a b:undo_user_indent +" variable and use it in much the same way the core's indent.vim does +" b:undo_indent in Vim >= 7.0. This allows you to undo your own indent files +" the same way you can the core ones. +" +if exists('g:loaded_user_indent') + \ || !has('autocmd') + \ || &compatible + finish +endif +let g:loaded_user_indent = 1 + +function! s:LoadUserIndent() + if exists('b:undo_user_indent') + execute b:undo_user_indent + unlet b:undo_user_indent + endif +endfunction + +augroup user_indent + autocmd! + autocmd FileType * call s:LoadUserIndent() +augroup END -- cgit v1.2.3 From 13ecd5658e55afb84513a37226b790799e82c872 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 7 Nov 2017 13:48:11 +1300 Subject: Bump version number to v0.11.0 --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index a559f617..a6f5ce1e 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.10.0 -Sun Nov 5 23:53:44 UTC 2017 +tejr dotfiles v0.11.0 +Tue Nov 7 00:48:03 UTC 2017 -- cgit v1.2.3