How to Collapse All in VS Code

The folding commands in VS code minimize and expand different parts of your program, allowing you to focus on the areas you’re working on. This can be done by running a particular fold command, entering keyboard shortcuts, or by clicking on the chevrons in the gutter beside the code of interest.

How to Collapse All in VS Code

If you want to know how to collapse sections of your code, in this article, we’ll take you through the basic fold/unfold commands and their Windows, Linux, and Mac shortcuts. Plus, we’ll cover plenty of handy keyboard shortcuts.

How to Collapse All Source Code in VS Code?

To fold all top-level and child elements of your code:

  • Enter the command >fold and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K or Ctrl+O (the letter)

Mac: ⌘K ⌘0

To unfold all top-level and child elements of your code:

  • Enter the command >unfold all and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+J

Mac: ⌘K ⌘J

How to Collapse All Folders in VS Code?

To fold all the folders in your code:

  • Enter the command >fold and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K or Ctrl+O (the letter)

Mac: ⌘K ⌘0

To unfold all the folders in your code:

  • Enter the command >unfold all and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+J

Mac: ⌘K ⌘J

How to Collapse All Regions in VS Code?

To fold all the regions in your code:

  • Enter command >fold and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K or Ctrl+O (the letter)

Mac: ⌘K or ⌘0

To unfold all the regions in your code:

  • Enter command >unfold all and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+J

Mac: ⌘K ⌘J

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:

Windows and Linux: Ctrl+K or Ctrl+O (the letter)

Mac: ⌘K ⌘0

To unfold all the XML nodes in your code:

  • Enter command >unfold all and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+J

Mac: ⌘K ⌘J

How to Collapse All Comments in VS Code?

To fold all the documentation comments in your code:

  • Enter command >fold all block comments and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+/

Mac: ⌘K ⌘/

To unfold all the comments:

  • Enter command >unfold all and hit Enter.

Or use keyboard shortcuts:

Windows and Linux: Ctrl+K Ctrl+J

Mac: ⌘K ⌘J

How to Collapse All Search Results in VS Code?

To collapse the search results in VS code, use the toggle expand/collapse icon found towards the top-right of the search area. This will display the search result file name only. The number of matches is displayed to the right of each file name.

To expand the results, just click on the expand/collapse toggle button again.

Additional FAQ

What’s the Hot Key to Collapse the Deepest Region?

The keyboard shortcut to fold the innermost expanded region at the current cursor position is:

Windows and Linux: Ctrl+Shift+[

Mac: ⌥⌘[

To unfold, it’s:

Windows and Linux: Ctrl+Shift+]

Mac: ⌥⌘]

What’s the Hot Key to Collapse a Particular Level in the Code?

The keyboard shortcut to fold all regions at a precise level, excluding the current cursor position, is:

Windows and Linux: Ctrl+K Ctrl + (level number)

Mac: ⌘K ⌘(level number)

What’s the Hot Key to Collapse and Expand Regions Stated as Markers?

To fold all maker regions, it’s:

Windows and Linux: Ctrl+K Ctrl+8

Mac: ⌘K ⌘8

To unfold, it’s:

Windows and Linux: Ctrl+K Ctrl 9

Mac: ⌘K ⌘9

What Is the Command Palette in VS Code?

The “Command Palette” is where all the VS commands reside. It’s very useful since it displays the keyboard shortcuts for commands. To access commands based on your current context:

Windows and Linux: ⇧ Ctrl+P

Mac: ⇧⌘P

What Is the VS Shortcut to Open Files?

The keyboard shortcut to open your files is:

Windows and Linux: Ctrl+P

Mac: ⌘P

To create new files:

Windows and Linux: Ctrl+alt+N

Mac: ⌘N

To create new folders:

Windows and Linux: Ctrl+alt+shift+N

Mac: ⌘N

What Is the VS Shortcut to See Errors and Warnings?

The keyboard shortcut to bring up any errors and warnings in your code is:

Windows and Linux: ⇧Ctrl+M

Mac: ⇧⌘M

Then use the F8 or ⇧F8 keys to navigate through them.

What Is the VS Shortcut for Side-by-Side Editing?

The keyboard shortcut to use side-by-side editing is:

Windows and Linux: Ctrl+\

Mac: ⌘\

How Do You Change the Display Language in VS?

You can change the GUI default language setting by using the “Configure Display Language” command.

To bring up the Command Palette, enter ⇧+Ctrl+P or ⇧⌘P, then type display for the Configure Display Language command.

Then press Enter for a list of installed languages by locale with the current locale highlighted.

How Do I Navigate the Screen Layout in VS?

The minimal and intuitive screen layout of VS code has been designed for maximum editor space whilst allowing room to access the context of your projects and folders. The User Interface is split into five sections:

  • The “Editor” is the key area for editing your files. You have the option of opening as many editors as you want. They’ll display next to each other horizontally and vertically.
  • The “Side Bar” has different views to support you whilst you work on your projects.
  • The “Status Bar” includes useful info about the opened project and files being edited.
  • Situated on the far left-hand side of the screen is the “Activity Bar.” Here you can swap between views and see extra context-specific pointers, e.g., the number of outgoing amendments when “Git” is switched on.
  • Different “Panels” can be displayed beneath the editor area for warnings and error information or an integrated terminal. This Panel can be moved to the right of the screen for more space.

Every time you launch VS code, it opens with the same display as when you previously closed it, including your opened files and folder layout.

Hiding Blocks of Code in VS

Visual Code Studio helps make a programmer’s life easier to navigate code with the fold and unfold command. You have the option to collapse and expand particular sections of code, comments, and even the search results to focus on what you need and hide the rest.

Now that we’ve shown you the various ways to collapse and expand your code, what method have you found to be the easiest? If you use shortcuts—what method do you use to remember them? We’d love to hear about your experience in using VS code; please leave a comment in the comments section below.

Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.