Last updated: Apr 6, 2024
Reading time·3 min
To collapse all folders in the left sidebar (Explorer) in VS Code:
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.Here is a short clip that demonstrates the process.
There is also a specific button right in the Explorer menu that allows you to issue the command.
Here is a short clip that demonstrates using the button.
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.
Ctrl
+ 0
(zero) (or Cmd
+ 0
on macOS) to focus Explorer.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:
Ctrl
+ Shift
+ E
Cmd
+ Shift
+ E
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:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can also click on the row and then click on the plus icon to set a keyboard shortcut.
Enter
to confirm.For example, I use Ctrl
+ F4
.
Here is a short clip of using the keyboard shortcut.
You can also set a keyboard shortcut directly in your keybindings.json
file.
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.keybindings.json
file.[ { "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.
You can learn more about the related topics by checking out the following tutorials: