5

Problem summary

I use vim to edit emails that I send with mutt. I also use format=flowed, which "reflows" text. That is, lines are limited to a fixed number of characters, and a "soft wrap" is applied, as indicated by the presence of a trailing space.

In vim, I have the following set:

setl tw=72
setl fo=aw

This sets the line length to 72 charaters, and sets up autoformatting with the trailing space. This works well in general. However, if I attempt to quote something with >, this character is not treated as a special character, and will be considered "inline" to the text.

Example

Copy the following text and paste it into vim.

Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing nullam nec gravida non, at posuere enim, consectetuer ve. [1]

vim correctly breaks it into two lines, the first with a trailing space.

Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing nullam 
nec gravida non, at posuere enim, consectetuer ve. [1]

I add > by selecting the lines and using :'<,'>s/^/> /, which results in the following.

> Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing nullam 
> nec gravida non, at posuere enim, consectetuer ve. [1]

However, I now want to remove the [1] from the end, so I navigate to the end and delete. vim now reflows to the following, with the > "inline".

> Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing 
nullam > nec gravida non, at posuere enim, consectetuer ve.

What's even worse is that I can delete the > manually and insert a new > before nullam, but this will immediately be reflowed to the previous line as follows.

> Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing > 
nullam nec gravida non, at posuere enim, consectetuer ve.

Question

Is there a way to make vim's flowing aware of >? FWIW I've also tried this mail.vim customised for format=flowed, but it suffers from the same problems.

1
  • For the note, you can do it manually using gqap in normal mode. I actually prefer to do it manually than having to fight it
    – zmo
    Commented Mar 5, 2016 at 11:16

2 Answers 2

6

From one of my previous answers, you can get this to work if:

  1. You have nb:> in your comments setting.
  2. And you have q in your formatoptions setting.

So:

setlocal comments+=nb:>
setlocal fo+=q

After doing these, I get the expected wrapping:

> Tempus. Vivamus. Dis natoque vitae erat. Consectetuer adipiscing 
> nullam nec gravida non, at posuere enim, consectetuer ve.
4
  • 1
    Thanks! That works well. However, wouldn't setlocal make more sense? Also, could you please explain set fo+=q? I looked in the help and it said q was Allow formatting of comments with "gq"…, which seemed to suggest it wouldn't alter the automatic formatting.
    – Sparhawk
    Commented Mar 5, 2016 at 12:43
  • @Sparhawk setlocal would be better yes, these were commands I manually entered, so I just went with set. I don't know why q affects this, but it does, and has done so for some time now, as the trail of links shows. :/
    – muru
    Commented Mar 5, 2016 at 12:47
  • Okay, thanks for the explanation. I'll accept this answer because it's minimal and hence easier to follow the help.
    – Sparhawk
    Commented Mar 5, 2016 at 12:55
  • Just noting that the b in nb:> is unnecessary to get the desired effect, and, off the top of my head, might not be desired for format=flowed (because > > text means something different from >> text in f=f.)
    – Rich
    Commented Nov 28, 2017 at 17:33
2

setlocal formatoptions=jawtcqln worked for me. I'd put it in ~/.vim/ftplugin/mail.vim.

2
  • 3
    That's half of the formatoptions strings right there. Can you explain which particular combination of these solves this problem?
    – muru
    Commented Mar 5, 2016 at 10:13
  • 1
    Thank you, that works. FWIW the q option is key here. i.e. in combination, the minimum that works for me is setl fo=awq.
    – Sparhawk
    Commented Mar 5, 2016 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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