How do I close one more level of folds without collapsing all folds at once?
Answer
zm
Explanation
Instead of jumping between fully open (zR) and fully closed (zM), zm and zr let you step through fold levels one at a time. This gives precise control when navigating deeply nested code or structured documents.
How it works
zm— more folds: decreasesfoldlevelby 1, closing one additional nesting levelzr— reduce folds: increasesfoldlevelby 1, opening one additional nesting level- Both accept a count:
3zmdecreases fold level by 3 in one step
Fold level 0 means all folds are closed; higher values open progressively deeper nesting.
Example
In a file with three nesting levels (module → class → method):
▸ module
▸ class A
▸ method foo
▸ method bar
▸ class B
Starting with all folds open:
zm→ method-level folds collapse (level 3 hidden)zm→ class-level folds also collapse (levels 2–3 hidden)zr→ class-level folds reopen (methods still hidden)
Tips
- Check or set the current fold level directly:
:set foldlevel?/:set foldlevel=2 zMandzRare the extremes: close all and open all, respectively- Pair
zm/zrwithzj/zkto navigate between folds at the current level - Works with any
foldmethod:indent,syntax,marker,manual, orexpr