2

I would like to wrap email text to 72 characters using a command-line program (so that reformatting can be integrated with vim). Quotes using > need to be handled nicely.

Lines longer than 72 characters should be wrapped, as well as those shorter than 72 characters and ending with a space. Lines not ending with a space should be left alone so that you can write something like

Best wishes,
Greg

(with no space after Best wishes,) without it being wrapped into a single line.

Where lines are wrapped, a trailing space should be left at the end so that when the email is sent using the format=flowed Content-Type header it's displayed correctly by an email client.

Here's some example text:

This is an example text file that I would like to reformat using par. I would like this paragraph wrapped to 72 characters because at the moment it's just one long line of text.

> This paragraph should also be wrapped 
> to 72 characters because each line 
> except the last ends with a space. 
> The quotes should be handled nicely.

These lines shouldn't be wrapped
because they are shorter than 72 chars
and don't have any trailing spaces.

par w72q (output below) gets close, but doesn't leave trailing spaces at the end of lines and does wrap the lines with no trailing space:

This is an example text file that I would like to reformat using par. I
would like this paragraph wrapped to 72 characters because at the moment
it's just one long line of text.

> This paragraph should also be wrapped to 72 characters because each
> line except the last ends with a space. The quotes should be handled
> nicely.

These lines shouldn't be wrapped because they are shorter than 72 chars
and don't have any trailing spaces.
2

Vim actually handles this well without resorting to another program. The following options are useful:

setlocal comments=n:>
setlocal formatoptions+=aw
setlocal textwidth=72

See :help format-comments and :help fo-table for more info.

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.