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

How do I open folds one level at a time in Vim without revealing all nested folds at once?

Answer

zr

Explanation

zr ("reduce" fold level) decrements the global foldlevel option by 1, opening the next layer of folds across the entire file. This is the incremental counterpart to zR, which opens all folds at once. With zr, you stay in control — each press reveals one more level of nesting without exposing deeply nested folds you haven't reached yet.

How it works

  • foldlevel controls how many nesting levels are open; a level of 0 means all folds are closed
  • zr runs :set foldlevel+=1 (decrements the number of closed levels)
  • zm runs :set foldlevel-=1 (the opposite — closes one level)
  • zR opens everything: :set foldlevel=99
  • zM closes everything: :set foldlevel=0

Example

With a deeply nested file (say, 4 levels of folds):

+-- 20 lines: Level 1 ----   ← all closed (foldlevel=0)

Press zr → foldlevel=1      ← Level 1 opens
Press zr → foldlevel=2      ← Level 2 opens
Press zr → foldlevel=3      ← Level 3 opens
Press zm → foldlevel=2      ← Level 3 closes again

Tips

  • Use zr to incrementally reveal a large file without getting overwhelmed
  • Pair with za (toggle a single fold) for fine-grained control at the cursor
  • A count prefix works: 2zr opens two levels at once
  • Works with all foldmethod settings: indent, expr, marker, syntax, manual

Next

How do I inspect a Vim register's full details including its type (charwise, linewise, or blockwise) in Vimscript?