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

How do I open just enough folds to see the current line without expanding everything?

Answer

zv

Explanation

zv (view cursor) opens the minimum number of folds needed to make the current line visible — nothing more. This is especially useful after navigation commands that land inside a closed fold (like /search, G, a mark jump, or a tag jump) where the cursor ends up hidden inside a collapsed region.

How it works

  • zv opens folds from the top level down until the cursor line is visible
  • It leaves sibling folds closed and does not recursively open child folds
  • Unlike zo (open one fold) or zO (open all nested folds), zv only opens exactly as many levels as needed to expose the cursor line

Example

You have a file with nested folds and search for a function body that is currently folded:

/calculateTotal

The cursor jumps to the match inside a two-level-deep fold, but the line is hidden. Running zv opens just those two levels, while leaving all other folds closed.

Compare the alternatives:

zv   → open minimum folds to reveal cursor (surgical)
zo   → open the fold directly under cursor (one level only)
zO   → open the fold and ALL nested folds recursively
zR   → open every fold in the entire file

Tips

  • Many search-and-jump workflows (tags, marks, quickfix navigation) automatically call zv after landing — but when they don't, zv is your quick fix
  • Pair with zz after zv to both reveal and center the line: zvzz
  • zv is a no-op when the cursor is already in an open fold, so it is safe to add to mappings without checking fold state first

Next

How do I accept a flagged word as correct for the current session without permanently adding it to my spellfile?