Word Wrap in Vim (preserving indentation)

This did not work when the question was originally asked, but as of June 25, 2014, this will work. (Assuming you update your vim to a version newer than that date)

Add to your .vimrc:

" Indents word-wrapped lines as much as the 'parent' line
set breakindent
" Ensures word-wrap does not split words
set formatoptions=l
set lbr

And that’s it!

Some people (myself included) share a single .vimrc across multiple computers. In that case, it’s important to have this line be robust (to avoid annoying error messages). This is a little better:

if has("patch-7.4.354")
    " Indents word-wrapped lines as much as the 'parent' line
    set breakindent
    " Ensures word-wrap does not split words
    set formatoptions=l
    set lbr
endif

This way, if you’re on an earlier version of vim, you don’t get an error message.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)