Vim Tips Wiki

Changes: Automatic word wrapping


Back to page

(added gq)
(Removed the Review line as this tip is very helpful)
Line 1: Line 1:

Revision as of 04:36, September 14, 2013

Tip 850 Printable Monobook Previous Next

created 2005 · complexity basic · author mmj · version 6.0

You can set the text width using :set textwidth=n (or :set tw=n) where n is a positive integer, for example:

:set tw=79

That will automatically wrap text as close to 79 characters as white space allows without exceeding the 79 character limit. This option wraps at word boundaries.

The textwidth option can be unset using:

:set tw=0

If you want to apply this to specific areas; bring the cursor at the beginning of the text you want to format and type gq. Now specify the range, say $ to format a large line.

:set wm=2

sets a wrap margin of 2 characters from the right window border. A system-dependent EOL character is inserted and the line wraps as you type. This option may be useful in some situations, but probably is not what you are looking for.



on a line or paragraph that is too long, and vim will wrap it automatically at your assigned textwidth.



Around Wikia's network

Random Wiki