Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make vim break lines only on whitespace?

I want vim to wrap long lines, but not split words in the middle. I found this post: Word wrap in Gvim

but that does not work for me. I already have l in formatoptions and linebreak enabled.

:set formatoptions?
formatoptions=lnq

As you can see, it is still splitting words: http://i.imgur.com/ekJIHww.png

After consulting the relevant help pages, I also tried setting breakat to \s, but that didn't work either.

like image 206
Daniel Avatar asked Oct 27 '13 21:10

Daniel


1 Answers

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
like image 147
glts Avatar answered Sep 19 '22 17:09

glts