visual studio code – How to create a workspace

visual studio code – How to create a workspace

I had your same question, but the answer is simple, you dont. There is no need to start a blank workspace. To start on a new project use Open Folder from the File menu: navigate to the project, create a folder if needed, and then select the folder. You are now working on any files within that folder as if it were a workspace. If you leave and open another folder or workspace with files still open in editors, those files will be open when you open that folder again. Visual Studio Code making things work effortlessly! Until you do something that specifically requires a workspace you dont have to save it. If you save a workspace with no settings changed to the root folder heres what it looks like: {folders: [{path: .}],settings: {}}. Thats it. The open editors are saved internally regardless of whether you saved as workspace. Starting by saving a blank workspace is like having an empty file cabinet in your office. VSCode will inform you if you ever need that and you can save a workspace then.

I finally had a chance to use VSC on a Mac. The difference on a Mac is
that Open File and Open Folder are under the same general Open
command (apparently because Macs use the same browser to select files and folders). Just use that to Open a folder, and open files in that folder workspace using the VSC explorer. All this still applies. The folder is the workspace.

You only need to save that workspace if you want to Add Folder to Workspace (in which case VSC will prompt you to save your multiroot workspace if you exit, or if you want to save settings specific to your project folder (though you can do that without a workspace using a settings json in a .vscode folder within). Even then VSC will auto save workspace settings for the folder internally when you havent explicitly made the project folder a workspace.

Do you need a workspace and the extra .code-workspace file involved? If you have multiple root folders its certainly nice to open the workspace and have those all there in your next session. If its just for settings for a project with one root its not needed (maybe if you want a file you can share with others on the project), and if the reason you are changing settings per project is language related then it may make far more sense to add language settings to your main settings file and have them in effect every time you work on that kind of project.

In short every time you use Open Folder workbench.action.files.openFolder you are essentially switching to another workspace.


In the folder you want to add to your workspace, create a file {foldername}.code-workspace and in the file put in the following code.

    folders: [
            path: .

Save and close the file. Back in Visual Studio Code, click menu FileOpen Workspace… and select the .code-workspace file you created and it will open it as a new workspace without having to add a folder to an existing workspace.

visual studio code – How to create a workspace

In the File menu choose Open Folder…. Select a folder. You can add folders to the workspace using File | Add Folder to Workspace….

Optionally, also go to File | Preferences | Settings. The User Settings tab will be open by default. Look for the Workspace Settings tab and select it. Modify a setting, such as change the theme.

Then you can save the workspace using Save in the File menu.

When you close the workspace using Close Workspace in the File menu then if you changed the theme for the workspace then the theme should revert to the global theme. When you re-open the workspace VS Code will open the folder(s) that were added to the workspace and apply whatever settings that were specified for the workspace. There are a few settings that are ignored for workspaces for security reasons but all other settings can be overridden in workspaces.

It is possible to add multiple projects to a workspace; see Multi-root Workspaces.

Leave a Reply

Your email address will not be published.