How to Collapse all Folders in Explorer in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# How to Collapse all Folders in Explorer in VS Code

To collapse all folders in the left sidebar (Explorer) in VS Code:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux
  • Command + Shift + P on macOS
Note: you can also press F1 to open the Command Palette.
  1. Type collapse and select Collapse Folders in Explorer.

collapse folders in explorer

Here is a short clip that demonstrates the process.

collapse all folders in explorer

There is also a specific button right in the Explorer menu that allows you to issue the command.

click button in sidebar to collapse all folders

Here is a short clip that demonstrates using the button.

collapse all folders in explorer using button

# Collapse all folders in Explorer using a keyboard shortcut

There is also a keyboard shortcut that allows you to collapse all folders in the sidebar.

However, the Explorer menu has to be in focus for the key combination to work.

  1. Press Ctrl + 0 (zero) (or Cmd + 0 on macOS) to focus Explorer.
  2. Press Ctrl + Left arrow (or Cmd + Left arrow on macOS) to collapse all folders.

Note that the keyboard shortcut for focusing the Primary sidebar is Ctrl (or Cmd) + 0 (zero, not the letter o).

You can also use the following keyboard shortcut to focus Explorer:

  • on Windows and Linux: Ctrl + Shift + E
  • on macOS: Cmd + Shift + E

# Setting a custom keyboard shortcut to Collapse all Folders in Explorer

By default, the Collapse Folders in Explorer command is not associated with a keyboard shortcut.

The benefit of setting a custom keyboard shortcut is that you don't have to focus the Explorer tab before pressing the key combination.

If you need to set a custom keyboard shortcut for the command:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Search for collapse folders and double-click on the row.

search collapse folders in keyboard shortcuts

You can also click on the row and then click on the plus icon to set a keyboard shortcut.

  1. Specify your preferred key combination and hit Enter to confirm.

For example, I use Ctrl + F4.

setting custom keyboard shortcut to collapse all folders

Here is a short clip of using the keyboard shortcut.

using keyboard shortcut to collapse all folders

You can also set a keyboard shortcut directly in your keybindings.json file.

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following object to your keybindings.json file.
keybindings.json
[ { "key": "ctrl+f4", "command": "workbench.files.action.collapseExplorerFolders" } ]

You can also set the keybinding to "cmd+f4" if you are on macOS or any other key combination.

I've also written an article on how to hide specific files/folders from the left sidebar.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.