Wikia

Vim Tips Wiki

Fix email quotations with long lines

Talk0
1,610pages on
this wiki
Revision as of 02:58, December 4, 2009 by JohnBot (Talk | contribs)

Tip 273 Printable Monobook Previous Next

created 2002 · complexity basic · version 5.7


When using Vim as your editor of choice, even for email processing - as I do - it is often unpleasing how some MUAs quote the email body produced by mailers such as Outlook. The lines often span across multiple visual lines and it's difficult to reply on certain parts of it.

With Vim, you can quickly fix those quotations to maintain a proper 75 char break. For example, when using Mutt, put this line in your .muttrc, or use a custom .vimrc_mail for it:

set editor="vim -c 'set fo=tcrq' -c 'set tw=76'"

For other MUAs this has to be fitted. However, now, when your quoted email is displayed, you can use this Vim sequence to fix it:

  • Move cursor to first line of broken paragraph.
  • Press 'V' and move to the last line of the paragraph you want to fix.
  • Press 'g' and then 'q'. The marked text will wrap around to your specified textwidth (76 in our case) and the quotations will be preserved across the lines.

Comments

You can also simply use the { and } paragraph motions in conjunction with gq. For example, move to the top of a paragraph using {, then hit gq} to reformat it.


Like just about everything else, gq will take any motion command. I find myself stepping through mails and random files with :set tw=72 or whatnot and gqj and J and occasionally inserting stray > characters.


The comments setting must contain the quoting character (usually '>'). So with

set comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-

everything works as described.


See also Brian Medley's email ftplugin that does a very nice job on this issue.


Advertisement | Your ad here

Around Wikia's network

Random Wiki