Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 40 ยท Getting Started

Opening Folders and Workspaces

Understand the difference between a folder and a workspace in VS Code, create multi-root workspaces, use .vscode settings, recent projects and Workspace Trust.

VS Code is designed around folders. When you open a project folder, the Explorer shows its files, search covers it, the terminal starts inside it and settings can be stored with it. This lesson explains the three ways of opening work: a single file, a folder and a multi-root workspace, and how Workspace Trust keeps unknown code from running automatically.

Files versus folders

You can open one file (code notes.txt), but most tools want a project root:

  • Git integration needs a folder that contains (or sits inside) a repository.
  • Search, Quick Open and the file watcher all use the opened folder as their scope.
  • Debug configurations and tasks live in a .vscode folder inside the project.
  • Language extensions use files like package.json or pyproject.toml to discover your project.

Open a folder with File > Open Folder (Ctrl+K Ctrl+O), by dragging a folder onto the window, or with code . from a terminal.

The Explorer

The Explorer view (Ctrl+Shift+E) shows the folder tree. Useful actions:

  • New File / New Folder icons at the top, or right-click in the tree. Typing src/utils/math.js as a file name creates missing folders automatically.
  • F2 renames the selected file; Delete moves it to the trash.
  • Ctrl+C / Ctrl+V copies files inside the tree; drag and drop moves them.
  • Reveal in File Explorer (Finder on macOS) opens the location in your operating system.
  • Outline and Timeline panels at the bottom show the symbols of the open file and its local history.

Files you do not want to see can be hidden with the files.exclude setting, for example "**/node_modules": true. Search has its own search.exclude. See Settings: UI and JSON.

The .vscode folder

Project-specific configuration lives in .vscode/ at the folder root:

File Purpose
settings.json Settings that apply only to this folder
launch.json Debug configurations (launch.json)
tasks.json Build and run tasks
extensions.json Recommended extensions for the project

Teams often commit .vscode to Git so everyone gets the same formatter and recommended extensions. Keep personal preferences, such as fonts and themes, in your user settings rather than the shared file.

Multi-root workspaces

Sometimes one window needs several folders, for example a frontend and a backend that live in different repositories. Choose File > Add Folder to Workspace and VS Code switches to a multi-root workspace: the Explorer lists each folder as a root, search covers all of them, and each root can have its own .vscode settings.

Save it with File > Save Workspace As to create a .code-workspace file. It is JSON:

JSON
{
  "folders": [
    { "path": "frontend" },
    { "path": "backend", "name": "API" }
  ],
  "settings": {
    "editor.tabSize": 2
  }
}

Open the file later with File > Open Workspace from File, or double-click it. The paths are relative to the file, so keep it next to or above the folders it lists. Settings inside "settings" apply to the whole workspace.

A stand-in: how roots and paths resolve

This JavaScript model resolves the folders listed in a workspace file relative to its location. It runs on plain strings, not real files.

JS Stand-in: resolving workspace folders

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The third root shows why relative paths are handy: ../shared-lib climbs out of the workspace file's directory.

Recent projects and quick switching

  • File > Open Recent lists folders and workspaces you opened before.
  • Ctrl+R opens the same list as a quick pick; type to filter, press Enter to switch.
  • Ctrl+Shift+N opens a new window; Ctrl+W closes the folder in the window.
  • The window.restoreWindows setting controls what comes back on start (all, folders, none).

Many people keep one window per project. Use Ctrl+K Ctrl+O to open a different folder in the current window, or use code -n path to open a new one.

Workspace Trust

VS Code can run code from the project you open: tasks, debug configurations, extensions that read project files, even scripts in package.json. To protect you from malicious repositories, VS Code asks the first time you open a folder: Do you trust the authors of the files in this folder?

  • Yes, I trust the authors enables everything.
  • No, I don't trust the authors starts Restricted Mode. Tasks, debugging, workspace settings that can run code and some extension features are disabled, and a banner explains what is limited.

You can change the decision later through the Command Palette with Workspaces: Manage Workspace Trust. Trusting a parent folder (such as ~/projects) also trusts everything below it, so choose carefully. Use Restricted Mode when you only want to read code you downloaded from an unknown source.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where are project-specific VS Code settings stored?

    Workspace folder settings live in .vscode/settings.json and apply only to that project.
  2. 2. What is a multi-root workspace?

    A multi-root workspace lists several folders and optional shared settings in a .code-workspace JSON file.
  3. 3. What happens when you choose not to trust a folder?

    Restricted Mode limits tasks, debugging and some extensions so unknown code cannot run automatically.
  4. 4. Which shortcut opens the Explorer view?

    Ctrl+Shift+E shows Explorer; X is Extensions, G is Source Control and D is Run and Debug.

Summary

  • Open projects as folders (code .) so search, Git and settings know the project root.
  • .vscode/ holds settings.json, launch.json, tasks.json and extensions.json.
  • Multi-root workspaces combine several folders in one .code-workspace JSON file.
  • Recent projects are one shortcut away (Ctrl+R).
  • Workspace Trust and Restricted Mode protect you from unknown code.

Next: The Command Palette