From b1dee73b770c7bda4bcc24b54c5ab2dd9953eb17 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 00:28:36 +1300 Subject: Separate command typos config to plugin Tentatively named command_typos.vim. I've just moved this as-is for now, but it will need review, especially the hardcoded mappings. --- vim/config/command.vim | 15 --------------- vim/plugin/command_typos.vim | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) create mode 100644 vim/plugin/command_typos.vim diff --git a/vim/config/command.vim b/vim/config/command.vim index 2a60bab3..f339635f 100644 --- a/vim/config/command.vim +++ b/vim/config/command.vim @@ -25,18 +25,3 @@ set shellpipe=> if exists('+shellslash') set shellslash endif - -" 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 -if has('user_commands') - command! -bang -complete=file -nargs=? E e - command! -bang -complete=file -nargs=? W w - command! -bang -complete=file -nargs=? WQ wq - command! -bang -complete=file -nargs=? Wq wq - command! -bang Q q - command! -bang Qa qa - command! -bang QA qa - command! -bang Wa wa - command! -bang WA wa -endif diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim new file mode 100644 index 00000000..5ee43e09 --- /dev/null +++ b/vim/plugin/command_typos.vim @@ -0,0 +1,14 @@ +" 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 +if has('user_commands') + command! -bang -complete=file -nargs=? E e + command! -bang -complete=file -nargs=? W w + command! -bang -complete=file -nargs=? WQ wq + command! -bang -complete=file -nargs=? Wq wq + command! -bang Q q + command! -bang Qa qa + command! -bang QA qa + command! -bang Wa wa + command! -bang WA wa +endif -- cgit v1.2.3 From 4c5e30242182c2b970b69381758f17f9e3703b11 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 3 Nov 2017 00:36:04 +1300 Subject: Move trailing space strip config into plugin --- vim/config/whitespace.vim | 57 -------------------------------- vim/plugin/strip_trailing_whitespace.vim | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 vim/config/whitespace.vim create mode 100644 vim/plugin/strip_trailing_whitespace.vim diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim deleted file mode 100644 index cc2554bd..00000000 --- a/vim/config/whitespace.vim +++ /dev/null @@ -1,57 +0,0 @@ -" Strip trailing whitespace with \x in the whole document -if has('eval') - - " Define function for stripping whitespace - function! s:StripTrailingWhitespace() - - " Iterating line number - let l:li = 1 - - " Line number of last line that had non-whitespace characters on it - let l:lw = 0 - - " Line number of the file's last line - let l:ll = line('$') - - " Iterate over the lines - while l:li <= l:ll - - " Get the line text - let l:line = getline(l:li) - - " Replace the line with a subsitution of its text stripping extraneous - " whitespace - call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) - - " If this line has any non-whitespace characters on it, update l:lw with - " its index - if l:line =~# '\m\C\S' - let l:lw = l:li - endif - - " Increment the line counter for the next iteration - let l:li = l:li + 1 - endwhile - - " If the last non-whitespace line was before the last line proper, we can - " delete all lines after it - if l:lw < l:ll - - " Get the current line and column so we can return to it - " (Yes I know about winsaveview() and winrestview(); I want this to work - " even on very old versions of Vim if possible) - let l:lc = line('.') - let l:cc = col('.') - - " Delete the lines, which will move the cursor - execute l:lw + 1.',$ delete' - - " Return the cursor to the saved position - call cursor(l:lc, l:cc) - endif - endfunction - - " Map \x to the function just defined - nnoremap x :call StripTrailingWhitespace() - -endif diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim new file mode 100644 index 00000000..cc2554bd --- /dev/null +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -0,0 +1,57 @@ +" Strip trailing whitespace with \x in the whole document +if has('eval') + + " Define function for stripping whitespace + function! s:StripTrailingWhitespace() + + " Iterating line number + let l:li = 1 + + " Line number of last line that had non-whitespace characters on it + let l:lw = 0 + + " Line number of the file's last line + let l:ll = line('$') + + " Iterate over the lines + while l:li <= l:ll + + " Get the line text + let l:line = getline(l:li) + + " Replace the line with a subsitution of its text stripping extraneous + " whitespace + call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) + + " If this line has any non-whitespace characters on it, update l:lw with + " its index + if l:line =~# '\m\C\S' + let l:lw = l:li + endif + + " Increment the line counter for the next iteration + let l:li = l:li + 1 + endwhile + + " If the last non-whitespace line was before the last line proper, we can + " delete all lines after it + if l:lw < l:ll + + " Get the current line and column so we can return to it + " (Yes I know about winsaveview() and winrestview(); I want this to work + " even on very old versions of Vim if possible) + let l:lc = line('.') + let l:cc = col('.') + + " Delete the lines, which will move the cursor + execute l:lw + 1.',$ delete' + + " Return the cursor to the saved position + call cursor(l:lc, l:cc) + endif + endfunction + + " Map \x to the function just defined + nnoremap x :call StripTrailingWhitespace() + +endif -- cgit v1.2.3 From 17d0781bb4d6eb12f79729f36b09e55bae7391a2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:02:36 +1300 Subject: Rename bigfile plugin to big_file Just for consistency with the other plugins I'm making. I don't think I really like the cutesy names given to Vim plugins. I prefer the slightly longer and maybe even namespaced names like Perl distributions and modules have. Let's see how well this works. --- vim/doc/big_file.txt | 12 ++++++++++ vim/doc/bigfile.txt | 12 ---------- vim/plugin/big_file.vim | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ vim/plugin/bigfile.vim | 60 ------------------------------------------------- 4 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 vim/doc/big_file.txt delete mode 100644 vim/doc/bigfile.txt create mode 100644 vim/plugin/big_file.vim delete mode 100644 vim/plugin/bigfile.vim diff --git a/vim/doc/big_file.txt b/vim/doc/big_file.txt new file mode 100644 index 00000000..aea0ee79 --- /dev/null +++ b/vim/doc/big_file.txt @@ -0,0 +1,12 @@ +*big_file.txt* Disable slow options for big files to speed things up + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to check the file size of an incoming +buffer, and if it's over a certain threshold, disables certain options in order +to make the file a bit easier to edit. + +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/bigfile.txt b/vim/doc/bigfile.txt deleted file mode 100644 index d7e56f28..00000000 --- a/vim/doc/bigfile.txt +++ /dev/null @@ -1,12 +0,0 @@ -*bigfile.txt* Disable slow options for big files to speed things up - -Author: Tom Ryder -License: Same terms as Vim itself (see |license|) - -This plugin adds an |autocmd| hook to check the file size of an incoming -buffer, and if it's over a certain threshold, disables certain options in order -to make the file a bit easier to edit. - -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/big_file.vim b/vim/plugin/big_file.vim new file mode 100644 index 00000000..4c07d7c3 --- /dev/null +++ b/vim/plugin/big_file.vim @@ -0,0 +1,60 @@ +" +" big_file.vim: When opening a large file, take some measures to keep things +" loading quickly. +" +" Author: Tom Ryder +" Copyright: 2017 +" License: Same as Vim itself +" +if has('eval') && has('autocmd') + + " Default threshold is 10 MiB + if !exists('g:big_file_size') + let g:big_file_size = 10 * 1024 * 1024 + endif + + " Default to leaving syntax highlighting off + if !exists('g:big_file_syntax') + let g:big_file_syntax = 0 + endif + + " Cut 'synmaxcol' down to this or smaller for big files + if !exists('g:big_file_size_synmaxcol') + let g:big_file_size_synmaxcol = 256 + endif + + " Declare function for turning off slow options + function! s:BigFileOptions(name, size) + + " Don't do anything if the file is under the threshold + if getfsize(a:name) <= a:size + return + endif + + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile + endif + + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') && &synmaxcol > g:big_file_size_synmaxcol + execute 'setlocal synmaxcol=' . g:big_file_size_synmaxcol + endif + + " Disable syntax highlighting if configured to do so + if !g:big_file_syntax + setlocal syntax=OFF + endif + + endfunction + + " Define autocmd for calling to check filesize + augroup big_file_options_bufreadpre + autocmd! + autocmd BufReadPre * call s:BigFileOptions(expand(''), g:big_file_size) + augroup end + +endif diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim deleted file mode 100644 index fece3d9b..00000000 --- a/vim/plugin/bigfile.vim +++ /dev/null @@ -1,60 +0,0 @@ -" -" bigfile.vim: When opening a large file, take some measures to keep things -" loading quickly. -" -" Author: Tom Ryder -" Copyright: 2017 -" License: Same as Vim itself -" -if has('eval') && has('autocmd') - - " Default threshold is 10 MiB - if !exists('g:bigfile_size') - let g:bigfile_size = 10 * 1024 * 1024 - endif - - " Default to leaving syntax highlighting off - if !exists('g:bigfile_syntax') - let g:bigfile_syntax = 0 - endif - - " Cut 'synmaxcol' down to this or smaller for big files - if !exists('g:bigfile_size_synmaxcol') - let g:bigfile_size_synmaxcol = 256 - endif - - " Declare function for turning off slow options - function! s:BigFileOptions(name, size) - - " Don't do anything if the file is under the threshold - if getfsize(a:name) <= a:size - return - endif - - " Turn off backups, swap files, and undo files - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - - " Limit the number of columns of syntax highlighting - if exists('&synmaxcol') && &synmaxcol > g:bigfile_size_synmaxcol - execute 'setlocal synmaxcol=' . g:bigfile_size_synmaxcol - endif - - " Disable syntax highlighting if configured to do so - if !g:bigfile_syntax - setlocal syntax=OFF - endif - - endfunction - - " Define autocmd for calling to check filesize - augroup bigfile_options_bufreadpre - autocmd! - autocmd BufReadPre * call s:BigFileOptions(expand(''), g:bigfile_size) - augroup end - -endif -- cgit v1.2.3 From 41b748050659534927267bbf6240e42fd1182e79 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:03:56 +1300 Subject: Rename a misnamed variable in big_file.vim The word "size" was added to this variable's name unnecesarily. --- vim/plugin/big_file.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/plugin/big_file.vim b/vim/plugin/big_file.vim index 4c07d7c3..5ccad7d2 100644 --- a/vim/plugin/big_file.vim +++ b/vim/plugin/big_file.vim @@ -19,8 +19,8 @@ if has('eval') && has('autocmd') endif " Cut 'synmaxcol' down to this or smaller for big files - if !exists('g:big_file_size_synmaxcol') - let g:big_file_size_synmaxcol = 256 + if !exists('g:big_file_synmaxcol') + let g:big_file_synmaxcol = 256 endif " Declare function for turning off slow options @@ -40,8 +40,8 @@ if has('eval') && has('autocmd') endif " Limit the number of columns of syntax highlighting - if exists('&synmaxcol') && &synmaxcol > g:big_file_size_synmaxcol - execute 'setlocal synmaxcol=' . g:big_file_size_synmaxcol + if exists('&synmaxcol') && &synmaxcol > g:big_file_synmaxcol + execute 'setlocal synmaxcol=' . g:big_file_synmaxcol endif " Disable syntax highlighting if configured to do so -- cgit v1.2.3 From 7ed0559c10d4bac62ef315560eaa592d9699ae32 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:20:55 +1300 Subject: Use prefix, make space strip configurable This properly abstracts out the StripTrailingWhitespace mapping rather than forcing it to x within the plugin itself. A bit nicer this way. --- vim/config/whitespace.vim | 2 ++ vim/plugin/strip_trailing_whitespace.vim | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 vim/config/whitespace.vim diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim new file mode 100644 index 00000000..75ab7173 --- /dev/null +++ b/vim/config/whitespace.vim @@ -0,0 +1,2 @@ +" \x strips trailing whitespace via a custom plugin +nmap x StripTrailingWhitespace diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index cc2554bd..6a83eb53 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,4 +1,5 @@ -" Strip trailing whitespace with \x in the whole document +" User-defined key mapping to strip trailing whitespace in the whole document +" Suggested mapping: \x if has('eval') " Define function for stripping whitespace @@ -51,7 +52,8 @@ if has('eval') endif endfunction - " Map \x to the function just defined - nnoremap x :call StripTrailingWhitespace() - + " Create mapping proxy to the function just defined + " Suggested mapping: x + noremap StripTrailingWhitespace + \ :call StripTrailingWhitespace() endif -- cgit v1.2.3 From b0a15bf0e7aae09b8a875a3803632e878be595bd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:27:42 +1300 Subject: Spin stable join config out into new plugin Again using the mapping abstraction and not defining the mapping for the user. --- vim/config/join.vim | 25 ++++--------------------- vim/plugin/fixed_join.vim | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 vim/plugin/fixed_join.vim diff --git a/vim/config/join.vim b/vim/config/join.vim index 7d764dce..ebf42a8b 100644 --- a/vim/config/join.vim +++ b/vim/config/join.vim @@ -2,26 +2,9 @@ " despite the noble Steve Losh's exhortations set nojoinspaces -" Keep my cursor in place when I join lines +" Rebind normal J to run plugin-defined join that doesn't jump around, but +" only if we have the eval feature, because otherwise this mapping won't exist +" and we should keep the default behaviour if has('eval') - - " Declare function - function! s:StableNormalJoin() - - " Save current cursor position - let l:lc = line('.') - let l:cc = col('.') - - " Build and execute join command - let l:command = '.,+' . v:count1 . 'join' - execute l:command - - " Restore cursor position - call cursor(l:lc, l:cc) - - endfunction - - " Remap J to the above function - nnoremap J :call StableNormalJoin() - + nmap J FixedJoin endif diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim new file mode 100644 index 00000000..ef1b03ef --- /dev/null +++ b/vim/plugin/fixed_join.vim @@ -0,0 +1,26 @@ +" User-defined key mapping to keep cursor in place when joining lines in +" normal mode +" Suggesting mapping: normal J +if has('eval') + + " Declare function + function! s:FixedJoin() + + " Save current cursor position + let l:lc = line('.') + let l:cc = col('.') + + " Build and execute join command + let l:command = '.,+' . v:count1 . 'join' + execute l:command + + " Restore cursor position + call cursor(l:lc, l:cc) + + endfunction + + " Create mapping proxy to the function just defined + " Suggesting mapping: normal J + noremap FixedJoin + \ :call FixedJoin() +endif -- cgit v1.2.3 From bfec788882cba3b6711d42c747960784daec012c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 02:51:50 +1300 Subject: Spin copyable linebreak config into new plugin Calling this one copy_linebreak.vim. Renamed both the internal function and the plugin key. --- vim/config/wrap.vim | 38 ++++---------------------------------- vim/plugin/copy_linebreak.vim | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 vim/plugin/copy_linebreak.vim diff --git a/vim/config/wrap.vim b/vim/config/wrap.vim index 0e5866d8..8cc1473a 100644 --- a/vim/config/wrap.vim +++ b/vim/config/wrap.vim @@ -23,42 +23,12 @@ if has('linebreak') " Precede continued lines with '...' set showbreak=... - " If we have the option, indent wrapped lines as much as the first line; - " keep the value as a script variable for the toggle function. - let s:breakindent = v:version > 704 - \ || v:version ==# 704 && has('patch338') - if s:breakindent + " If we have the option, indent wrapped lines as much as the first line + if has('&breakindent') set breakindent endif - " Bind \b to turn off linebreak and toggle the showbreak characters on and - " off for convenience of copypasting multiple lines from terminal emulators. - if has('eval') + " \b toggles copy-pasteable linebreak settings + nmap b CopyLinebreak - " Define function - function! s:ToggleBreak() - - " If linebreak is on, turn it off - if &l:linebreak - setlocal nolinebreak linebreak? - setlocal showbreak= - if s:breakindent - setlocal nobreakindent - endif - - " If it's off, turn it on - else - setlocal linebreak linebreak? - setlocal showbreak=... - if s:breakindent - setlocal breakindent - endif - endif - - endfunction - - " Map \b to defined function - nnoremap b :call ToggleBreak() - - endif endif diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim new file mode 100644 index 00000000..ac21b66d --- /dev/null +++ b/vim/plugin/copy_linebreak.vim @@ -0,0 +1,36 @@ +" +" 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. +" +" Suggested mapping: b +" +if has('eval') + + " Define function + function! s:CopyLinebreak() + + " If linebreak is on, turn it off + if &l:linebreak + setlocal nolinebreak linebreak? + setlocal showbreak= + if exists('&breakindent') + setlocal nobreakindent + endif + + " If it's off, turn it on + else + setlocal linebreak linebreak? + setlocal showbreak< + if exists('&breakindent') + setlocal breakindent + endif + endif + + endfunction + + " Provide mapping proxy to the function just defined + " Suggested mapping: b + noremap CopyLinebreak + \ :call CopyLinebreak() +endif -- cgit v1.2.3 From 28b65e3893f4b822de4a80f21ab75c59a21272b5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 03:55:34 +1300 Subject: Spin 'fo' toggle out into new flag toggler plugin This is an experimental new plugin that provides a command to toggle individual single-character flags in an option with a value of a set of such flags, in my case 'formatoptions'. A fair bit of evil eval()ing via :execute here, but I've tried to control it with some strict patern matching. --- vim/config/format.vim | 35 +++++++---------------------- vim/plugin/option_flags.vim | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 vim/plugin/option_flags.vim diff --git a/vim/config/format.vim b/vim/config/format.vim index 35245d0d..ceff2be1 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -5,8 +5,8 @@ if v:version > 703 || v:version ==# 703 && has('patch541') endif " -" Quick way to toggle flags in 'formatoptions' that I often want to change; -" specifically: +" Use option_flags.vim plugin to bind quick toggle actions for some +" 'formatoptions' flags: " " a - Automatically format paragraphs, reapplying the wrap on every text " insertion or deletion; sometimes I want this and sometimes I @@ -16,30 +16,11 @@ endif " to set for me) " t - Automatically wrap text at 'textwidth' (as above) " -" So I just have to type e.g. \a to toggle the auto-format flag on and off; -" very handy -" if has('eval') - - " Declare function - function! s:ToggleFormatFlag(flag) - - " Decide on whether we're adding or removing the flag - if &l:formatoptions =~# a:flag - let l:command = 'setlocal formatoptions-=' . a:flag - else - let l:command = 'setlocal formatoptions+=' . a:flag - endif - - " Execute the command we determined and show the result - silent! execute l:command - setlocal formatoptions? - - endfunction - - " Map leader-letters to corresponding format option flags - nnoremap a :call ToggleFormatFlag('a') - nnoremap c :call ToggleFormatFlag('c') - nnoremap t :call ToggleFormatFlag('t') - + nnoremap a + \ :call option_flags#toggle_local('formatoptions', 'a') + nnoremap c + \ :call option_flags#toggle_local('formatoptions', 'c') + nnoremap t + \ :call option_flags#toggle_local('formatoptions', 't') endif diff --git a/vim/plugin/option_flags.vim b/vim/plugin/option_flags.vim new file mode 100644 index 00000000..10739149 --- /dev/null +++ b/vim/plugin/option_flags.vim @@ -0,0 +1,54 @@ +" +" option_flags.vim: Provide functions to toggle flags in single-char grouped +" options like 'formatoptions', 'shortmess', 'complete' etc. +" +" This will fail hilariously if you try to set e.g. 'switchbuf' with it! +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if has('eval') + + " Public wrapper function to toggle a flag with 'set' + function! option_flags#toggle(option, flag) + call s:toggle(a:option, a:flag, 0) + endfunction + + " Public wrapper function to toggle a flag with 'setlocal' + function! option_flags#toggle_local(option, flag) + call s:toggle(a:option, a:flag, 1) + endfunction + + " Internal function to do the toggling + function! s:toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + if a:local + let l:set = 'setlocal ' + else + let l:set = 'set ' + endif + + " Use eval() to assign -= or += to l:op for the option toggle + " (I couldn't get {curly braces} indirection to work) + let l:op = '' + execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' + + " Use eval() to perform the option toggle and then print the value + execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' + + endfunction + +endif -- cgit v1.2.3 From 4c46c80b18df43eb7917f312e13e992a343b6fa1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 14:49:47 +1300 Subject: Specify an install-vim-autoload target We'll use this for defining Vim functions that should be dynamically loaded when required, rather like how pathogen.vim does it. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index c09541fd..cb5fcc4c 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ install-urxvt \ install-vim \ install-vim-after \ + install-vim-autoload \ install-vim-bundle \ install-vim-config \ install-vim-ftdetect \ @@ -472,6 +473,7 @@ install-urxvt: urxvt/ext/select -exec cp -p -- {} $(HOME)/.urxvt/ext \; install-vim: install-vim-after \ + install-vim-autoload \ install-vim-bundle \ install-vim-config \ install-vim-doc \ @@ -485,6 +487,10 @@ install-vim-after: -type d -exec sh -c 'mkdir -p -- $(HOME)/."$$1"' _ {} \; -o \ -type f -exec sh -c 'cp -p -- "$$1" $(HOME)/."$$1"' _ {} \; +install-vim-autoload: + mkdir -p -- $(HOME)/.vim/autoload + cp -p -- vim/autoload/*.vim $(HOME)/.vim/autoload + install-vim-bundle: install-vim-config find vim/bundle -name .git -prune -o \ -type d -exec sh -c 'mkdir -p -- $(HOME)/."$$1"' _ {} \; -o \ -- cgit v1.2.3 From c88cb8805f683eb6d886743f3e147a3ab0fbee91 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 14:52:07 +1300 Subject: Move Vim background detection logic into plugin --- vim/autoload/detect_background.vim | 18 ++++++++++++++++++ vim/config/syntax.vim | 27 ++------------------------- 2 files changed, 20 insertions(+), 25 deletions(-) create mode 100644 vim/autoload/detect_background.vim diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim new file mode 100644 index 00000000..a1a2c208 --- /dev/null +++ b/vim/autoload/detect_background.vim @@ -0,0 +1,18 @@ +" Invert Vim's built-in logic for choosing dark or light backgrounds; we'll +" default to choosing a dark background unless we find some reason *not* to. +function! detect_background#DetectBackground() + + " Split up the value of $COLORFGBG (if any) by semicolons + let l:colorfgbg = split($COLORFGBG, ';') + + " Get the background color value, or an empty string if none + let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : '' + + " Choose the background setting based on this value + if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15' + set background=light + else + set background=dark + endif + +endfunction diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index e7d94b1b..dfa7b784 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -5,32 +5,9 @@ if has('syntax') silent! syntax enable silent! syntax sync minlines=100 - " Invert Vim's built-in logic for choosing dark or light backgrounds; we'll - " default to choosing a dark background unless we find some reason *not* to. + " If we can, detect a light background, but default to a dark one if has('eval') && v:version >= 701 - - " Wrap all this logic in a function - function! s:DetectBackground() - - " Split up the value of $COLORFGBG (if any) by semicolons - let l:colorfgbg = split($COLORFGBG, ';') - - " Get the background color value, or an empty string if none - let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : '' - - " Choose the background setting based on this value - if l:bg ==# 'default' || l:bg ==# '7' || l:bg ==# '15' - set background=light - else - set background=dark - endif - - endfunction - - " Call the function just defined directly - call s:DetectBackground() - - " Ancient or cut-down Vim? Just go dark + call detect_background#DetectBackground() else set background=dark endif -- cgit v1.2.3 From 85b05425ed3be65439fefa5f0074d3d7f18217f9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:33:06 +1300 Subject: Don't suggest mappings in Vim plugin comments Pretty useless, really. --- vim/autoload/flag_toggle.vim | 54 ++++++++++++++++++++++++++++++++ vim/plugin/copy_linebreak.vim | 2 -- vim/plugin/fixed_join.vim | 2 -- vim/plugin/option_flags.vim | 54 -------------------------------- vim/plugin/strip_trailing_whitespace.vim | 2 -- 5 files changed, 54 insertions(+), 60 deletions(-) create mode 100644 vim/autoload/flag_toggle.vim delete mode 100644 vim/plugin/option_flags.vim diff --git a/vim/autoload/flag_toggle.vim b/vim/autoload/flag_toggle.vim new file mode 100644 index 00000000..10739149 --- /dev/null +++ b/vim/autoload/flag_toggle.vim @@ -0,0 +1,54 @@ +" +" option_flags.vim: Provide functions to toggle flags in single-char grouped +" options like 'formatoptions', 'shortmess', 'complete' etc. +" +" This will fail hilariously if you try to set e.g. 'switchbuf' with it! +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if has('eval') + + " Public wrapper function to toggle a flag with 'set' + function! option_flags#toggle(option, flag) + call s:toggle(a:option, a:flag, 0) + endfunction + + " Public wrapper function to toggle a flag with 'setlocal' + function! option_flags#toggle_local(option, flag) + call s:toggle(a:option, a:flag, 1) + endfunction + + " Internal function to do the toggling + function! s:toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + if a:local + let l:set = 'setlocal ' + else + let l:set = 'set ' + endif + + " Use eval() to assign -= or += to l:op for the option toggle + " (I couldn't get {curly braces} indirection to work) + let l:op = '' + execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' + + " Use eval() to perform the option toggle and then print the value + execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' + + endfunction + +endif diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index ac21b66d..cba2c866 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -3,7 +3,6 @@ " showbreak characters and breakindent mode on and off, for convenience of " copying multiple lines from terminal emulators. " -" Suggested mapping: b " if has('eval') @@ -30,7 +29,6 @@ if has('eval') endfunction " Provide mapping proxy to the function just defined - " Suggested mapping: b noremap CopyLinebreak \ :call CopyLinebreak() endif diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index ef1b03ef..81e61614 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -1,6 +1,5 @@ " User-defined key mapping to keep cursor in place when joining lines in " normal mode -" Suggesting mapping: normal J if has('eval') " Declare function @@ -20,7 +19,6 @@ if has('eval') endfunction " Create mapping proxy to the function just defined - " Suggesting mapping: normal J noremap FixedJoin \ :call FixedJoin() endif diff --git a/vim/plugin/option_flags.vim b/vim/plugin/option_flags.vim deleted file mode 100644 index 10739149..00000000 --- a/vim/plugin/option_flags.vim +++ /dev/null @@ -1,54 +0,0 @@ -" -" option_flags.vim: Provide functions to toggle flags in single-char grouped -" options like 'formatoptions', 'shortmess', 'complete' etc. -" -" This will fail hilariously if you try to set e.g. 'switchbuf' with it! -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if has('eval') - - " Public wrapper function to toggle a flag with 'set' - function! option_flags#toggle(option, flag) - call s:toggle(a:option, a:flag, 0) - endfunction - - " Public wrapper function to toggle a flag with 'setlocal' - function! option_flags#toggle_local(option, flag) - call s:toggle(a:option, a:flag, 1) - endfunction - - " Internal function to do the toggling - function! s:toggle(option, flag, local) - - " Check for weird options, we don't want to eval() anything funny - if a:option =~# '[^a-z]' - echoerr 'Illegal option name' - return - endif - - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' - echoerr 'Illegal flag' - return - endif - - " Choose which set command to use - if a:local - let l:set = 'setlocal ' - else - let l:set = 'set ' - endif - - " Use eval() to assign -= or += to l:op for the option toggle - " (I couldn't get {curly braces} indirection to work) - let l:op = '' - execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' - - " Use eval() to perform the option toggle and then print the value - execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' - - endfunction - -endif diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 6a83eb53..36e1d2ad 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,5 +1,4 @@ " User-defined key mapping to strip trailing whitespace in the whole document -" Suggested mapping: \x if has('eval') " Define function for stripping whitespace @@ -53,7 +52,6 @@ if has('eval') endfunction " Create mapping proxy to the function just defined - " Suggested mapping: x noremap StripTrailingWhitespace \ :call StripTrailingWhitespace() endif -- cgit v1.2.3 From ad7cb8319053250e4f2a2eb559bd942e741ba9b5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:35:09 +1300 Subject: Rename and refactor option toggle plugin Renamed to flag_toggle.vim and placed in autoload using the namespaced autoload function syntax. I'm not sure this is the right approach yet, but I seem to pretty rarely use a Vim earlier than 7.1 these days. --- vim/autoload/flag_toggle.vim | 89 +++++++++++++++++++++----------------------- vim/config/format.vim | 16 ++++---- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/vim/autoload/flag_toggle.vim b/vim/autoload/flag_toggle.vim index 10739149..2ff4584d 100644 --- a/vim/autoload/flag_toggle.vim +++ b/vim/autoload/flag_toggle.vim @@ -1,5 +1,5 @@ " -" option_flags.vim: Provide functions to toggle flags in single-char grouped +" flag_toggle.vim: Provide functions to toggle flags in single-char grouped " options like 'formatoptions', 'shortmess', 'complete' etc. " " This will fail hilariously if you try to set e.g. 'switchbuf' with it! @@ -7,48 +7,45 @@ " Author: Tom Ryder " License: Same as Vim itself " -if has('eval') - - " Public wrapper function to toggle a flag with 'set' - function! option_flags#toggle(option, flag) - call s:toggle(a:option, a:flag, 0) - endfunction - - " Public wrapper function to toggle a flag with 'setlocal' - function! option_flags#toggle_local(option, flag) - call s:toggle(a:option, a:flag, 1) - endfunction - - " Internal function to do the toggling - function! s:toggle(option, flag, local) - - " Check for weird options, we don't want to eval() anything funny - if a:option =~# '[^a-z]' - echoerr 'Illegal option name' - return - endif - - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' - echoerr 'Illegal flag' - return - endif - - " Choose which set command to use - if a:local - let l:set = 'setlocal ' - else - let l:set = 'set ' - endif - - " Use eval() to assign -= or += to l:op for the option toggle - " (I couldn't get {curly braces} indirection to work) - let l:op = '' - execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' - - " Use eval() to perform the option toggle and then print the value - execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' - - endfunction - -endif + +" Public wrapper function to toggle a flag with 'set' +function! flag_toggle#Toggle(option, flag) + call s:Toggle(a:option, a:flag, 0) +endfunction + +" Public wrapper function to toggle a flag with 'setlocal' +function! flag_toggle#ToggleLocal(option, flag) + call s:Toggle(a:option, a:flag, 1) +endfunction + +" Internal function to do the toggling +function! s:Toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + if a:local + let l:set = 'setlocal ' + else + let l:set = 'set ' + endif + + " Use eval() to assign -= or += to l:op for the option toggle + " (I couldn't get {curly braces} indirection to work) + let l:op = '' + execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' + + " Use eval() to perform the option toggle and then print the value + execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' + +endfunction diff --git a/vim/config/format.vim b/vim/config/format.vim index ceff2be1..9c68d843 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -5,7 +5,7 @@ if v:version > 703 || v:version ==# 703 && has('patch541') endif " -" Use option_flags.vim plugin to bind quick toggle actions for some +" Use flag_toggle.vim plugin to bind quick toggle actions for some " 'formatoptions' flags: " " a - Automatically format paragraphs, reapplying the wrap on every text @@ -16,11 +16,11 @@ endif " to set for me) " t - Automatically wrap text at 'textwidth' (as above) " -if has('eval') - nnoremap a - \ :call option_flags#toggle_local('formatoptions', 'a') - nnoremap c - \ :call option_flags#toggle_local('formatoptions', 'c') - nnoremap t - \ :call option_flags#toggle_local('formatoptions', 't') +if has('eval') && v:version >= 701 + silent! nnoremap a + \ :call flag_toggle#ToggleLocal('formatoptions', 'a') + silent! nnoremap c + \ :call flag_toggle#ToggleLocal('formatoptions', 'c') + silent! nnoremap t + \ :call flag_toggle#ToggleLocal('formatoptions', 't') endif -- cgit v1.2.3 From 5c18cfe99006fabb0a78bce6b946a4a930dde248 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:36:38 +1300 Subject: Wrap detect_background.vim func call in 'silent!' This prevents older versions of Vim like 6.2 from throwing "E1017: Missing braces" on merely parsing this code, even though they don't evaluate it. --- vim/config/syntax.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim index dfa7b784..8cb1228b 100644 --- a/vim/config/syntax.vim +++ b/vim/config/syntax.vim @@ -7,7 +7,7 @@ if has('syntax') " If we can, detect a light background, but default to a dark one if has('eval') && v:version >= 701 - call detect_background#DetectBackground() + silent! call detect_background#DetectBackground() else set background=dark endif -- cgit v1.2.3 From 2eb421d272c65106a9922f0be764bb2ac12f3fe3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:38:38 +1300 Subject: Check 'eval' feature for loading command_typos.vim I strongly suspect the presence of 'user_commands' implies it, but I'm not sure. --- vim/plugin/command_typos.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim index 5ee43e09..592392ab 100644 --- a/vim/plugin/command_typos.vim +++ b/vim/plugin/command_typos.vim @@ -1,7 +1,7 @@ " 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 -if has('user_commands') +if has('eval') && has('user_commands') command! -bang -complete=file -nargs=? E e command! -bang -complete=file -nargs=? W w command! -bang -complete=file -nargs=? WQ wq -- cgit v1.2.3 From 562c9ce6fbbd6fc8b9c5e470121dcc8e731de21e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:39:23 +1300 Subject: Use same comment boilerplate for custom plugins A brief explanation, an author name, and the license should do fine. --- vim/autoload/detect_background.vim | 10 ++++++++-- vim/plugin/big_file.vim | 1 - vim/plugin/command_typos.vim | 5 +++++ vim/plugin/copy_linebreak.vim | 2 ++ vim/plugin/fixed_join.vim | 5 +++++ vim/plugin/strip_trailing_whitespace.vim | 5 +++++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/vim/autoload/detect_background.vim b/vim/autoload/detect_background.vim index a1a2c208..89e5d19e 100644 --- a/vim/autoload/detect_background.vim +++ b/vim/autoload/detect_background.vim @@ -1,5 +1,11 @@ -" Invert Vim's built-in logic for choosing dark or light backgrounds; we'll -" default to choosing a dark background unless we find some reason *not* to. +" +" detect_background.vim: Invert Vim's built-in logic for choosing dark or +" light backgrounds; we'll default to choosing a dark background unless we +" find some reason *not* to. +" +" Author: Tom Ryder +" License: Same as Vim itself +" function! detect_background#DetectBackground() " Split up the value of $COLORFGBG (if any) by semicolons diff --git a/vim/plugin/big_file.vim b/vim/plugin/big_file.vim index 5ccad7d2..ec30158a 100644 --- a/vim/plugin/big_file.vim +++ b/vim/plugin/big_file.vim @@ -3,7 +3,6 @@ " loading quickly. " " Author: Tom Ryder -" Copyright: 2017 " License: Same as Vim itself " if has('eval') && has('autocmd') diff --git a/vim/plugin/command_typos.vim b/vim/plugin/command_typos.vim index 592392ab..32d194fb 100644 --- a/vim/plugin/command_typos.vim +++ b/vim/plugin/command_typos.vim @@ -1,6 +1,11 @@ +" " 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 +" if has('eval') && has('user_commands') command! -bang -complete=file -nargs=? E e command! -bang -complete=file -nargs=? W w diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim index cba2c866..1dc537d4 100644 --- a/vim/plugin/copy_linebreak.vim +++ b/vim/plugin/copy_linebreak.vim @@ -3,6 +3,8 @@ " 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 " if has('eval') diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim index 81e61614..c002f667 100644 --- a/vim/plugin/fixed_join.vim +++ b/vim/plugin/fixed_join.vim @@ -1,5 +1,10 @@ +" " User-defined key mapping to keep cursor in place when joining lines in " normal mode +" +" Author: Tom Ryder +" License: Same as Vim itself +" if has('eval') " Declare function diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim index 36e1d2ad..17fff33f 100644 --- a/vim/plugin/strip_trailing_whitespace.vim +++ b/vim/plugin/strip_trailing_whitespace.vim @@ -1,4 +1,9 @@ +" " User-defined key mapping to strip trailing whitespace in the whole document +" +" Author: Tom Ryder +" License: Same as Vim itself +" if has('eval') " Define function for stripping whitespace -- cgit v1.2.3 From dae845727dbb3a7f91137d85d322ee475d604289 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 17:57:39 +1300 Subject: Add short documentation for new custom plugins I'm using the plugin_name.txt syntax suggested by the Vim documentation. That may change in future as I study plugins written by experienced authors like Tim Pope. There will almost certainly be a lot more detail to add to each of these. --- vim/doc/command_typos.txt | 12 ++++++++++++ vim/doc/copy_linebreak.txt | 13 +++++++++++++ vim/doc/detect_background.txt | 14 ++++++++++++++ vim/doc/fixed_join.txt | 11 +++++++++++ vim/doc/flag_toggle.txt | 15 +++++++++++++++ vim/doc/strip_trailing_whitespace.txt | 12 ++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 vim/doc/command_typos.txt create mode 100644 vim/doc/copy_linebreak.txt create mode 100644 vim/doc/detect_background.txt create mode 100644 vim/doc/fixed_join.txt create mode 100644 vim/doc/flag_toggle.txt create mode 100644 vim/doc/strip_trailing_whitespace.txt diff --git a/vim/doc/command_typos.txt b/vim/doc/command_typos.txt new file mode 100644 index 00000000..93f37df9 --- /dev/null +++ b/vim/doc/command_typos.txt @@ -0,0 +1,12 @@ +*command_typos.txt* Bind capital-letter versions of common commands + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin defines custom commands like :W, :Qa, and :Wq to match their +lowercase analogues, to forgive me when my pinky finger doesn't roll off the +Shift key quite soon enough after pressing the colon key. + +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/copy_linebreak.txt b/vim/doc/copy_linebreak.txt new file mode 100644 index 00000000..c8463386 --- /dev/null +++ b/vim/doc/copy_linebreak.txt @@ -0,0 +1,13 @@ +*copy_linebreak.txt* Mapping to toggle copy-paste friendly linebreak options + +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 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/detect_background.txt b/vim/doc/detect_background.txt new file mode 100644 index 00000000..ad42221c --- /dev/null +++ b/vim/doc/detect_background.txt @@ -0,0 +1,14 @@ +*detect_background.txt* Figure out 'background' with a bias towards "dark" + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin inspects the $COLORFGBG environment variable to determine whether +the user is using a terminal with a light background. It reverses Vim's +built-in attempts to do this, which have the opposite default. + +It does not inspect the value of the $TERM variable or |'term'| at all. + +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/fixed_join.txt b/vim/doc/fixed_join.txt new file mode 100644 index 00000000..0ee957d0 --- /dev/null +++ b/vim/doc/fixed_join.txt @@ -0,0 +1,11 @@ +*fixed_join.txt* Mapping to join lines in normal mode without moving cursor + +Author: Tom Ryder +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. + +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/flag_toggle.txt b/vim/doc/flag_toggle.txt new file mode 100644 index 00000000..5f1b504a --- /dev/null +++ b/vim/doc/flag_toggle.txt @@ -0,0 +1,15 @@ +*flag_toggle.txt* Functions to toggle single-character flags in options + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin provides functions flag_toggle#Toggle(option, flag) and +flag_toggle#ToggleLocal(option, flag) to toggle the values of options like +|'formatoptions'| or |'complete'| that have values comprised of +single-character flags. The author originally designed it for toggling flags in +|'formatoptions'| quickly. + +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/strip_trailing_whitespace.txt b/vim/doc/strip_trailing_whitespace.txt new file mode 100644 index 00000000..670877c9 --- /dev/null +++ b/vim/doc/strip_trailing_whitespace.txt @@ -0,0 +1,12 @@ +*strip_trailing_whitespace.txt* Strip trailing whitespace from whole buffer + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +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. + +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. -- cgit v1.2.3 From 2c20a3c3427befd77029fc37cbda0476f650b681 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 18:21:16 +1300 Subject: Rename toggle plugin again, use commands not funcs This method makes a bit more sense, and amounts to slightly less verbose mapping commands. It does really on the +user_commands feature being available, however. --- vim/autoload/flag_toggle.vim | 51 --------------------------------------- vim/config/format.vim | 16 ++++++------ vim/doc/flag_toggle.txt | 15 ------------ vim/doc/toggle_option_flag.txt | 16 ++++++++++++ vim/plugin/toggle_option_flag.vim | 44 +++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 74 deletions(-) delete mode 100644 vim/autoload/flag_toggle.vim delete mode 100644 vim/doc/flag_toggle.txt create mode 100644 vim/doc/toggle_option_flag.txt create mode 100644 vim/plugin/toggle_option_flag.vim diff --git a/vim/autoload/flag_toggle.vim b/vim/autoload/flag_toggle.vim deleted file mode 100644 index 2ff4584d..00000000 --- a/vim/autoload/flag_toggle.vim +++ /dev/null @@ -1,51 +0,0 @@ -" -" flag_toggle.vim: Provide functions to toggle flags in single-char grouped -" options like 'formatoptions', 'shortmess', 'complete' etc. -" -" This will fail hilariously if you try to set e.g. 'switchbuf' with it! -" -" Author: Tom Ryder -" License: Same as Vim itself -" - -" Public wrapper function to toggle a flag with 'set' -function! flag_toggle#Toggle(option, flag) - call s:Toggle(a:option, a:flag, 0) -endfunction - -" Public wrapper function to toggle a flag with 'setlocal' -function! flag_toggle#ToggleLocal(option, flag) - call s:Toggle(a:option, a:flag, 1) -endfunction - -" Internal function to do the toggling -function! s:Toggle(option, flag, local) - - " Check for weird options, we don't want to eval() anything funny - if a:option =~# '[^a-z]' - echoerr 'Illegal option name' - return - endif - - " Weird flags, too; should be a single inoffensive char - if a:flag !~# '^[a-z0-9.]$' - echoerr 'Illegal flag' - return - endif - - " Choose which set command to use - if a:local - let l:set = 'setlocal ' - else - let l:set = 'set ' - endif - - " Use eval() to assign -= or += to l:op for the option toggle - " (I couldn't get {curly braces} indirection to work) - let l:op = '' - execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' - - " Use eval() to perform the option toggle and then print the value - execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' - -endfunction diff --git a/vim/config/format.vim b/vim/config/format.vim index 9c68d843..572e9877 100644 --- a/vim/config/format.vim +++ b/vim/config/format.vim @@ -5,7 +5,7 @@ if v:version > 703 || v:version ==# 703 && has('patch541') endif " -" Use flag_toggle.vim plugin to bind quick toggle actions for some +" Use toggle_option_flag.vim plugin to bind quick toggle actions for some " 'formatoptions' flags: " " a - Automatically format paragraphs, reapplying the wrap on every text @@ -16,11 +16,11 @@ endif " to set for me) " t - Automatically wrap text at 'textwidth' (as above) " -if has('eval') && v:version >= 701 - silent! nnoremap a - \ :call flag_toggle#ToggleLocal('formatoptions', 'a') - silent! nnoremap c - \ :call flag_toggle#ToggleLocal('formatoptions', 'c') - silent! nnoremap t - \ :call flag_toggle#ToggleLocal('formatoptions', 't') +if has('eval') && has('user_commands') + nnoremap a + \ :ToggleOptionFlagLocal formatoptions a + nnoremap c + \ :ToggleOptionFlagLocal formatoptions c + nnoremap t + \ :ToggleOptionFlagLocal formatoptions t endif diff --git a/vim/doc/flag_toggle.txt b/vim/doc/flag_toggle.txt deleted file mode 100644 index 5f1b504a..00000000 --- a/vim/doc/flag_toggle.txt +++ /dev/null @@ -1,15 +0,0 @@ -*flag_toggle.txt* Functions to toggle single-character flags in options - -Author: Tom Ryder -License: Same terms as Vim itself (see |license|) - -This plugin provides functions flag_toggle#Toggle(option, flag) and -flag_toggle#ToggleLocal(option, flag) to toggle the values of options like -|'formatoptions'| or |'complete'| that have values comprised of -single-character flags. The author originally designed it for toggling flags in -|'formatoptions'| quickly. - -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/toggle_option_flag.txt b/vim/doc/toggle_option_flag.txt new file mode 100644 index 00000000..16557d5c --- /dev/null +++ b/vim/doc/toggle_option_flag.txt @@ -0,0 +1,16 @@ +*toggle_option_flag.txt* Commands to toggle single-character option flags + +Author: Tom Ryder +License: Same terms as Vim itself (see |license|) + +This plugin provides commands :ToggleOptionFlag and :ToggleOptionFlagLocal to +toggle the values of options like |'formatoptions'| or |'complete'| that have +values comprised of single-character flags. The author originally designed it +for toggling flags in |'formatoptions'| quickly. + + :ToggleOptionFlag formatoptions a + :ToggleOptionFlagLocal shortmess I + +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/toggle_option_flag.vim b/vim/plugin/toggle_option_flag.vim new file mode 100644 index 00000000..10b4fe7a --- /dev/null +++ b/vim/plugin/toggle_option_flag.vim @@ -0,0 +1,44 @@ +" +" toggle_option_flag.vim: Provide commands to toggle flags in single-char +" grouped options like 'formatoptions', 'shortmess', 'complete' etc. +" +" This will fail hilariously if you try to set e.g. 'switchbuf' with it! +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if has('eval') && has('user_commands') + + " Internal function to do the toggling + function! s:Toggle(option, flag, local) + + " Check for weird options, we don't want to eval() anything funny + if a:option =~# '[^a-z]' + echoerr 'Illegal option name' + return + endif + + " Weird flags, too; should be a single inoffensive char + if a:flag !~# '^[a-z0-9.]$' + echoerr 'Illegal flag' + return + endif + + " Choose which set command to use + let l:set = a:local ? 'setlocal' : 'set' + + " Use eval() to assign -= or += to l:op for the option toggle + " (I couldn't get {curly braces} indirection to work) + let l:op = '' + execute 'let l:op = &'.a:option.' =~# a:flag ? "-=" : "+="' + + " Use eval() to perform the option toggle and then print the value + execute l:set . ' ' . a:option . l:op . a:flag . ' ' . a:option . '?' + + endfunction + + " User commands wrapping around calls to the above function + command! -nargs=+ ToggleOptionFlag :call Toggle(, 0) + command! -nargs=+ ToggleOptionFlagLocal :call Toggle(, 1) + +endif -- cgit v1.2.3 From 173d86f0ad79b0d1739b2f202d0aafc9c08335c9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 18:40:54 +1300 Subject: Update README to mention Vim plugins --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 361cfa62..b30bf8f7 100644 --- a/README.md +++ b/README.md @@ -343,10 +343,20 @@ The configuration is broken into subfiles in `~/.vim/config/*.vim`, included by extensively commented, mostly because I was reading through it one day and realised I'd forgotten what half of it did. -I define a few custom per-filetype rules for stuff I often edit in +If the logic for doing something involves more than a few lines or any +structures like functions, I like to implement it as a plugin in +`~/.vim/plugin` and/or `~/.vim/autoload`. There's documentation for each of +those in `~/.vim/doc`. + +I also define a few custom per-filetype rules for stuff I often edit in `~/.vim/ftplugin`, including some local mappings for checking, linting, and tidying. +Any/all of the general or filetype plugins may eventually be spun off into +their own repositories in the future, but for the moment they live here. +Contact me if you find one of them useful and you'd like to see it in its own +distribution. + Third-party plugins are in submodules in `~/.vim/bundle`, loaded using Tim Pope's [pathogen.vim](https://github.com/tpope/vim-pathogen). -- cgit v1.2.3 From 93b8600d0c2dbb5c0d256f5f768efc51b798be7a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 18:42:17 +1300 Subject: Add heading for Vim plugins subsection --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b30bf8f7..bc84d378 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,8 @@ The configuration is broken into subfiles in `~/.vim/config/*.vim`, included by extensively commented, mostly because I was reading through it one day and realised I'd forgotten what half of it did. +#### Plugins + If the logic for doing something involves more than a few lines or any structures like functions, I like to implement it as a plugin in `~/.vim/plugin` and/or `~/.vim/autoload`. There's documentation for each of -- cgit v1.2.3 From af5ec4f4753888fa760f6cc4c005555747601849 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 18:45:41 +1300 Subject: Bump version number --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 7feb464a..2de1dcdb 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.6.1 -Fri Nov 3 12:46:45 UTC 2017 +tejr dotfiles v0.7.0 +Sat Nov 4 05:45:33 UTC 2017 -- cgit v1.2.3 From deda498e30dcde4a037224beb6662a795bdc2392 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 4 Nov 2017 18:46:01 +1300 Subject: Update dotfiles(7) manual from README.md --- man/man7/dotfiles.7df | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/man/man7/dotfiles.7df b/man/man7/dotfiles.7df index fe56e138..fbb1da64 100644 --- a/man/man7/dotfiles.7df +++ b/man/man7/dotfiles.7df @@ -142,6 +142,8 @@ Fork of the rxvt terminal emulator with Unicode support Subversion (https://subversion.apache.org/) \[en] Apache Subversion, a version control system .IP \[bu] 2 +tidy (http://www.html-tidy.org/) \[en] HTML/XHTML linter and tidier +.IP \[bu] 2 tmux (https://tmux.github.io/) \[en] Terminal multiplexer similar to GNU Screen .IP \[bu] 2 @@ -475,13 +477,29 @@ I try not to deviate too much from the Vim defaults behaviour in terms of interactive behavior and keybindings. .PP The configuration is broken into subfiles in -\f[C]\&.vim/config/*.vim\f[], included by \f[C]~/.vimrc\f[] using +\f[C]~/.vim/config/*.vim\f[], included by \f[C]~/.vimrc\f[] using \f[C]:runtime\f[] (http://vimdoc.sourceforge.net/htmldoc/repeat.html#:runtime). It's extensively commented, mostly because I was reading through it one day and realised I'd forgotten what half of it did. +.SS Plugins +.PP +If the logic for doing something involves more than a few lines or any +structures like functions, I like to implement it as a plugin in +\f[C]~/.vim/plugin\f[] and/or \f[C]~/.vim/autoload\f[]. +There's documentation for each of those in \f[C]~/.vim/doc\f[]. +.PP +I also define a few custom per\-filetype rules for stuff I often edit in +\f[C]~/.vim/ftplugin\f[], including some local mappings for checking, +linting, and tidying. +.PP +Any/all of the general or filetype plugins may eventually be spun off +into their own repositories in the future, but for the moment they live +here. +Contact me if you find one of them useful and you'd like to see it in +its own distribution. .PP -Plugins are in submodules in \f[C]\&.vim/bundle\f[], loaded using Tim -Pope's pathogen.vim (https://github.com/tpope/vim-pathogen). +Third\-party plugins are in submodules in \f[C]~/.vim/bundle\f[], loaded +using Tim Pope's pathogen.vim (https://github.com/tpope/vim-pathogen). .SS Scripts .PP Where practical, I make short scripts into POSIX (but not Bourne) -- cgit v1.2.3