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
zvopens 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) orzO(open all nested folds),zvonly 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
zvafter landing — but when they don't,zvis your quick fix - Pair with
zzafterzvto both reveal and center the line:zvzz zvis 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