Can you anyone provide the shortcut for collapse all files in visual studio code explorer?
Can you anyone provide the shortcut for collapse all files in visual studio code explorer?
Open the Keyboard Shortcut by pressing Ctrl + K then Ctrl + S and search for Collapse, you will see the Collapse Folders in Explorer key binding (It is empty by default). Press the + button to add your desired key binding.
Now you can enjoy your shortcut.
I personally prefer not to create new shortcuts. As @Mark pointed out on the answer of @JayChase there is an existing shortcut, but it requires the explorer to be in focus. Therefore I combine the shortcut mentioned by @JayChase with another standard shortcut, to get the desired behaviour.
command + 0 (focusses on explorer).command + left-arrowAn additional benefit over this approach is that I usually want to focus on the explorer view if I want to collapse the folders.
First, click anywhere in the explorer window to activate it, then use the shortcut.
On Windows and Linux.
Ctrl + Left arrow
On Mac:
ā + Left arrow
When the Explorer is active, you could use the Workbench list based shortcuts. list based shortcuts include collapse, collapse all, expand, expand all, toggle expand/collapse
To see what are the shortcuts open Keyboard Shorcuts -> Search for list. . Here you find shortcuts for collapse, collapse all, expand, expand all, toggle expand/collapse. These shortcuts work when the Explorer is active, as the Explorer works as a list.
Below is a screenshot for Mac.

If you would like to define a shortcut, without activating the Explorer, then I would recommend - cmd+k ctrl+c. You could add this by opening Keyboard Shorcuts -> Search for Collapse Folders in Explorer -> Click the edit button after hovering over the the Command you want to edit.