How do I toggle folding on and off for the entire buffer in one keystroke?
Answer
zi
Explanation
zi toggles the foldenable option for the current window, instantly showing or hiding all folds without altering your fold method or the configured fold levels. It is the fastest way to temporarily see all content in a heavily-folded file — press zi to open everything, read what you need, then press zi again to restore all folds exactly as they were.
How it works
z— the prefix for fold-related normal mode commandsi— mnemonic for "invert", toggling the booleanfoldenableflag- When
foldenableis off, every fold is displayed as open, regardless of its individual open/closed state - Pressing
ziagain re-enablesfoldenable, restoring all folds to their previous state — open folds reopen, closed folds re-close
Example
A buffer with syntax-based folding collapses two functions:
▸ def authenticate(): (22 lines)
▸ def process_request(): (35 lines)
After pressing zi:
def authenticate():
if not self.token:
raise AuthError("missing token")
...
def process_request():
...
Press zi again and both folds collapse back to their original state.
Tips
- Unlike
zR(which opens all folds without toggling) orzm(which increases fold level),ziis a true toggle — one key for both directions - The fold state is per-window, so
ziin one split does not affect other splits showing the same buffer - Pair with
zMto close all folds first, thenzito disable folding entirely for a clean view