How do I control the exact indentation amount for continuation lines when text wrapping is enabled?
Answer
:set breakindentopt=shift:2
Explanation
When breakindent is enabled, wrapped continuation lines are indented to match the start of their logical line. The breakindentopt option lets you fine-tune this behaviour with several sub-options, making long lines in prose, code comments, and markdown far easier to read.
How it works
First, enable the base option:
:set wrap breakindent
Then use breakindentopt to adjust the indent:
shift:N— add an extraNcolumns of indent beyond the normal hanging indent. Useful for visually distinguishing continuation lines from the start of new lines.min:N— ensure at leastNcolumns remain for the wrapped text, preventing over-indentation on deeply nested code.sbr— place theshowbreakstring (if set) inside the indentation rather than before it.
Multiple values can be combined with commas:
:set breakindentopt=shift:2,min:20
Example
Given a long comment with shift:4:
/* This is a very long comment that wraps across multiple screen lines when the window is narrow */
With breakindentopt=shift:4, continuation lines appear as:
/* This is a very long comment that wraps across
multiple screen lines when the window is narrow */
Without breakindentopt, only the base breakindent would indent to column 4, matching the /* start.
Tips
- Pair with
:set showbreak=↪\to add a visual marker at the start of each continuation line min:Nprevents extremely indented lines (e.g. 8-space indented code) from leaving no room for text- These settings only affect visual display — the actual file content and newlines are unchanged
- Add to your
vimrc/init.luaasvim.opt.breakindentopt = 'shift:2'