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.
Fold or Collapse All:
Ctrl + K, Ctrl + 0
Unfold or Expand All:
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.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly