How can I make vim break lines only on whitespace?

It depends whether you are talking about hard linebreaks, where a newline character is actually inserted into the text, or a soft linebreak, which only affects how the text is displayed on the screen. I suspect that you are referring to the latter.

If that is correct, then you want to :set list and probably add set list to your vimrc.

Besides, wrapping the display,just the display, not the actual text at word boundaries, list also causes Vim to display various "invisible" characters, such as spaces, tabs, and (hard) newlines, according to the listchars variable (see :help listchars for more); if you want the soft line-wrapping at word boundaries but not invisible characters, you could presumably set the listchars to nothing.

I personally find that I sometimes want list enabled and sometimes not. :set nolist turns it off and :set list! toggles it. And just for completeness, :set list? tells you whether is is currently enabled or not. Those are all standard Vim conventions.

And if that's too much typing, you could set up a custom key mapping in your .vimrc, but that's another question.


As you found out this is done using the 'linebreak' option (with 'wrap' on).

If on Vim will wrap long lines at a character in 'breakat' rather than at the last character that fits on the screen.

And since 'breakat' by default contains Space and Tab and some punctuation characters, this should break lines as expected (not in the middle of a word). I suggest resetting 'breakat' to the Vim default in case it has been changed by a plugin or a mapping.

Oh, and don't set 'list', these features don't mix.

All together now:

:set nolist wrap linebreak breakat&vim