created June 8, 2005 · complexity intermediate · author Kyle Wheeler · version 5.7
I frequently get email from people who do not use format-flowed email properly. I prefer to send out "correct" email, including the stuff I'm quoting, and Vim helps me do that. I added this function to my vimrc, and now I use it when editing mail by simply typing:
:call FixFlowed()
That's easier to type, because I really type :call F<tab>
Here's the function:
function! Fixflowed() " save cursor position let pos = getpos(".")[1:] " add spaces to the end of every line silent! %s/\([^]> :]\)\ze\n>[> ]*[^> ]/\1 /g " remove extraneous spaces silent! %s/ \+\ze\n[> ]*$// " make sure there's only ONE space at the end of each line silent! %s/ \{2,}$/ / " fix the wockas spacing from the text silent! %s/^[> ]*>\ze[^> ]/& / " compress the wockas while search('^>\+ >', 'w') > 0 s/^>\+\zs >/>/ endwhile " restore the original cursor location call cursor(pos) endfunction
It's a little sensitive because it blows away ascii art, and it also doesn't automatically reflow paragraphs (I have no idea how to do that properly). Hope it helps someone.
Comments
PAR is a lot better at this kind of thing: http://www.nicemice.net/par/
PAR is a useful tool, but is not specific to format=flowed, and so can be over-zealous in some cases. For example, it doesn't recognized the -- separator between email body and signature, and wraps it into the signature.