Wikia

Vim Tips Wiki

Changes: Fix email quotations with long lines

Edit

Back to page

(change "anon" author to blank; trim "created" date; minor manual clean)
(Change <tt> to <code>, perhaps also minor tweak.)
Line 3: Line 3:
 
|id=273
 
|id=273
 
|previous=272
 
|previous=272
|next=275
+
|next=277
 
|created=2002
 
|created=2002
 
|complexity=basic
 
|complexity=basic
Line 25: Line 25:
   
 
==Comments==
 
==Comments==
You can also simply use the <tt>{</tt> and <tt>}</tt> paragraph motions in conjunction with <tt>gq</tt>. For example, move to the top of a paragraph using <tt>{</tt>, then hit <tt>gq}</tt> to reformat it.
+
You can also simply use the <code>{</code> and <code>}</code> paragraph motions in conjunction with <code>gq</code>. For example, move to the top of a paragraph using <code>{</code>, then hit <code>gq}</code> to reformat it.
   
 
----
 
----
Like just about everything else, <tt>gq</tt> will take any motion command. I find myself stepping through mails and random files with <tt>:set tw=72</tt> or whatnot and <tt>gqj</tt> and <tt>J</tt> and occasionally inserting stray <tt>></tt> characters.
+
Like just about everything else, <code>gq</code> will take any motion command. I find myself stepping through mails and random files with <code>:set tw=72</code> or whatnot and <code>gqj</code> and <code>J</code> and occasionally inserting stray <code>></code> characters.
   
 
----
 
----

Revision as of 07:49, July 11, 2012

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.


Around Wikia's network

Random Wiki