Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collapse sub-folders when a folder is closed in VS Code?

When I collapse a folder, I want the sub-folder to be collapsed as well. Right now when I collapse a folder and re-open it, the sub-folders stay as they were while the folder was being closed. I want the behaviour where collapsing the folder also collapses the sub-folders.

like image 676
Gurleen Sethi Avatar asked Jul 28 '19 07:07

Gurleen Sethi


People also ask

How do I collapse a folder in VS Code?

How to Collapse All Folders in VS Code? To fold all the folders in your code: Enter command >fold and hit enter.

Is there a way to collapse folders?

Expand/collapse folders icons to expand or collapse a selected folder. Right-click a folder and choose Expand > Folder or Collapse > Folder to expand/collapse the selected folder. Right-click a folder and choose Expand > Expand All or Collapse > Collapse All to expand or collapse the entire tree.

How to collapse all folders and regions in VS Code?

Or use keyboard shortcuts: How to Collapse All Folders in VS Code? To fold all the folders in your code: Enter command >fold and hit enter. Or use keyboard shortcuts: To unfold all the folders in your code: Enter command >unfold all and hit enter. Or use keyboard shortcuts: How to Collapse All Regions in VS Code?

How to add collapse folders to the keyboard shortcut?

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.

How to fold/collapse a code block in Visual Studio Code?

This feature is now supported, since Visual Studio Code 1.17. To fold/collapse your code block, just add the region tags, such as //#region my block name and //#endregion if coding in TypeScript/JavaScript.

How to unfold and collapse all nodes in VS Code?

To unfold all the regions in your code: Enter command >unfold all and hit enter. Or use keyboard shortcuts: How to Collapse All XML Nodes in VS Code? To fold all the XML nodes in your code: Enter command >fold and hit enter. Or use keyboard shortcuts:


2 Answers

You can Alt+Click a folder to recursively expand or collapse it. However, I don't think it's possible to make that the default, since keybindings don't support mouse input.

like image 118
Gama11 Avatar answered Oct 21 '22 10:10

Gama11


The new 1.42 (Q1 2020) VSCode might help:

Two-step collapse in multi-root Explorer

When you are using a multi-root workspace, the Collapse Folder button in the File Explorer now has a two-step behavior, where:

  • the first click will collapse all folders within each top-level, and
  • the second click will collapse the top-level folders.

The Search view already has this behavior.

Two-step File Explorer collapse button -- https://media.githubusercontent.com/media/microsoft/vscode-docs/vnext/release-notes/images/1_42/2-step-collapse.gif

like image 36
VonC Avatar answered Oct 21 '22 10:10

VonC