Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make folding regions folded by default in VS Code?

Is it possible to close all closable code segments of some kind in VS Code?

For example I want all my style property code segments to be closed by default and only open them when they are hovered. Is this possible? They get extremely huge and make a component unreadable.

like image 781
Allleex Avatar asked Oct 15 '25 09:10

Allleex


1 Answers

Not that I know of (without using extensions). But you can get pretty close.

You can fold (collapse) all folding regions in an editor by using the Fold All command in the command palette, or whatever keyboard shortcut that command is bound to by default. On Windows and Linux, it's bound to ctrl+k,cltr+o. I assume that on macOS, you just switch ctrl in the previous shortcut with cmd. VS Code remembers things about the workspace state like which folding regions are folded or not folded. It will recall that info when reopening a closed editor tab, or reopening the workspace.


If you're opening to trying extensions, try @rioV8's rioj7.commandOnAllFiles (I have no affiliation with this extension) (see also How to execute command across multiple files in VS Code?), where usage might look something like this:

settings.json:

  "commandOnAllFiles.commands": {
    "Fold All Folding Regions": {
      "command": "editor.foldAll"
    }
  }

keybindings.json:

  {
    "key": "ctrl+i o", // or any other key combo
    "command": "commandOnAllFiles.applyOnWorkspace",
    "args": ["Fold All Folding Regions"]
  }
like image 140
starball Avatar answered Oct 19 '25 14:10

starball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!