Ramya Ramachandran
Ramya Ramachandran

Reputation: 1151

Visual Studio Code - Shortcut - Collapse all files in explorer

Can you anyone provide the shortcut for collapse all files in visual studio code explorer?

Upvotes: 85

Views: 37414

Answers (7)

Andrew D. Bond
Andrew D. Bond

Reputation: 1280

The below solution:

  • Works without a mouse
  • Works even if a different primary sidebar (Search, Source Control, Run and Debug, etc.) was last open
  • Works out of the box / does not require adding new shortcut(s)

Solution:

  1. Ctrl+Shift+E (Corresponding command is View: Show Explorer. For macOS: +Shift+E)
  2. Ctrl+ (Corresponding command is list.collapseAll. For macOS: +)

Upvotes: 9

Mwiza
Mwiza

Reputation: 8951

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

Upvotes: 18

Libin Varghese
Libin Varghese

Reputation: 1734

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. Collapse shortcuts for list

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.

Upvotes: 2

Fluous
Fluous

Reputation: 2475

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-arrow

An additional benefit over this approach is that I usually want to focus on the explorer view if I want to collapse the folders.

Upvotes: 123

JayChase
JayChase

Reputation: 11525

You can collapse all folders using cmd/ctrl left-arrow.

Upvotes: 19

ahhmarr
ahhmarr

Reputation: 2320

it's cmd/ctrl + shift + up-arrow

Upvotes: 38

Thanh Le Hai Hoang
Thanh Le Hai Hoang

Reputation: 1403

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.

Upvotes: 89

Related Questions