How do I toggle all folding on and off globally with a single keystroke?
Answer
zi
Explanation
Pressing zi in normal mode toggles the foldenable option, which controls whether folds are active in the current window. When foldenable is off, all folds are displayed as if they are open — regardless of their actual fold level or method. Press zi again to re-enable folding and restore the previous fold state. This is faster than :set foldenable! and is especially useful when you want to temporarily scan an entire file without expanding every fold individually.
How it works
zis the prefix for fold-related commands in Vimitogglesfoldenable(think: fold inhibit)- When
foldenableis off,:set nofoldenableis active — all folds are shown open - When you press
ziagain,foldenableis restored and all folds return to their previous state - Per-window setting: each split window has its own
foldenablestate
Example
With a file that has several collapsed folds:
+-- 15 lines: function foo() ---
+-- 23 lines: function bar() ---
baz()
Press zi to instantly see the full file with all folds expanded:
function foo() {
...
}
function bar() {
...
}
baz()
Press zi again to re-collapse everything as it was.
Tips
zRopens all folds (but keepsfoldenableon) — unlikezi, folds can still be closed individuallyzMcloses all folds at oncezatoggles a single fold under the cursorziis the only command that truly disables the fold mechanism globally for the window