How can I set the default working directory when opening a new terminal with VS Code?
Asked Answered
M

3

7

I'm using Visual Studio Code with the integrated terminal.

When opening a new terminal in a workspace with multiple folders, I always receive a prompt saying:

Select current working directory for new terminal

How do I remove this prompt i.e. Set the default to always use the directory of the first folder?

Moreen answered 4/2, 2021 at 7:42 Comment(0)
L
1

I'm pretty sure you can do this using the terminal.integrated.cwd setting. You can set it in your user settings.json file or your workspace's .vscode/settings.json file.

It supports variable substitution. See the list of available variables here: https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables.

Some examples of variables you can use: ${workspaceFolder}, ${fileWorkspaceFolder}, ${fileDirname}, ${selectedText}.

It seems that not all the directory variables are supported. For example, userHome doesn't work for me on my machine.

See also the terminal.integrated.splitCwd setting.

You may also be interested in the workbench.action.terminal.newInActiveWorkspace keybinding command.


If the terminal is opened for a task, then use the task's options property object's cwd property (docs).

Lilongwe answered 14/2, 2023 at 1:2 Comment(0)
C
0

I've tried using the terminal.integrated.cwd option, but it still prompts me to Select current working directory for new terminal every time I create a new terminal.

To achieve what you intended, you can set a keyboard shortcut for Terminal: Create New Terminal (In Active Workspace) (workbench.action.terminal.newInActiveWorkspace). It behaves similar to the default one but creates a new terminal without asking for the current working directory if you are within a workspace.

It's a convenient way, but keep in mind that the current working directory will be based on the workspace where your active (focused) editor is located.

Carburize answered 15/6, 2024 at 8:14 Comment(0)
S
0

Select File> preferences>settings at command prompt type terminal.integrated.Cwd type location default you should select C:\Users\computer name

good luck

Stephenstephenie answered 16/9, 2024 at 9:8 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.