Word Wrap in Vim (preserving indentation)

后端 未结 4 1319
南旧
南旧 2021-01-31 00:53

I was just looking at this post which describes how to wrap entire words in vim. The accepted solution was this:

:set formatoptions=l
:set lbr

4条回答
  •  一整个雨季
    2021-01-31 01:22

    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.

提交回复
热议问题