vimtricks.wiki Concise Vim tricks, one at a time.

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 extra N columns of indent beyond the normal hanging indent. Useful for visually distinguishing continuation lines from the start of new lines.
  • min:N — ensure at least N columns remain for the wrapped text, preventing over-indentation on deeply nested code.
  • sbr — place the showbreak string (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:N prevents 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.lua as vim.opt.breakindentopt = 'shift:2'

Next

How do I enable matchit so % jumps between if/else/end style pairs?