aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--vim/config/leader.vim3
-rw-r--r--vim/ftplugin/html.vim24
-rw-r--r--vim/ftplugin/perl.vim17
-rw-r--r--vim/ftplugin/sh.vim22
-rw-r--r--vim/ftplugin/vim.vim5
6 files changed, 66 insertions, 13 deletions
diff --git a/README.md b/README.md
index 028a42fa..c3ffbf44 100644
--- a/README.md
+++ b/README.md
@@ -342,8 +342,12 @@ 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 are in submodules in `~/.vim/bundle`, loaded using Tim Pope's
-[pathogen.vim](https://github.com/tpope/vim-pathogen).
+I define a few custom per-filetype rules for stuff I often edit in
+`~/.vim/ftplugin`, including some local mappings for checking, linting, and
+tidying.
+
+Third-party plugins are in submodules in `~/.vim/bundle`, loaded using Tim
+Pope's [pathogen.vim](https://github.com/tpope/vim-pathogen).
Scripts
-------
diff --git a/vim/config/leader.vim b/vim/config/leader.vim
new file mode 100644
index 00000000..9ca8f762
--- /dev/null
+++ b/vim/config/leader.vim
@@ -0,0 +1,3 @@
+" Use different keys for global and local leaders
+let g:mapleader = '\'
+let g:maplocalleader = '_'
diff --git a/vim/ftplugin/html.vim b/vim/ftplugin/html.vim
index 309b7132..c756eb80 100644
--- a/vim/ftplugin/html.vim
+++ b/vim/ftplugin/html.vim
@@ -1,11 +1,25 @@
-" Run tidy -eq -utf8 on file for the current buffer
-nnoremap <LocalLeader>v :exe "!tidy -eq -utf8 " . shellescape(expand("%"))<CR>
+" Run `tidy -errors -quiet` over buffer
+nnoremap <buffer> <silent> <LocalLeader>c
+ \ :write !tidy -errors -quiet<CR>
+
+" Filter buffer through `tidy`
+nnoremap <buffer> <silent> <LocalLeader>t
+ \ :%!tidy -quiet<CR>
" Make a bare URL into a link to itself
function! s:UrlLink()
+
+ " Yank this whole whitespace-separated word
normal! yiW
- execute "normal! i<a href=\"\<C-R>0\">\<Esc>"
+ " Open a link tag
+ normal! i<a href="">
+ " Paste the URL into the quotes
+ normal! hP
+ " Move to the end of the link text URL
normal! E
- execute "normal! a</a>\<Esc>"
+ " Close the link tag
+ normal! a</a>
+
endfunction
-nnoremap <silent> <LocalLeader>r :<C-U>call <SID>UrlLink()<CR>
+nnoremap <buffer> <silent> <LocalLeader>r
+ \ :<C-U>call <SID>UrlLink()<CR>
diff --git a/vim/ftplugin/perl.vim b/vim/ftplugin/perl.vim
index 53341183..2ea4676b 100644
--- a/vim/ftplugin/perl.vim
+++ b/vim/ftplugin/perl.vim
@@ -1,6 +1,11 @@
-" Run perl -c on file for the current buffer
-nnoremap <LocalLeader>pc :exe "!perl -c " . shellescape(expand("%"))<CR>
-" Run perlcritic on the file for the current buffer
-nnoremap <LocalLeader>pl :exe "!perlcritic " . shellescape(expand("%"))<CR>
-" Run the current buffer through perltidy
-nnoremap <LocalLeader>pt :%!perltidy<CR>
+" Run `perl -c` over buffer
+nnoremap <buffer> <silent> <LocalLeader>c
+ \ :write !perl -c<CR>
+
+" Run `perlcritic` over buffer
+nnoremap <buffer> <silent> <LocalLeader>l
+ \ :write !perlcritic<CR>
+
+" Filter buffer through `perltidy`
+nnoremap <buffer> <silent> <LocalLeader>t
+ \ :%!perltidy<CR>
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index a6dd62eb..c09e4fe8 100644
--- a/vim/ftplugin/sh.vim
+++ b/vim/ftplugin/sh.vim
@@ -24,3 +24,25 @@ endif
if exists('b:is_bash') && executable('han')
setlocal keywordprg=han
endif
+
+" Map checker based on shell family
+if exists('b:is_bash') && b:is_bash
+ let b:check = 'bash -n'
+elseif exists('b:is_ksh') && b:is_ksh
+ let b:check = 'ksh -n'
+else
+ let b:check = 'sh -n'
+endif
+nnoremap <buffer> <silent> <LocalLeader>c
+ \ :<C-U>execute ':write !' . b:check<CR>
+
+" Map linter based on shell family
+if exists('b:is_bash') && b:is_bash
+ let b:lint = 'shellcheck -s bash -'
+elseif exists('b:is_ksh') && b:is_ksh
+ let b:lint = 'shellcheck -s ksh -'
+else
+ let b:lint = 'shellcheck -s sh -'
+endif
+nnoremap <buffer> <silent> <LocalLeader>l
+ \ :<C-U>execute ':write !' . b:lint<CR>
diff --git a/vim/ftplugin/vim.vim b/vim/ftplugin/vim.vim
new file mode 100644
index 00000000..e023553e
--- /dev/null
+++ b/vim/ftplugin/vim.vim
@@ -0,0 +1,5 @@
+" Run `vint` over buffer
+" /dev/stdin is not optimal here; it's widely implemented, but not POSIX.
+" `vint` does not seem to have another way to parse standard input.
+nnoremap <buffer> <silent> <LocalLeader>l
+ \ :write !vint -s /dev/stdin<CR>