VS Code collapse all: fold all functions and methods
Codemia Knowledge Hub ·
To collapse all methods in Visual Studio Code, press Ctrl+K Ctrl+0 on Windows/Linux or Cmd+K Cmd+0 on macOS. This folds every collapsible block in the file. VS Code also has level-specific folding, region folding and language-aware folding when you need finer control over what gets collapsed.
All folding shortcuts
| Action | Windows / Linux | macOS |
| Fold All | Ctrl+K Ctrl+0 | Cmd+K Cmd+0 |
| Unfold All | Ctrl+K Ctrl+J | Cmd+K Cmd+J |
| Fold current block | Ctrl+Shift+[ | Cmd+Option+[ |
| Unfold current block | Ctrl+Shift+] | Cmd+Option+] |
| Fold Level 1 | Ctrl+K Ctrl+1 | Cmd+K Cmd+1 |
| Fold Level 2 | Ctrl+K Ctrl+2 | Cmd+K Cmd+2 |
| Fold Level 3 | Ctrl+K Ctrl+3 | Cmd+K Cmd+3 |
| Fold All Block Comments | Ctrl+K Ctrl+/ | Cmd+K Cmd+/ |
| Fold All Regions | Ctrl+K Ctrl+8 | Cmd+K Cmd+8 |
| Unfold All Regions | Ctrl+K Ctrl+9 | Cmd+K Cmd+9 |
| Toggle Fold | Ctrl+K Ctrl+L | Cmd+K Cmd+L |
These are chord shortcuts: press the first key combination, release, then press the second.
Fold All vs. fold by level
Fold All (Ctrl+K Ctrl+0) collapses every block, including nested blocks inside methods, so only the top-level declarations remain visible.
Fold by level is more precise. In a class file:
- Level 1 (
Ctrl+K Ctrl+1) folds classes, leaving imports visible. - Level 2 (
Ctrl+K Ctrl+2) folds methods inside classes but keeps the class declaration expanded. - Level 3 (
Ctrl+K Ctrl+3) folds if/for/while blocks inside methods.
Level 2 is usually what people mean by "collapse all methods": the methods fold while the class structure stays visible.
Example: Level 2 fold on a TypeScript file
Before folding:
After Ctrl+K Ctrl+2:
Every method signature is visible while the implementations are hidden.
Finding fold commands in the Command Palette
If you forget a shortcut, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and type "fold" to list the fold commands:
- Fold All
- Unfold All
- Fold Level 1 / 2 / 3 / 4 / 5 / 6 / 7
- Fold All Block Comments
- Fold All Regions
- Fold Recursively
- Unfold Recursively
Custom fold regions with #region markers
Language-specific markers define foldable regions that fold independently of the code structure. They help organize files that have no natural block boundaries.
JavaScript / TypeScript:
Python:
C# / Java:
CSS / SCSS:
Fold all custom regions with Ctrl+K Ctrl+8 and unfold them with Ctrl+K Ctrl+9.
Folding settings
Open Settings JSON (Ctrl+, then click the JSON icon) and add:
| Setting | Options | Effect |
showFoldingControls | "always" / "mouseover" | Whether gutter arrows are always visible or only on hover |
foldingStrategy | "auto" / "indentation" | auto uses the language server; indentation uses whitespace |
foldingHighlight | true / false | Highlights the folded region background |
foldingMaximumRegions | number | Caps fold regions for performance on very large files |
Per-language folding strategy
Languages like Python or YAML often fold better by indentation. Set it per language:
Auto-folding when a file opens
VS Code does not fold files on open by default. The simplest fix is the Auto Fold extension from the Marketplace:
- Install Auto Fold from the Extensions panel.
- Set
"autofold.default": 2in your settings to auto-fold at level 2 when files open.
Alternatively, bind Fold Level 2 to a single key and press it right after opening a file:
When folding does not behave as expected
- Chord shortcuts do nothing. Press
Ctrl+K, release both keys, then pressCtrl+0. Holding all keys at once will not register. - Methods are not detected. If
foldingStrategyis"indentation"for a language with a language server (like TypeScript or Java), switch it to"auto"for structure-aware folding. - Fold All collapses too much. Use
Ctrl+K Ctrl+2instead ofCtrl+K Ctrl+0to keep class declarations visible. - Search and folded code.
Ctrl+Fsearches folded regions too, and matches inside folded blocks expand when you navigate to them. - Fold state is lost on reopen. Folds reset when you close and reopen a file. The "Remember Fold State" extension adds persistence.
- Very large files lag. Files with more than 5,000 foldable regions may lag. Increase
foldingMaximumRegionsor split the file.
Related reading
- CollectionT versus ListT what should you use on your interfaces?
- Command for WPF TextBox that fires up when we hit Enter Key
- Compare String and Object in C
- Comparing double values in C
- Comparing two byte arrays in .NET
- Compilation Error The modifier 'public' is not valid for this item while explicitly implementing the interface
- Compilation Error The type 'ASP.global_asax' exists in both DLLs
- Compiling C to Native?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.