aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim')
-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.vim9
-rw-r--r--vim/ftplugin/markdown.vim9
-rw-r--r--vim/ftplugin/sh.vim9
-rw-r--r--vim/ftplugin/text.vim9
-rw-r--r--vim/indent.vim1
-rw-r--r--vim/indent/csv.vim9
-rw-r--r--vim/indent/tsv.vim9
-rw-r--r--vim/indent/vim.vim10
-rw-r--r--vim/plugin/user_ftplugin.vim24
-rw-r--r--vim/plugin/user_indent.vim24
13 files changed, 121 insertions, 47 deletions
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 236f25ff..d4840bfd 100644
--- a/vim/ftplugin/mail.vim
+++ b/vim/ftplugin/mail.vim
@@ -1,9 +1,4 @@
" Use trailing whitespace to denote continued paragraph
setlocal formatoptions+=w
-
-" Undo
-if !exists('b:undo_ftplugin')
- let b:undo_ftplugin = ''
-endif
-let b:undo_ftplugin = b:undo_ftplugin
- \ . '|setlocal formatoptions<'
+let b:undo_user_ftplugin
+ \ = 'setlocal formatoptions<'
diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim
index 15333202..ab27c2f7 100644
--- a/vim/ftplugin/markdown.vim
+++ b/vim/ftplugin/markdown.vim
@@ -1,11 +1,6 @@
" Spellcheck documents by default
if has('syntax')
setlocal spell
-
- " Undo
- if !exists('b:undo_ftplugin')
- let b:undo_ftplugin = ''
- endif
- let b:undo_ftplugin = b:undo_ftplugin
- \ . '|setlocal spell<'
+ let b:undo_user_ftplugin
+ \ = 'setlocal spell<'
endif
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index 85251aa1..21d494e3 100644
--- a/vim/ftplugin/sh.vim
+++ b/vim/ftplugin/sh.vim
@@ -23,6 +23,8 @@ endif
" Use han(1df) as a man(1) wrapper for Bash files if available
if exists('b:is_bash') && executable('han')
setlocal keywordprg=han
+ let b:undo_user_indent
+ \ = 'setlocal keywordprg<'
endif
" Map checker based on shell family
@@ -48,10 +50,3 @@ endif
nnoremap <buffer> <silent>
\ <LocalLeader>l
\ :<C-U>execute b:lint<CR>
-
-" Undo
-if !exists('b:undo_ftplugin')
- let b:undo_ftplugin = ''
-endif
-let b:undo_ftplugin = b:undo_ftplugin
- \ . '|setlocal keywordprg<'
diff --git a/vim/ftplugin/text.vim b/vim/ftplugin/text.vim
index 15333202..ab27c2f7 100644
--- a/vim/ftplugin/text.vim
+++ b/vim/ftplugin/text.vim
@@ -1,11 +1,6 @@
" Spellcheck documents by default
if has('syntax')
setlocal spell
-
- " Undo
- if !exists('b:undo_ftplugin')
- let b:undo_ftplugin = ''
- endif
- let b:undo_ftplugin = b:undo_ftplugin
- \ . '|setlocal spell<'
+ let b:undo_user_ftplugin
+ \ = 'setlocal spell<'
endif
diff --git a/vim/indent.vim b/vim/indent.vim
new file mode 100644
index 00000000..baedf89b
--- /dev/null
+++ b/vim/indent.vim
@@ -0,0 +1 @@
+silent! runtime plugin/user_indent.vim
diff --git a/vim/indent/csv.vim b/vim/indent/csv.vim
index 24ef53ce..682bc3a8 100644
--- a/vim/indent/csv.vim
+++ b/vim/indent/csv.vim
@@ -1,10 +1,5 @@
" Manual indenting and literal tabs for CSVs
setlocal noautoindent
setlocal noexpandtab
-
-" Undo
-if !exists('b:undo_indent')
- let b:undo_indent = ''
-endif
-let b:undo_indent = b:undo_indent
- \ . '|setlocal autoindent< expandtab<'
+let b:undo_user_indent
+ \ = 'setlocal autoindent< expandtab<'
diff --git a/vim/indent/tsv.vim b/vim/indent/tsv.vim
index 161fbbe3..951b3e60 100644
--- a/vim/indent/tsv.vim
+++ b/vim/indent/tsv.vim
@@ -1,10 +1,5 @@
" Manual indenting and literal tabs for TSVs
setlocal noautoindent
setlocal noexpandtab
-
-" Undo
-if !exists('b:undo_indent')
- let b:undo_indent = ''
-endif
-let b:undo_indent = b:undo_indent
- \ . '|setlocal autoindent< expandtab<'
+let b:undo_user_indent
+ \ = 'setlocal autoindent< expandtab<'
diff --git a/vim/indent/vim.vim b/vim/indent/vim.vim
index f9a8f211..047a353d 100644
--- a/vim/indent/vim.vim
+++ b/vim/indent/vim.vim
@@ -3,9 +3,9 @@ setlocal shiftwidth=2
setlocal softtabstop=2
setlocal tabstop=2
-" Undo
-if !exists('b:undo_indent')
- let b:undo_indent = ''
+" Ancient Vim can't use the '<' suffix syntax for resetting local integer
+" options
+if v:version > 700
+ let b:undo_user_indent
+ \ = 'setlocal shiftwidth< softtabstop< tabstop<'
endif
-let b:undo_indent = b:undo_indent
- \ . '|setlocal shiftwidth< softtabstop< tabstop<'
diff --git a/vim/plugin/user_ftplugin.vim b/vim/plugin/user_ftplugin.vim
new file mode 100644
index 00000000..d9739bda
--- /dev/null
+++ b/vim/plugin/user_ftplugin.vim
@@ -0,0 +1,24 @@
+"
+" user_ftplugin.vim: When switching filetypes, look for a b:undo_user_ftplugin
+" variable and use it in much the same way the core's ftplugin.vim does
+" b:undo_ftplugin in Vim >= 7.0. This allows you to undo your own ftplugin
+" files the same way you can the core ones.
+"
+if exists('g:loaded_user_ftplugin')
+ \ || !has('autocmd')
+ \ || &compatible
+ finish
+endif
+let g:loaded_user_ftplugin = 1
+
+function! s:LoadUserFtplugin()
+ if exists('b:undo_user_ftplugin')
+ execute b:undo_user_ftplugin
+ unlet b:undo_user_ftplugin
+ endif
+endfunction
+
+augroup user_ftplugin
+ autocmd!
+ autocmd FileType * call s:LoadUserFtplugin()
+augroup END
diff --git a/vim/plugin/user_indent.vim b/vim/plugin/user_indent.vim
new file mode 100644
index 00000000..01596bdb
--- /dev/null
+++ b/vim/plugin/user_indent.vim
@@ -0,0 +1,24 @@
+"
+" user_indent.vim: When switching filetypes, look for a b:undo_user_indent
+" variable and use it in much the same way the core's indent.vim does
+" b:undo_indent in Vim >= 7.0. This allows you to undo your own indent files
+" the same way you can the core ones.
+"
+if exists('g:loaded_user_indent')
+ \ || !has('autocmd')
+ \ || &compatible
+ finish
+endif
+let g:loaded_user_indent = 1
+
+function! s:LoadUserIndent()
+ if exists('b:undo_user_indent')
+ execute b:undo_user_indent
+ unlet b:undo_user_indent
+ endif
+endfunction
+
+augroup user_indent
+ autocmd!
+ autocmd FileType * call s:LoadUserIndent()
+augroup END