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.

Comments

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)

This doesn't work. With the settings saved, I restarted vim and created a new file. If I hold down the "a" key and randomly press the space bar. Eventually vim still inserts line feed characters into the text. This is not a visual wrap, but the actual '\n' character. Which shouldn't happen.