Vim Tips Wiki
Register
Advertisement
Tip 989 Printable Monobook Previous Next

created 2005 · complexity basic · version 6.0


When editing a text file, if you want word wrapping, but only want line breaks inserted when you explicitly press the Enter key:

:set wrap
:set linebreak
:set nolist  " list disables linebreak

This will get Vim to wrap existing text as desired. wrap tells Vim to word wrap visually (as opposed to changing the text in the buffer), and linebreak tells Vim to only wrap at a character in the breakat option (by default, this includes " ^I!@*-+;:,./?" (note the inclusion of " " and that ^I is the control character for Tab)).

In addition, you will need to prevent Vim from automatically inserting line breaks in newly entered text. The easiest way to do this is:

:set textwidth=0
:set wrapmargin=0

If you want to keep your existing 'textwidth' settings for most lines in your file, but not have Vim automatically reformat when typing on existing lines, you can do this with:

:set formatoptions+=l

To make settings permanent, without the need to type this every time you use Vim, just add the commands to your vimrc.

References

See also

Comments

I'm not certain whether 'wrapmargin' is always turned off when it is set equal to zero, but it seems to work. Is this always the case?

--Fritzophrenic 17:47, June 15, 2010 (UTC)

I do not use wrapmargin but surely its meaning implies that it only does something when set to a value above zero. I think it's pretty safe to assume the tip is ok. JohnBeckett 11:32, June 16, 2010 (UTC)
Advertisement