Collapse all methods in Visual Studio Code
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
To collapse (fold) 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, giving you a bird's-eye view of your code structure. VS Code also offers level-specific folding, region folding, and language-aware folding that let you control exactly what gets collapsed.
Quick Reference: 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 |
All of 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 single block, including nested blocks inside methods. You see only the top-level declarations.
Fold by Level gives you finer control. For example, 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.
This is usually what developers actually want when they say "collapse all methods." Use Level 2 to fold methods while keeping the class structure visible.
Example: Level 2 fold on a TypeScript file
Before folding:
After Ctrl+K Ctrl+2:
You can see every method signature at a glance while the implementation details are hidden.
Using the Command Palette
If you forget a shortcut, open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and type "fold". You will see all available 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
You can define custom foldable regions using language-specific markers. These regions fold independently of the code structure and are useful for organizing files that do not have 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.
Configuring Fold Behavior in Settings
VS Code exposes several settings that control how folding works. 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 |
Language-specific folding strategy
Some languages (like Python or YAML) work better with indentation-based folding. You can set it per language:
Auto-Fold on File Open
VS Code does not auto-fold files on open by default, but you can achieve this with a task or an extension. The simplest approach is to use 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, you can add a keybinding that runs fold after opening:
Common Pitfalls
- Chord shortcuts not working. These are two-step shortcuts. Press
Ctrl+K, release both keys, then pressCtrl+0. If you hold all keys at once, it will not register. - Folding does not detect methods. If
foldingStrategyis set to"indentation"for a language that has a language server (like TypeScript or Java), switch it to"auto"for structure-aware folding. - Fold All collapses too much. Use level-specific folding (
Ctrl+K Ctrl+2) instead of Fold All (Ctrl+K Ctrl+0) to keep class declarations visible. - Folded code disappears from search.
Ctrl+Fsearches all text including folded regions. Matches inside folded blocks will auto-expand when you navigate to them. - Saving does not preserve fold state. Folds reset when you close and reopen a file. Use the "Remember Fold State" extension if you need persistence.
- Performance on very large files. Files with more than 5,000 foldable regions may lag. Increase
foldingMaximumRegionsor split the file.
Summary
- Fold all methods:
Ctrl+K Ctrl+0(Windows/Linux) orCmd+K Cmd+0(macOS). - Fold only methods (keep class visible): Use Level 2 folding with
Ctrl+K Ctrl+2. - Unfold everything:
Ctrl+K Ctrl+J. - Use
#region/#endregionmarkers for custom foldable sections in any language. - Set
"editor.foldingStrategy": "auto"for language-aware folding, or"indentation"for whitespace-based languages. - All fold commands are accessible through the Command Palette by typing "fold".
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 courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.