5

Every time I type an email with mutt, it inserts these line breaks every 70 characters or so. I'd rather it just relied on word wrap instead, since my editing style (lots of revision) makes reformatting a pain. Is there a way to set this up in muttrc?

Jonathan
  • 7,470

4 Answers4

8

You can set the editor option in your .muttrc option and include command line options. The command line options can set vim settings. An example would be:

set editor="vim +':set textwidth=0' +':set wrapmargin=0' +':set wrap'"

or

# use vim, tell it to set cursor on first line of body
set editor="vim -c 'set expandtab textwidth=65 | normal }j'"

And so on and so forth. See the vim man page for many more options.

Hamish Downer
  • 19,506
2

Another approach is to specify an extra source file just for mutt with vim's -S cli flag:

Here is the value of editor in my .muttrc:

set editor="vim -S ~/.mutt/vimrc"

And then here is my ~/.mutt/vimrc:

set textwidth=0
set wrapmargin=0
eupharis
  • 121
0

With after/ftplugin/mail.vim

Using Hamish Downer's solution for a long time in Neovim, I noticed today that the text width gets reset after opening a buffer (another file where I keep email addresses, in my case) in the same window.

I think the reason is that the default file type plugin at /usr/share/nvim/runtime/ftplugin/mail.vim is loaded, which sets the text width to 72:

" Part of /usr/share/nvim/runtime/ftplugin/mail.vim

" many people recommend keeping e-mail messages 72 chars wide if &tw == 0 setlocal tw=72 endif

To solve this, I removed the line set editor="vim +':set textwidth=0' +':set wrapmargin=0' +':set wrap'" from my muttrc and instead created a custom file type plugin at ~/.config/nvim/after/ftplugin/mail.vim consisting only of this line:

setlocal textwidth=0

Generally, the files in after/ftplugin/ are sourced after the configurations in /usr/share/nvim/runtime/fpgplugin, effectively overriding them.

I find this also a bit cleaner than the set editor= method and it has the upshot that Neovim will use this config for all files of type mail. This makes for consistent settings when writing mails with other clients than Mutt.

Also, I can now have the configuration on multiple lines and add comments:

" Contents of ~/.config/nvim/after/ftplugin/mail.vim

setlocal textwidth=0 " Jump over first paragraph (useful when muttrc contains set edit_headers) normal! }

0

Try settings the textwidth to 0:

; ~/.vimrc
:set textwidth=0
:set wrapmargin=0