Does VS Code have the ability to be controlled with a script?

Viewed 25

There's a task I do every day multiple times.

  • Start with no files open for my project.
  • Press Cmd-1, then Cmd-2, then Cmd-3 to create three editors.
  • Open my CSS file, which places it in the third section.
  • Press Cmd-2 and then place the HTML file in that section.
  • Press Cmd-3 and open my JS file there.

I'm moving from component to component, doing this each time. Can VS Code be scripted so that I could, perhaps, select the three files, and have VS Code get me to the final state I want?

2 Answers

I have written an extension command for that, and more: File Group Scripts

Your use case could be scripted with the following setting:

  "fileGroup.scripts": {
    "open side by side (HTML,CSS,*)": {
      "script": [
        { "command": "workbench.action.focusFirstEditorGroup" },
        { "file": "all;\\.x?html$",
          "command": "htmlRelatedLinks.openFile",
          "args": { "file": "${file}"}
        },
        { "command": "workbench.action.focusSecondEditorGroup" },
        { "file": "all;\\.css$",
          "command": "htmlRelatedLinks.openFile",
          "args": { "file": "${file}"}
        },
        { "command": "workbench.action.focusThirdEditorGroup" },
        { "file": "all",
          "command": "htmlRelatedLinks.openFile",
          "args": { "file": "${file}"}
        }
      ],
      "interval": 500
    }
  }

You could save each combination of files as a workspace (File -> Save Workspace As... / Workspaces: Save Workspace As... command) and switch between those.

Workspaces appear in the "recently opened" list, so they can be easily recalled by pressing Ctrl+R.

Related