What is shortcut for expand-collapse sections of code in VS Code?

I have just started using Visual Studio Code and not sure what is the keyboard shortcut for expand-collapse or fold-unfold sections of code in VS Code? Can you help me with that.

Asked by:- jon
: 757 At:- 1/6/2023 3:57:35 PM
Visual Studio Code VS Code shortcut

1 Answers
profileImage Answered by:- vikas_jk

Fold or Collapse All:

  • Windows, Mac and Linux: Ctrl + K, Ctrl + 0

Unfold or Expand All:

  • Windows, Mac and Linux: Ctrl + K, Ctrl + J

Note: In Mac 'Ctrl' buttons looks different, text of which, I am not able to add due to editor limitations.

Please take a look at the below GIF, I am using VS Code in Windows and using Ctrl + K, Ctrl + 0 to collapse all regions of code


More VS Code Shortcuts in Windows related to code collapse

Ctrl + K, Ctrl + 0: fold all levels (namespace, class, method, and block)
Ctrl + K + 1: namspace
Ctrl + K + 2: class
Ctrl + K + 3: methods
Ctrl + K + 4: blocks
Ctrl + K + [ or Ctrl + k + ]: current cursor block
Ctrl + K + j: UnFold

You should also have VS Code user settings, Fold enabled, which you can check using JSON settings

    "editor.showFoldingControls": "always",
    "editor.folding": true,
    "editor.foldingStrategy": "indentation", 

That's it.

At:- 1/6/2023 4:06:59 PM
Great answer, it helped me today. 0
By : bhanu - at :- 1/17/2023 9:06:24 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly