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?

1
  • 1
    gq is your friend. I have a keybinding to do vipgq which reformats the current paragraph according to the correct word wrap length.
    – jsve
    Mar 22 '21 at 23:03
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.

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
0

Try settings the textwidth to 0:

; ~/.vimrc
:set textwidth=0
:set wrapmargin=0
2
  • I have no problem changing the settings in vim, but it's mutt's default vim settings that I can't set.
    – Jonathan
    Oct 13 '11 at 17:34
  • Hmm, since I do not use mutt, I cannot help you more than this I guess :-( Oct 14 '11 at 14:18
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! }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.