194

Trying to find the equivalent to Ctrl + Shift + - in Intellij that collapses/expands all functions.

Penny Liu
  • 11,885
  • 5
  • 66
  • 81
michali
  • 2,529
  • 4
  • 16
  • 20
  • 3
    Possible duplicate of [How do I collapse sections of code in Visual Studio Code for Windows](http://stackoverflow.com/questions/30067767/how-do-i-collapse-sections-of-code-in-visual-studio-code-for-windows) – Jevgeni Geurtsen Sep 27 '16 at 07:29

5 Answers5

343

Here it is.

Ctrl+Shift+[    Fold (collapse) region  editor.fold
Ctrl+Shift+]    Unfold (uncollapse) region  editor.unfold
Ctrl+K Ctrl+[   Fold (collapse) all subregions  editor.foldRecursively
Ctrl+K Ctrl+]   Unfold (uncollapse) all subregions  editor.unfoldRecursively
Ctrl+K Ctrl+0   Fold (collapse) all regions editor.foldAll
Ctrl+K Ctrl+J   Unfold (uncollapse) all regions

Take Look at Visual studio Code Keybindings section at this link.

Also Platform specific Key board shortcuts available in pdf.here is the links

Windows,MAC,Linux

Jagadeesh Govindaraj
  • 5,767
  • 6
  • 30
  • 51
  • 5
    This may have a conflict with the Vim plugin. Mentioning in case folks come here and scratch their head why it seems not to work. The Vim plugin is extremely bad about Ctrl-key sequences and MSoft could care less. – jatal Jun 02 '18 at 23:16
  • Ctrl + K Ctrl + 3 – noririco Jul 27 '20 at 05:18
  • 1
    Nice, and for Mac users, all same, just in place of `Ctrl` use `⌘ (Command)` – kishore Jun 03 '21 at 12:55
  • 4
    Yes, it makes sense to make Ctrl+K+zero and Ctrl+K+J a pair of commonly used key bindings. Very wise to make them completely forgettable and bizarre. Well done Microsoft. Looking forward to not being able to install Windows 11. – Dan Rayson Jun 29 '21 at 13:47
41

You can set custom values for that.

  1. Open the Command Palette ( + + P or F1 on Mac)
  2. Search Open Keyboard Shortcuts
  3. Then search for collapse
  4. Finally click the + sign near the Collapse All and Collapse Folders in Explorer options and set the shortcuts like I did

keyboard vscode collapse all shortcuts

Or you can open keybindings.json file and add this to the main array.

 ,
  {
    "key": "cmd+k cmd+s",
    "command": "search.action.collapseSearchResults"
  },
  {
    "key": "cmd+k cmd+e",
    "command": "workbench.files.action.collapseExplorerFolders"
  }
Nordle
  • 2,698
  • 3
  • 12
  • 32
Ahmad Awais
  • 28,567
  • 4
  • 71
  • 55
27

Go to File --> Preferences --> Keyboard Shortcuts (or Ctrl+K Ctrl+S)

Search for the word fold all

The ones you need are:

  • Fold All
  • Unfold All

Set your custom keyboard shortcut

Stefanos Kargas
  • 9,683
  • 21
  • 74
  • 98
11

One simple way I use is:

  1. Launch command pallete with Ctrl + Shift + P
  2. Search for Collapse Folders in Explorer
  3. Press Enter

You can also define a custom shortcut for this command in settings.

Luis Felipe
  • 111
  • 1
  • 4
  • Thanks this was helpful, a recent update has made all of my folders expand when I first open VS Code, which is less than ideal. This makes it easy to close them all. – Karl Carpenter Oct 14 '21 at 13:01
1

Go to 'Keyboard Shortcuts' and type in search input: "fold all regions". You see fold/unfold (expand/collapse) commands and shortcuts. Use or change them.

Alexander
  • 11
  • 2