aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:48:45 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:48:45 +1300
commite10d9dfb621c210d99aff61fd20de5105455b220 (patch)
treead1cc192db6e8a8c59392c08148c9129cf172453
parentMerge branch 'release/v0.10.0' (diff)
parentBump version number to v0.11.0 (diff)
downloaddotfiles-0.11.0.tar.gz (sig)
dotfiles-0.11.0.zip
Merge branch 'release/v0.11.0'v0.11.0
* release/v0.11.0: Bump version number to v0.11.0 Add user_ftplugin.vim and user_indent.vim plugins Bind <Leader>f to show current 'formatoptions' Add leader bindings for date stamping Use b:undo variables correctly Add \p Vim binding to show filetype Update <Leader>b mapping to use new mapping name Add commands to copy_linebreak.vim Give copy_linebreak.vim enable/disable funcs, maps Add :FixedJoin command Add :StripTrailingWhitespace command Add "do", "then" keywords to Bash completion Break bash/bashrc.d/completion.bash inline lists Use consistent comment layout for Vim plugins Simplify 'formatoptions' config Refactor toggle_option_flag.vim
-rw-r--r--Makefile2
-rw-r--r--VERSION4
-rw-r--r--bash/bashrc.d/completion.bash87
-rw-r--r--vim/config/command.vim9
-rw-r--r--vim/config/file.vim5
-rw-r--r--vim/config/format.vim76
-rw-r--r--vim/config/wrap.vim2
-rw-r--r--vim/doc/copy_linebreak.txt20
-rw-r--r--vim/doc/fixed_join.txt5
-rw-r--r--vim/doc/strip_trailing_whitespace.txt3
-rw-r--r--vim/doc/user_ftplugin.txt27
-rw-r--r--vim/doc/user_indent.txt27
-rw-r--r--vim/ftplugin.vim1
-rw-r--r--vim/ftplugin/mail.vim2
-rw-r--r--vim/ftplugin/markdown.vim6
-rw-r--r--vim/ftplugin/sh.vim2
-rw-r--r--vim/ftplugin/text.vim6
-rw-r--r--vim/indent.vim1
-rw-r--r--vim/indent/_GLOBAL.vim12
-rw-r--r--vim/indent/c.vim2
-rw-r--r--vim/indent/csv.vim5
-rw-r--r--vim/indent/html.vim2
-rw-r--r--vim/indent/perl.vim2
-rw-r--r--vim/indent/php.vim3
-rw-r--r--vim/indent/sh.vim2
-rw-r--r--vim/indent/tsv.vim5
-rw-r--r--vim/indent/vim.vim10
-rw-r--r--vim/plugin/command_typos.vim7
-rw-r--r--vim/plugin/copy_linebreak.vim69
-rw-r--r--vim/plugin/fixed_join.vim11
-rw-r--r--vim/plugin/strip_trailing_whitespace.vim10
-rw-r--r--vim/plugin/toggle_option_flag.vim81
-rw-r--r--vim/plugin/user_ftplugin.vim24
-rw-r--r--vim/plugin/user_indent.vim24
34 files changed, 390 insertions, 164 deletions
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/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
diff --git a/bash/bashrc.d/completion.bash b/bash/bashrc.d/completion.bash
index 51de24b8..eb01dda2 100644
--- a/bash/bashrc.d/completion.bash
+++ b/bash/bashrc.d/completion.bash
@@ -4,53 +4,102 @@
# If COMP_WORDBREAKS has a value, strip all colons from it; this allows
# completing filenames correctly, since a colon is not a shell metacharacter:
# <http://tiswww.case.edu/php/chet/bash/FAQ> (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 \
+ do \
+ exec \
+ if \
+ hash \
+ then \
+ 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
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 <silent>
+ \ <Leader>d
+ \ :<C-U>read !date<CR>
+" \D inserts the current UTC date from date(1)
+nnoremap <silent>
+ \ <Leader>D
+ \ :<C-U>read !date -u<CR>
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 <silent>
+ \ <Leader>p
+ \ :<C-U>set filetype?<CR>
+
" Use all ancestors of current directory for :find
if has('file_in_path')
set path=**
diff --git a/vim/config/format.vim b/vim/config/format.vim
index 1f24ee56..e1da2d0b 100644
--- a/vim/config/format.vim
+++ b/vim/config/format.vim
@@ -1,65 +1,33 @@
-" 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')
+" Show the current formatoptions at a glance
+noremap <silent>
+ \ <Leader>f
+ \ :<C-U>setlocal formatoptions?<CR>
- " 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
+if has('user_commands')
- "
- " 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 <silent>
+ \ <Leader>a
+ \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
- " 'c' and 't' have both been around since at least 6.1
+ " c: Reformat comments to 'textwidth'
nnoremap <silent>
\ <Leader>c
\ :<C-U>ToggleOptionFlagLocal formatoptions c<CR>
+
+ " j: Delete comment leaders when joining lines
+ nnoremap <silent>
+ \ <Leader>j
+ \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR>
+
+ " t: Reformat non-comment text to 'textwidth'
nnoremap <silent>
\ <Leader>t
\ :<C-U>ToggleOptionFlagLocal formatoptions t<CR>
-
- " 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 <silent>
- \ <Leader>a
- \ :<C-U>ToggleOptionFlagLocal formatoptions a<CR>
- else
- nnoremap <silent>
- \ <Leader>a
- \ :<C-U>echoerr 'No formatoptions a-flag'<CR>
- endif
-
- " 'j' needs testing
- if s:formatoptions_has_j
- nnoremap <silent>
- \ <Leader>j
- \ :<C-U>ToggleOptionFlagLocal formatoptions j<CR>
- else
- nnoremap <silent>
- \ <Leader>j
- \ :<C-U>echoerr 'No formatoptions j-flag'<CR>
- endif
-
endif
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 <Leader>b <Plug>CopyLinebreak
+ nmap <Leader>b <Plug>CopyLinebreakToggle
endif
diff --git a/vim/doc/copy_linebreak.txt b/vim/doc/copy_linebreak.txt
index c8463386..15e4b1b0 100644
--- a/vim/doc/copy_linebreak.txt
+++ b/vim/doc/copy_linebreak.txt
@@ -3,10 +3,22 @@
Author: Tom Ryder <tom@sanctum.geek.nz>
License: Same terms as Vim itself (see |license|)
-This plugin provides a mapping target <Plug>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:
+
+ <Plug>CopyLinebreakEnable
+ <Plug>CopyLinebreakDisable
+ <Plug>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
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 <tom@sanctum.geek.nz>
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 <Plug>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/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/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 <tom@sanctum.geek.nz>
+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 <tom@sanctum.geek.nz>
+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 35432b96..d4840bfd 100644
--- a/vim/ftplugin/mail.vim
+++ b/vim/ftplugin/mail.vim
@@ -1,2 +1,4 @@
" Use trailing whitespace to denote continued paragraph
setlocal formatoptions+=w
+let b:undo_user_ftplugin
+ \ = 'setlocal formatoptions<'
diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim
new file mode 100644
index 00000000..ab27c2f7
--- /dev/null
+++ b/vim/ftplugin/markdown.vim
@@ -0,0 +1,6 @@
+" Spellcheck documents by default
+if has('syntax')
+ setlocal spell
+ let b:undo_user_ftplugin
+ \ = 'setlocal spell<'
+endif
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index 8990f0fa..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
diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim
new file mode 100644
index 00000000..ab27c2f7
--- /dev/null
+++ b/vim/ftplugin/text.vim
@@ -0,0 +1,6 @@
+" Spellcheck documents by default
+if has('syntax')
+ 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/_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..682bc3a8 100644
--- a/vim/indent/csv.vim
+++ b/vim/indent/csv.vim
@@ -1,6 +1,5 @@
-" Restore local indent settings to the global values
-runtime indent/_GLOBAL.vim
-
" Manual indenting and literal tabs for CSVs
setlocal noautoindent
setlocal noexpandtab
+let b:undo_user_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..951b3e60 100644
--- a/vim/indent/tsv.vim
+++ b/vim/indent/tsv.vim
@@ -1,6 +1,5 @@
-" Restore local indent settings to the global values
-runtime indent/_GLOBAL.vim
-
" Manual indenting and literal tabs for TSVs
setlocal noautoindent
setlocal noexpandtab
+let b:undo_user_indent
+ \ = 'setlocal autoindent< expandtab<'
diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim
index 3b038349..047a353d 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
+
+" 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
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 <tom@sanctum.geek.nz>
" License: Same as Vim itself
diff --git a/vim/plugin/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim
index faeb1617..2b5f7243 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 user-defined key sequences to toggle a group of
+" options that make text wrapped with 'wrap' copy-paste friendly. Also creates
+" user commands if it can.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -13,29 +13,54 @@ 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 <SID>CopyLinebreakEnable()
else
- setlocal linebreak linebreak?
- setlocal showbreak<
- if exists('&breakindent')
- setlocal breakindent
- endif
+ call <SID>CopyLinebreakDisable()
endif
-
endfunction
-" Provide mapping proxy to the function just defined
+" Provide mappings to the function just defined
noremap <silent> <unique>
- \ <Plug>CopyLinebreak
- \ :<C-U>call <SID>CopyLinebreak()<CR>
+ \ <Plug>CopyLinebreakEnable
+ \ :<C-U>call <SID>CopyLinebreakEnable()<CR>
+noremap <silent> <unique>
+ \ <Plug>CopyLinebreakDisable
+ \ :<C-U>call <SID>CopyLinebreakDisable()<CR>
+noremap <silent> <unique>
+ \ <Plug>CopyLinebreakToggle
+ \ :<C-U>call <SID>CopyLinebreakToggle()<CR>
+
+" Provide user commands if we can
+if has('user_commands')
+ command -nargs=0
+ \ CopyLinebreakEnable
+ \ call <SID>CopyLinebreakEnable
+ command -nargs=0
+ \ CopyLinebreakDisable
+ \ call <SID>CopyLinebreakDisable
+ command -nargs=0
+ \ CopyLinebreakToggle
+ \ call <SID>CopyLinebreakToggle
+endif
diff --git a/vim/plugin/fixed_join.vim b/vim/plugin/fixed_join.vim
index 18f563f3..2c9e1d92 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 and optional command to keep cursor
+" in place when joining lines in normal mode.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -31,3 +31,10 @@ endfunction
noremap <silent> <unique>
\ <Plug>FixedJoin
\ :<C-U>call <SID>FixedJoin()<CR>
+
+" Create a command as well in case it's useful
+if has('user_commands')
+ command -nargs=0
+ \ FixedJoin
+ \ call <SID>FixedJoin()
+endif
diff --git a/vim/plugin/strip_trailing_whitespace.vim b/vim/plugin/strip_trailing_whitespace.vim
index d5f5624a..1264a11f 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 and optional command
+" to strip trailing whitespace in the whole document.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -66,3 +67,10 @@ endfunction
noremap <silent> <unique>
\ <Plug>StripTrailingWhitespace
\ :<C-U>call <SID>StripTrailingWhitespace()<CR>
+
+" Define a user command too, if we can
+if has('user_commands')
+ command -nargs=0
+ \ StripTrailingWhiteSpace
+ \ call <SID>StripTrailingWhitespace()
+endif
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! \<Esc>'
+ 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
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