message-mode for VIM? (or Composing Email in VIM)

2

1

Emacs has something called message-mode (type M-x message-mail) that can be used to compose emails. This mode helps one to automatically wrap text to 72 columns .. keeping quoted marks properly.

Is there such a thing for VIM?

I am switching from Emacs to VIM and message-mode is the only thing that needs to be migrated.

NOTE: I don't want VIM to send emails; for that .. I use some other client. I only want to edit emails in VIM.

Sridhar Ratnakumar

Posted 2009-10-21T11:26:05.523

Reputation: 4 041

Answers

5

Yes. Vim implements message-mode using filetypes.

Vim should be able to autodetect that you're editing a mail message. It should automatically set the filetype to mail. You can check this by displaying the current value of filetype by typing (in command mode) ...

:set filetype

You can also force Vim to use a particular filetype. In command mode, type ...

:set filetype=mail

to force Vim to set the default editing preferences for mail messages.

You can read more about filetypes in the Vim help system.

:help filetype

Convict

Posted 2009-10-21T11:26:05.523

Reputation: 694

There's the following code in ftplugin/mail.vim: if &tw == 0 ; setlocal tw=72; endif - which should set this up properly. – blueyed – 2011-02-02T10:24:17.927

html documentation at vim.org: http://www.vim.org/htmldoc/filetype.html (may not be up-to-date for v7.x)

– quack quixote – 2009-10-21T12:07:30.243

But it does not automatically wrap long lines to fit the 72 cols. – Sridhar Ratnakumar – 2009-10-21T12:14:33.083

What is the value of 'textwidth'? The default setting for mail is 72 which should cause your text to wrap near column 72. Also check the value of 'warpmargin'. – Convict – 2009-10-22T10:00:45.780

I had to use gq to autowrap the text. – Sridhar Ratnakumar – 2009-11-12T22:17:39.270

4

I like to run vim (vim7) as:

vim -c "set spell spelllang=en" -c "set tw=72" -c "set filetype=mail"

this turns on the built-in spell checker, line wrapping on word boundaries at 72 characters and file syntax highlighting as email.

user23118

Posted 2009-10-21T11:26:05.523

Reputation:

0

You want this command:

:set wrapmargin=8

Assuming that your window is set for 80 characters wide. This sets the wrap margin 8 characters from the right hand side, which gives you a width of 72.

You can abbreviate wrapmargin to wm

You may also want to check the email category at this wiki about VIM

Michael Dillon

Posted 2009-10-21T11:26:05.523

Reputation: 899

It makes more sense to use :set textwidth=72 (tw) instead, doesn't it? – blueyed – 2011-02-02T10:08:26.427