Skip to main content
Back to Blog
vscode collapse allvscode shortcutsvisual studio codecode foldingdeveloper productivity

VSCode Collapse All: Master Shortcuts for a Cleaner Workflow

Greg Ceccarelli
Greg Ceccarelli
·9 min read

You've got a tree full of folders on the left, a giant file open on the right, and the cursor is blinking while your attention keeps getting pulled into the clutter. That's usually the moment a vscode collapse all habit starts paying off, because the fastest way to think clearly in a large project is to hide what you're not using and keep the structure that matters.

The tricky part is that VS Code uses the same idea, “collapse all,” in more than one place. The Explorer sidebar, the editor, Search, and the Outline each have their own behavior, so the shortcut you press has to match the surface you're working in. If you want a broader workflow refresher alongside the keyboard basics, the Tutorial VS Code guide is a useful companion, and team workflows benefit when everyone can move through the same project tree quickly, which is why collaborative coding tools often put navigation habits at the center of shared work.

Table of Contents

Taming the Clutter in VS Code

A big repo can feel like a bad map. Half a dozen services sit under one workspace, nested folders stack three or four levels deep, and the editor itself may be showing a file with long classes, helper functions, and comments you don't need right now. In that state, collapse all isn't a cosmetic trick, it's a focus reset.

Why a clean view changes how fast you work

When the file tree is fully expanded, you spend attention on scanning instead of building. Collapsing the Explorer reduces that constant visual decision making, and folding code in the editor removes the noise inside a file without deleting the context you still need. This is a key benefit of folding: it keeps structure visible while hiding the parts you're not reading.

I use it when I'm switching from architecture work to implementation work. One press gives me a clean map of the repo, another press gives me a compact view of the file I'm editing, and both save me from digging through deep directories or scrolling through repeated boilerplate.

Practical rule: collapse the surface that's distracting you, not everything at once.

If you work across teams, this matters even more because people rarely look at the same part of the codebase at the same time. A tidy editor makes it easier to compare intent, review changes, and stay oriented in a shared workspace.

The Two Core Collapse Commands

A visual guide showing keyboard shortcuts for collapsing and expanding file folders and code regions in VS Code.

Explorer collapse

The Explorer controls the file tree, so its job is navigation. If you want to hide nested folders and get back to a readable project outline, use the Explorer collapse command instead of folding code in the editor. VS Code's global collapse shortcut for foldable regions is Ctrl+K, Ctrl+0 on Windows/Linux and Cmd+K, Cmd+0 on macOS, and the corresponding unfold command is Ctrl+K, Ctrl+J or Cmd+K, Cmd+J. VS Code also supports level-based folding with Ctrl+K, Ctrl+1/2/3/4 when you want to keep top-level structure visible while hiding deeper detail, which is handy in large codebases as documented here.

ContextCollapse allExpand allBest for
Explorer sidebarUse the Explorer's collapse command from the Command PaletteExpand folders again from the same areaTidying the file tree
EditorCtrl+K, Ctrl+0 on Windows/Linux, Cmd+K, Cmd+0 on macOSCtrl+K, Ctrl+J on Windows/Linux, Cmd+K, Cmd+J on macOSHiding code regions

Open the Command Palette and search for the Explorer command if you prefer not to memorize shortcuts. That's the safest route when you're first cleaning up a workspace or when a shortcut conflicts with something else on your machine.

Editor fold

Editor folding works inside the file you're editing. It hides syntax regions, classes, methods, comments, and other foldable blocks, so you can scan the outline of a file without losing the ability to jump back into details. The fold and unfold chords above are the core shortcuts to remember, but the deeper point is that they work on the code structure, not on file navigation.

If you're trying to inspect a long service file, fold first and read second. You'll see the shape of the implementation faster, and you won't keep fighting the scroll bar.

Explorer Collapse vs Editor Fold Explained

A developer coding in Visual Studio Code on a large monitor with collapsed code sections displayed.

The common mistake is treating every collapse command as if it were the same tool. It isn't. VS Code separates the file navigation surface from the text-editing surface, and that's why collapsing folders in the Explorer and folding code in the editor solve different problems.

The situation is comparable to volume controls: your operating system has one control, your music player has another, and turning the wrong one doesn't help. The Explorer's collapse behavior changes the project tree, while editor folding changes the visible structure inside a file. That distinction matters because many guides blur Search, Explorer, Outline, and editor folding together, even though VS Code exposes separate behaviors such as search.collapseResults and outline.collapseItems for other panels as discussed in this overview.

What to use when

If your problem is “I can't see the shape of the repo,” collapse the Explorer. If your problem is “this file is too noisy to read,” fold the editor. If your problem is “my search results are flooding the sidebar,” the answer lives in Search, not in code folding.

That mental model removes a lot of frustration. You stop asking why one shortcut didn't seem to work, because now you know you were in the wrong UI surface. The command name is only half the answer, the panel you're focused on is the other half.

Customizing Your Collapse Keybindings

A close-up shot of a human hand resting on a mechanical keyboard with customized keycaps.

The default key chord is fine until you use folding dozens of times a day. Then it starts to feel like too much finger travel, especially if you're bouncing between the Explorer and the editor all day. That's why custom keybindings are worth the small setup cost.

Open Keyboard Shortcuts, then switch to the JSON view of keybindings.json. From there you can map the commands to something shorter and easier to hit, as long as you avoid conflicts with other shortcuts already in use.

A simple example looks like this:

[
  {
    "key": "ctrl+alt+0",
    "command": "workbench.actions.tree.collapseExplorerFolders"
  },
  {
    "key": "ctrl+alt+9",
    "command": "editor.foldAll"
  }
]

The exact command IDs can vary by context, so check the Keyboard Shortcuts editor before you settle on a layout. The goal is not to copy someone else's shortcut scheme, it's to make collapse and unfold feel automatic in your own hands.

One reason this pays off is that folding isn't just about the current moment. People often ask how to undo a mistaken collapse or keep the behavior consistent, and the answers are spread across unfold commands, keybinding changes, and folding preferences as noted in community discussion. If you want a smoother setup on a Mac workflow, the same customization mindset applies across tools, including editor-centric setups like Cursor on macOS.

If you're using the keyboard constantly, even a small remap can cut down on hesitation. The best layout is the one you don't have to think about.

Troubleshooting and Advanced Folding

An infographic detailing four troubleshooting steps to restore code folding functionality in Visual Studio Code.

When folding stops behaving the way you expect, start with the basics before you blame VS Code. A shortcut can be overridden, a language mode can affect what's foldable, and a file can need a different folding strategy.

If the keyboard chord feels dead, check the keybinding first, not the code.

A good troubleshooting flow is simple:

  • Check Keybindings: Verify that the collapse command is still mapped the way you expect, and look for overrides from extensions.
  • Inspect the language mode: Some folding behavior depends on syntax support, so the file type matters.
  • Use manual regions: #region and #endregion comments are useful when you want to control exactly what gets hidden in supported languages.
  • Adjust folding settings: Review editor.foldingStrategy if indentation and syntax folding aren't matching your workflow.

For function or method-specific hiding, VS Code's folding is syntax-driven and region-based, so the reliable tools are the gutter fold icons, fold markers, or the current-region chord Ctrl+Shift+[ and Ctrl+Shift+] as described here. If you need only methods collapsed by default, explicit regions often give you more control than hoping a global collapse command will do exactly what you want.

Teams working in large files usually get more value from predictable folding than from a single shortcut. The combination of unfold-all recovery, level-based folding, and deliberate region markers turns collapse from a one-off trick into a real navigation system.

For a deeper workflow view that connects editor habits with real development speed, check spec-story and Copilot after you've tuned your folding setup.


If you're tightening up your VS Code workflow, start by remapping the collapse commands you use most, then test them in both the Explorer and the editor. If you want a shared system for turning quick editor wins into repeatable team habits, SpecStory, Inc. is worth a look.

Newsletter

Get new posts in your inbox

Bring your team together to build better products. Fresh takes on remote collaboration and AI-driven development.