diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 01:02:42 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-04 01:02:42 +1300 |
commit | 36e3e01c088f1b59c7d4de953544748ff255d80e (patch) | |
tree | 94d6ce9b81493e5567adedcc7910879a9d2da9bc | |
parent | Merge branch 'feature/local-leader' into develop (diff) | |
parent | Update documentation to reflect ftplugin changes (diff) | |
download | dotfiles-36e3e01c088f1b59c7d4de953544748ff255d80e.tar.gz dotfiles-36e3e01c088f1b59c7d4de953544748ff255d80e.zip |
Merge branch 'feature/review-ftplugin' into develop
* feature/review-ftplugin:
Update documentation to reflect ftplugin changes
Add lint mapping for Vimscript
Specify scope of mapleader variables
Use underscore as local map leader
Add check and lint mappings for shell script
Add tidy mapping for HTML
Break long lines in check/lint/tidy mappings
Make all lint/check/tidy maps local and silent
Improve comments on check/lint/tidy maps
Use long form options for tidy(1) Vim call
Use direct :write !cmd instead of shellescape()
Use full ':execute' not just ':exe' in VimL
Check for availability of Vim shellescape()
Revert "Adjust UrlLink() to yank word without t...
Adjust UrlLink() to yank word without text objects
Refactor UrlLink() function normal! commands
Use single quotes for HTML link mapping :execute
Refactor HTML tidy(1) mapping
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | vim/config/leader.vim | 3 | ||||
-rw-r--r-- | vim/ftplugin/html.vim | 24 | ||||
-rw-r--r-- | vim/ftplugin/perl.vim | 17 | ||||
-rw-r--r-- | vim/ftplugin/sh.vim | 22 | ||||
-rw-r--r-- | vim/ftplugin/vim.vim | 5 |
6 files changed, 66 insertions, 13 deletions
@@ -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> |