How do I toggle a fold and all its nested folds open or closed at once?
Answer
zA
Explanation
The zA command toggles the fold under the cursor together with all nested sub-folds in one keystroke. Unlike za — which only affects the topmost fold at the cursor — zA recursively opens or closes the entire fold tree beneath the cursor, making it ideal for navigating deeply nested code structures.
How it works
- If the fold is closed:
zAopens it and all nested folds inside it (likezO) - If the fold is open:
zAcloses it and all nested folds inside it (likezC)
This makes zA the recursive counterpart of za:
| Command | Scope | Direction |
|---|---|---|
za |
Current fold only | Toggle |
zA |
Current + all nested | Toggle (recursive) |
zO |
Current + all nested | Open only |
zC |
Current + all nested | Close only |
Example
With a nested fold structure:
+-- class Foo ----------+ ← outer fold (open)
| +-- def bar() ---+ | ← inner fold (open)
| | ... | |
| +----------------+ |
+-----------------------+
Press zA on the outer fold:
+-- class Foo ----------+ ← outer fold (now closed, inner fold hidden)
Press zA again:
+-- class Foo ----------+ ← outer fold (open again)
| +-- def bar() ---+ | ← inner fold (open again)
Tips
zRopens all folds in the entire file;zMcloses all folds — use these for a global resetzmandzrincrement or decrement the fold level by one across the whole file- Works with any
foldmethod(indent, syntax, marker, expr, manual) - Combine with a count:
2zAtoggles two fold levels at once