Don't change indent level of wrapped lines

Tag: vim , indentation , wrap , vimscript Author: yangyi_1 Date: 2011-11-14

If there are lines in a file that are too long to be displayed on the screen, we can use the command

:set wrap

Now long lines are split into chunks visible on the screen. Usually the code is structured and indenting is used for readability, sometimes it's part of the syntax (Python).

If a line is wrapped into two (or more) lines, only the first line has right indenting and the other lines begin at the beginning of a row.

If you use the command

:set nowrap

the line is visible only partially.

Could this behavior be changed via vimscript so that all of the wrapped lines have the same indent level?

possible duplicate of Smart Wrap in Vim — search before asking
You shouldn't have lines long enough to wrap in the first place.
@CatPlusPlus, difficult to impose on everyone and everything. Have you ever seen deeply nested XML?

Best Answer

You are right, unfortunately there is no such feature in Vim 7.3 yet, if you fancy a patch you can find a link to it below.

However there are 2 things that might help you improve readability for long code lines:

:set nu

Line numbering is used by most people editing and debugging code. A long line will have no numbers on it's wrappings clearly disambiguating code's indentation from wrapped line.

:set sbr=>\ 

A fixed marker to display on all wrappings (i.e. ">\ "). It only supports a static marker string, not based on the line's indentation.

You can combine these options and if you want the marker to be displayed in-line with line numbers you can:

:set cpoptions+=n

Patch: If you really need this feature you can try this patch:

the option is supposed to be:

:set breakindent

It would be nice indeed if someone would pick it up in the source base.