- Instant help with your Developer coding problems

Collapse code blocks in VS Code

Question:
How to collapse code blocks in VS Code?
Answer:
// Collapse the actual code block
CTRL + SHIFT + [

// Collapse ALL 
CTRL + K CTRL + 0
Description:

In Visual Studio Code, there are several options for collapsing and expanding or, as is more often used folding and unfolding code blocks.

You can fold and unfold blocks using your mouse and click on the related small arrow icons on the gutter. 

A more common way is to use keyboard shortcuts. To fold the actual code block use the CTRL + SHIFT + [ to unfold it use CTRL + SHIFT + ]. Note that this combination depends on your language preferences and keyboard layout. To check the actual shortcut press F1 and type fold. You will get all folding-related options with the actual shortcut.

To collapse all use the CTRL + K CTRL + 0. Note that 0 on Numpad is not working, only the 0 from the main keyboard area works.

You can also collapse on a specified level. For example, use CTRL + K CTRL + 2 to easily see the methods of a Java class.

More folding options:

  • Fold
  • Fold All
  • Fold All Block Comments
  • Fold All Regions
  • Fold All Regions Except Selected
  • Fold Level 1
  • Fold Level 2
  • Fold Level 3
  • Fold Level 4
  • Fold Level 5
  • Fold Level 6
  • Fold Level 7
  • Fold Recursively
Share "How to collapse code blocks in VS Code?"