0

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Allleex
  • 137
  • 9
  • This might be possible but you need to show what a code segment you are interested in folding looks like to help. – Mark Apr 22 '23 at 20:38

1 Answers1

1

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"]
  }
starball
  • 20,030
  • 7
  • 43
  • 238