diff options
Diffstat (limited to 'vim')
-rw-r--r-- | vim/after/ftplugin/diff.vim | 9 | ||||
-rw-r--r-- | vim/after/ftplugin/gitcommit.vim | 24 | ||||
-rw-r--r-- | vim/after/ftplugin/mail.vim | 113 | ||||
-rw-r--r-- | vim/after/ftplugin/markdown.vim | 24 | ||||
-rw-r--r-- | vim/after/ftplugin/perl.vim | 61 | ||||
-rw-r--r-- | vim/after/syntax/sh.vim | 7 | ||||
-rw-r--r-- | vim/autoload/mail.vim | 58 | ||||
-rw-r--r-- | vim/autoload/perl.vim | 58 |
8 files changed, 193 insertions, 161 deletions
diff --git a/vim/after/ftplugin/diff.vim b/vim/after/ftplugin/diff.vim index 109b5b49..eecc8b8c 100644 --- a/vim/after/ftplugin/diff.vim +++ b/vim/after/ftplugin/diff.vim @@ -15,9 +15,12 @@ let b:undo_ftplugin .= '|nunmap <buffer> {' \ . '|nunmap <buffer> }' " Set mappings -nmap <buffer> <LocalLeader>p <Plug>(DiffPrune) -xmap <buffer> <LocalLeader>p <Plug>(DiffPrune) -nmap <buffer> <LocalLeader>pp <Plug>(DiffPrune)_ +nmap <buffer> <LocalLeader>p + \ <Plug>(DiffPrune) +xmap <buffer> <LocalLeader>p + \ <Plug>(DiffPrune) +nmap <buffer> <LocalLeader>pp + \ <Plug>(DiffPrune)_ let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>p' \ . '|xunmap <buffer> <LocalLeader>p' \ . '|nunmap <buffer> <LocalLeader>pp' diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim index 5699188d..c9b14b6b 100644 --- a/vim/after/ftplugin/gitcommit.vim +++ b/vim/after/ftplugin/gitcommit.vim @@ -23,16 +23,24 @@ if exists('g:no_plugin_maps') || exists('g:no_gitcommit_maps') finish endif -" Mail quote mappings -nnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>qq quote#Quote().'_' -xnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() -nnoremap <buffer> <expr> <LocalLeader>QQ quote#QuoteReformat().'_' -xnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() +" Quote operator +nnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() +nnoremap <buffer> <expr> <LocalLeader>qq + \ quote#Quote().'_' +xnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' \ . '|nunmap <buffer> <LocalLeader>qq' \ . '|xunmap <buffer> <LocalLeader>q' - \ . '|nunmap <buffer> <LocalLeader>Q' + +" Quote operator with reformatting +nnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +nnoremap <buffer> <expr> <LocalLeader>QQ + \ quote#QuoteReformat().'_' +xnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q' \ . '|nunmap <buffer> <LocalLeader>QQ' \ . '|xunmap <buffer> <LocalLeader>Q' diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim index a30b155a..c3353cc7 100644 --- a/vim/after/ftplugin/mail.vim +++ b/vim/after/ftplugin/mail.vim @@ -12,12 +12,12 @@ if line('.') == 1 && col('.') == 1 call search('\m^>', 'c') " Check this line to see if it's a generic hello-name greeting that we can - " just strip out; delete the following line too, if it's blank - if getline('.') =~? '^>\s*\%(<hello\|hi\)\s\+\S\+\s*$' + " just strip out; delete any following lines too, if they're blank + if getline('.') =~? '^>\s*\%(<hello\|hey\+\|hi\)\s\+\S\+\s*$' delete - if getline('.') =~# '^>$' + while getline('.') =~# '^>$' delete - endif + endwhile endif " Now move to the first quoted or unquoted blank line @@ -34,97 +34,46 @@ if exists('g:no_plugin_maps') || exists('g:no_mail_maps') finish endif -" The quote mapping in the stock plugin is a good idea, but I prefer it to -" work as a motion rather than quoting to the end of the buffer -nnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>qq quote#Quote().'_' -xnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() -nnoremap <buffer> <expr> <LocalLeader>QQ quote#QuoteReformat().'_' -xnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() +" Flag a message as unimportant +nnoremap <buffer> <LocalLeader>l + \ <C-U>:call mail#FlagUnimportant()<CR> +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>l' + +" Quote operator +nnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() +nnoremap <buffer> <expr> <LocalLeader>qq + \ quote#Quote().'_' +xnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' \ . '|nunmap <buffer> <LocalLeader>qq' \ . '|xunmap <buffer> <LocalLeader>q' - \ . '|nunmap <buffer> <LocalLeader>Q' + +" Quote operator with reformatting +nnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +nnoremap <buffer> <expr> <LocalLeader>QQ + \ quote#QuoteReformat().'_' +xnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q' \ . '|nunmap <buffer> <LocalLeader>QQ' \ . '|xunmap <buffer> <LocalLeader>Q' -" Flag a message as unimportant -function! s:FlagUnimportant() - call cursor(1, 1) - call search('^$') - - - call append(line('.'), 'X-Priority: 5') - call append(line('.'), 'Importance: Low') -endfunction -nnoremap <buffer> - \ <LocalLeader>l - \ <C-U>:call <SID>FlagUnimportant()<CR> -let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>l' - -" Move through quoted paragraphs like normal-mode `{` and `}` -function! s:NewBlank(count, up, visual) abort - - " Reselect visual selection - if a:visual - normal! gv - endif - - " Flag for whether we've started a block - let l:block = 0 - - " Flag for the number of blocks passed - let l:blocks = 0 - - " Iterate through buffer lines - let l:num = line('.') - while a:up ? l:num > 1 : l:num < line('$') - - " If the line is blank - if getline(l:num) =~# '^[ >]*$' - - " If we'd moved through a non-blank block already, reset that flag and - " bump up the block count - if l:block - let l:block = 0 - let l:blocks += 1 - endif - - " If we've hit the number of blocks, end the loop - if l:blocks == a:count - break - endif - - " If the line is not blank, flag that we're going through a block - else - let l:block = 1 - endif - - " Move the line number or up or down depending on direction - let l:num += a:up ? -1 : 1 - - endwhile - - " Move to line if nonzero and not equal to the current line - if l:num != line('.') - execute 'normal '.l:num.'G' - endif - -endfunction - " Maps using NewBlank() function above for quoted paragraph movement nnoremap <buffer> <silent> <LocalLeader>[ - \ :<C-U>call <SID>NewBlank(v:count1, 1, 0)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 1, 0)<CR> nnoremap <buffer> <silent> <LocalLeader>] - \ :<C-U>call <SID>NewBlank(v:count1, 0, 0)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 0, 0)<CR> onoremap <buffer> <silent> <LocalLeader>[ - \ :<C-U>call <SID>NewBlank(v:count1, 1, 0)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 1, 0)<CR> onoremap <buffer> <silent> <LocalLeader>] - \ :<C-U>call <SID>NewBlank(v:count1, 0, 0)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 0, 0)<CR> xnoremap <buffer> <silent> <LocalLeader>[ - \ :<C-U>call <SID>NewBlank(v:count1, 1, 1)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 1, 1)<CR> xnoremap <buffer> <silent> <LocalLeader>] - \ :<C-U>call <SID>NewBlank(v:count1, 0, 1)<CR> + \ :<C-U>call mail#NewBlank(v:count1, 0, 1)<CR> let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>[' \ . '|nunmap <buffer> <LocalLeader>]' \ . '|ounmap <buffer> <LocalLeader>[' diff --git a/vim/after/ftplugin/markdown.vim b/vim/after/ftplugin/markdown.vim index a5c80ca9..cd8873b9 100644 --- a/vim/after/ftplugin/markdown.vim +++ b/vim/after/ftplugin/markdown.vim @@ -26,16 +26,24 @@ if exists('g:no_plugin_maps') || exists('g:no_markdown_maps') finish endif -" Mail quote mappings -nnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>qq quote#Quote().'_' -xnoremap <buffer> <expr> <LocalLeader>q quote#Quote() -nnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() -nnoremap <buffer> <expr> <LocalLeader>QQ quote#QuoteReformat().'_' -xnoremap <buffer> <expr> <LocalLeader>Q quote#QuoteReformat() +" Quote operator +nnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() +nnoremap <buffer> <expr> <LocalLeader>qq + \ quote#Quote().'_' +xnoremap <buffer> <expr> <LocalLeader>q + \ quote#Quote() let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' \ . '|nunmap <buffer> <LocalLeader>qq' \ . '|xunmap <buffer> <LocalLeader>q' - \ . '|nunmap <buffer> <LocalLeader>Q' + +" Quote operator with reformatting +nnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +nnoremap <buffer> <expr> <LocalLeader>QQ + \ quote#QuoteReformat().'_' +xnoremap <buffer> <expr> <LocalLeader>Q + \ quote#QuoteReformat() +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>Q' \ . '|nunmap <buffer> <LocalLeader>QQ' \ . '|xunmap <buffer> <LocalLeader>Q' diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim index 9c3ce6f6..ee8da2a7 100644 --- a/vim/after/ftplugin/perl.vim +++ b/vim/after/ftplugin/perl.vim @@ -13,65 +13,6 @@ let b:undo_ftplugin .= '|unlet b:current_compiler' setlocal matchpairs+=<:> let b:undo_ftplugin .= '|setlocal matchpairs<' -" Function to add boilerplate intelligently -function! s:Boilerplate() abort - - " Flag whether the buffer started blank - let l:blank = line2byte(line('$') + 1) <= 2 - - " This is a .pm file, guess its package name from path - if expand('%:e') ==# 'pm' - - let l:match = matchlist(expand('%:p'), '.*/lib/\(.\+\).pm$') - if len(l:match) - let l:package = substitute(l:match[1], '/', '::', 'g') - else - let l:package = expand('%:t:r') - endif - - " Otherwise, just use 'main' - else - let l:package = 'main' - endif - - " Lines always to add - let l:lines = [ - \ 'package '.l:package.';', - \ '', - \ 'use strict;', - \ 'use warnings;', - \ 'use utf8;', - \ '', - \ 'use 5.006;', - \ '', - \ 'our $VERSION = ''0.01'';', - \ '' - \ ] - - " Conditional lines depending on package - if l:package ==# 'main' - let l:lines = ['#!perl'] + l:lines - else - let l:lines = l:lines + ['', '1;'] - endif - - " Add all the lines in the array - for l:line in l:lines - call append(line('.') - 1, l:line) - endfor - - " If we started in a completely empty buffer, delete the current blank line - if l:blank - delete - endif - - " If we added a trailing '1' for a package, move the cursor up two lines - if l:package !=# 'main' - -2 - endif - -endfunction - " Stop here if the user doesn't want ftplugin mappings if exists('g:no_plugin_maps') || exists('g:no_perl_maps') finish @@ -79,7 +20,7 @@ endif " Add boilerplate intelligently nnoremap <buffer> <silent> <LocalLeader>b - \ :<C-U>call <SID>Boilerplate()<CR> + \ :<C-U>call perl#Boilerplate()<CR> let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>b' " Mappings to choose compiler diff --git a/vim/after/syntax/sh.vim b/vim/after/syntax/sh.vim index 00f95fc0..977ee2cb 100644 --- a/vim/after/syntax/sh.vim +++ b/vim/after/syntax/sh.vim @@ -4,6 +4,13 @@ if &compatible || v:version < 700 finish endif +" Remove g:is_posix if we resorted to it in order to get correct POSIX sh +" highlighting with older Vim runtime files +if exists('g:is_posix') + \ && (v:version < 800 || v:version == 800 && !has('patch257')) + unlet g:is_posix +endif + " If we know we have another shell type, clear away the others completely, now " that core syntax/sh.vim is done prodding /bin/sh to determine the system " shell type (which I don't care about). diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim new file mode 100644 index 00000000..6bec6e55 --- /dev/null +++ b/vim/autoload/mail.vim @@ -0,0 +1,58 @@ +" Flag a message as unimportant +function! mail#FlagUnimportant() abort + call cursor(1, 1) + call search('^$') + - + call append(line('.'), 'X-Priority: 5') + call append(line('.'), 'Importance: Low') +endfunction + +" Move through quoted paragraphs like normal-mode `{` and `}` +function! mail#NewBlank(count, up, visual) abort + + " Reselect visual selection + if a:visual + normal! gv + endif + + " Flag for whether we've started a block + let l:block = 0 + + " Flag for the number of blocks passed + let l:blocks = 0 + + " Iterate through buffer lines + let l:num = line('.') + while a:up ? l:num > 1 : l:num < line('$') + + " If the line is blank + if getline(l:num) =~# '^[ >]*$' + + " If we'd moved through a non-blank block already, reset that flag and + " bump up the block count + if l:block + let l:block = 0 + let l:blocks += 1 + endif + + " If we've hit the number of blocks, end the loop + if l:blocks == a:count + break + endif + + " If the line is not blank, flag that we're going through a block + else + let l:block = 1 + endif + + " Move the line number or up or down depending on direction + let l:num += a:up ? -1 : 1 + + endwhile + + " Move to line if nonzero and not equal to the current line + if l:num != line('.') + execute 'normal '.l:num.'G' + endif + +endfunction diff --git a/vim/autoload/perl.vim b/vim/autoload/perl.vim new file mode 100644 index 00000000..3b87bb36 --- /dev/null +++ b/vim/autoload/perl.vim @@ -0,0 +1,58 @@ +" Function to add boilerplate intelligently +function! perl#Boilerplate() abort + + " Flag whether the buffer started blank + let l:blank = line2byte(line('$') + 1) <= 2 + + " This is a .pm file, guess its package name from path + if expand('%:e') ==# 'pm' + + let l:match = matchlist(expand('%:p'), '.*/lib/\(.\+\).pm$') + if len(l:match) + let l:package = substitute(l:match[1], '/', '::', 'g') + else + let l:package = expand('%:t:r') + endif + + " Otherwise, just use 'main' + else + let l:package = 'main' + endif + + " Lines always to add + let l:lines = [ + \ 'package '.l:package.';', + \ '', + \ 'use strict;', + \ 'use warnings;', + \ 'use utf8;', + \ '', + \ 'use 5.006;', + \ '', + \ 'our $VERSION = ''0.01'';', + \ '' + \ ] + + " Conditional lines depending on package + if l:package ==# 'main' + let l:lines = ['#!perl'] + l:lines + else + let l:lines = l:lines + ['', '1;'] + endif + + " Add all the lines in the array + for l:line in l:lines + call append(line('.') - 1, l:line) + endfor + + " If we started in a completely empty buffer, delete the current blank line + if l:blank + delete + endif + + " If we added a trailing '1' for a package, move the cursor up two lines + if l:package !=# 'main' + -2 + endif + +endfunction |