diff options
-rw-r--r-- | vim/after/ftplugin/mail.vim | 5 | ||||
-rw-r--r-- | vim/autoload/mail.vim | 20 |
2 files changed, 25 insertions, 0 deletions
diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim index 3aa3fec3..df0f043d 100644 --- a/vim/after/ftplugin/mail.vim +++ b/vim/after/ftplugin/mail.vim @@ -83,3 +83,8 @@ let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>[' \ . '|ounmap <buffer> <LocalLeader>]' \ . '|xunmap <buffer> <LocalLeader>[' \ . '|xunmap <buffer> <LocalLeader>]' + +" Quick map to strip multiple blank lines in the entire buffer; this comes up +" a lot when replying to stripped HTML mail +nnoremap <buffer> <silent> <LocalLeader>x + \ :<C-U>call mail#ContractMultipleBlankLines()<CR> diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim index baff4bbf..0c3b7eb7 100644 --- a/vim/autoload/mail.vim +++ b/vim/autoload/mail.vim @@ -65,3 +65,23 @@ function! mail#NewBlank(count, up, visual) abort endif endfunction + +" Quick map to strip multiple blank lines in the entire buffer; this comes up +" a lot when replying to stripped HTML mail. This should really be a command, +" but I'll do that Later(TM). +function! mail#ContractMultipleBlankLines() abort + let l:deletions = [] + let l:blank = 0 + for l:num in range(1, line('$')) + if strlen(getline(l:num)) > 0 + let l:blank = 0 + elseif l:blank + let l:deletions += [l:num] + else + let l:blank = 1 + endif + endfor + for l:num in reverse(l:deletions) + execute l:num . 'delete' + endfor +endfunction |