aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:45:41 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-07 13:45:41 +1300
commit1522c7e3b2d8fc4737c6bacfcf9bdb1d60f780b0 (patch)
tree41328bc7e1f123c6067b61f9a7efeb24991896d5
parent04e90fcd534d4146becc0e20d0828e2ff48c3cdf (diff)
parent61d05839a42b56c0759264b493f98d5a516affc4 (diff)
downloaddotfiles-1522c7e3b2d8fc4737c6bacfcf9bdb1d60f780b0.tar.gz
Merge branch 'feature/vim-plug' into develop
* feature/vim-plug: Add user_ftplugin.vim and user_indent.vim plugins Use b:undo variables correctly 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
-rw-r--r--Makefile2
-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/copy_linebreak.vim69
-rw-r--r--vim/plugin/fixed_join.vim11
-rw-r--r--vim/plugin/strip_trailing_whitespace.vim11
-rw-r--r--vim/plugin/user_ftplugin.vim24
-rw-r--r--vim/plugin/user_indent.vim24
27 files changed, 222 insertions, 64 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/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/copy_linebreak.vim b/vim/plugin/copy_linebreak.vim
index 40f03393..2b5f7243 100644
--- a/vim/plugin/copy_linebreak.vim
+++ b/vim/plugin/copy_linebreak.vim
@@ -1,7 +1,7 @@
"
-" 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. 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 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 <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 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 <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -67,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/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