This also works inside comments, ignoring the comment leader.
*fo-v*
v Vi-compatible auto-wrapping in insert mode: Only break a line at a
blank that you have entered during the current insert command. (Note:
this is not 100% Vi compatible. Vi has some "unexpected features" or
bugs in this area. It uses the screen column instead of the line
column.)
*fo-b*
b Like 'v', but only auto-wrap if you enter a blank at or before
the wrap margin. If the line was longer than 'textwidth' when you
started the insert, or you do not enter a blank in the insert before
reaching 'textwidth', Vim does not perform auto-wrapping.
*fo-l*
l Long lines are not broken in insert mode: When a line was longer than
'textwidth' when the insert command started, Vim does not
automatically format it.
*fo-m*
m Also break at a multibyte character above 255. This is useful for
Asian text where every character is a word on its own.
*fo-M*
M When joining lines, don't insert a space before or after a multibyte
character. Overrules the 'B' flag.
*fo-B*
B When joining lines, don't insert a space between two multibyte
characters. Overruled by the 'M' flag.
*fo-1*
1 Don't break a line after a one-letter word. It's broken before it
instead (if possible).
*fo-]*
] Respect 'textwidth' rigorously. With this flag set, no line can be
longer than 'textwidth', unless line-break-prohibition rules make this
impossible. Mainly for CJK scripts and works only if 'encoding' is
"utf-8".
*fo-j*
j Where it makes sense, remove a comment leader when joining lines. For
example, joining:
int i; // the index ~
// in the list ~
Becomes:
int i; // the index in the list ~
*fo-p*
p Don't break lines at single spaces that follow periods. This is
intended to complement 'joinspaces' and |cpo-J|, for prose with
sentences separated by two spaces. For example, with 'textwidth' set
to 28: >
Surely you're joking, Mr. Feynman!
< Becomes: >
Surely you're joking,
Mr. Feynman!
< Instead of: >
Surely you're joking, Mr.
Feynman!
With 't' and 'c' you can specify when Vim performs auto-wrapping:
value action ~
"" no automatic formatting (you can use "gq" for manual formatting)
"t" automatic formatting of text, but not comments
"c" automatic formatting for comments, but not text (good for C code)
"tc" automatic formatting for text and comments
Note that when 'textwidth' is 0, Vim does no automatic formatting anyway (but
does insert comment leaders according to the 'comments' option). An exception
is when the 'a' flag is present. |auto-format|
Note that 'textwidth' can be non-zero even if Vim never performs auto-wrapping;
'textwidth' is still useful for formatting with "gq".
If the 'comments' option includes "/*", "*" and/or "*/", then Vim has some
built in stuff to treat these types of comments a bit more cleverly.
Opening a new line before or after "/*" or "*/" (with 'r' or 'o' present in
'formatoptions') gives the correct start of the line automatically. The same
happens with formatting and auto-wrapping. Opening a line after a line
starting with "/*" or "*" and containing "*/", will cause no comment leader to
be inserted, and the indent of the new line is taken from the line containing
the start of the comment.
E.g.: >
/*
* Your typical comment.
*/
The indent on this line is the same as the start of the above
comment.
All of this should be really cool, especially in conjunction with the new
:autocmd command to prepare different settings for different types of file.
Some examples:
for C code (only format comments): >
:set fo=croq
< for Mail/news (format all, don't start comment with "o" command): >
:set fo=tcrq
<
Automatic formatting *auto-format* *autoformat*
When the 'a' flag is present in 'formatoptions' text is formatted
automatically when inserting text or deleting text. This works nicely for
editing text paragraphs. A few hints on how to use