Question

I'm currently using VIM to write emails for Mutt, it works great, but the word wrapping is driving me crazy. I currently set word wrapping when I call it from the muttrc file like so:

-c 'set fo+=aw' -c 'set tw=76'

This works perfectly, just what I was looking for. The problem is I also use headers in mutt so that when I'm writing an email the headers are first in my writer:

From: Name <me@me.com>
To: 
Cc: 
Bcc: 
Subject: 
Reply-To: 

Message here

The problem is that VIM is now wrapping everything, including the headers. When I go up to the Subject line if I haven't input a CC and BCC is wraps like so:

Cc: Bcc: Subject:

So I'm looking for a way to stop it from wrapping anything before the first empty line of the editor? Any ideas?

Was it helpful?

Solution

First, you don't need to explicit set your setting in your .muttrc, since Vim recognized mutt mails automatically and to set your settings for specifically writing mails with Vim, you simply create a file $HOME/.vim/ftplugin/mail.vim (create directories, if they don't exists) and put your seetings there:

setl tw=76
setl fo+=aw

You need to, however explicitly enable filetype plugins in Vim, to enable this, e.g. your .vimrc needs to contain filetype plugin on or similar.

For making sure, that those formatoptions are only considered, when writing the body of the mail (as I have set edit_headers on in mutt), I have written an autocommand, that specifically checks the region you are in and applies certain settings, if you are in the header or in a patch or in the signature region,...

I have written about this in more detail here. You might also be interested in the other settings at that page.

OTHER TIPS

Two ideas: With built-in features, you can try :set fo+=w additionally. Then, trailing whitespace indicates a paragraph continues. If you leave off the trailing space in the header, but add it elsewhere (in the email body), that might work.

Alternatively, there are plugins that can run actions depending on where you are in the buffer. The hookcursormoved plugin has a linechanged condition, where you could :set fo-=a in the first (header) lines and :set fo+=a elsehere. Or have a look at my OnSyntaxChange plugin, which can do this depending on the syntax group. But, for that particular use, you could also code this yourself, basically with an

:autocmd CursorMoved,CursorMovedI * if line('.') < 8 | set fo-=a | else | set fo+=a | endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top