If you only need the $PATH to be set in the integrated terminal, you can use VS Code's terminal.integrated.env.<platform> setting (added in version 1.15). Find the setting for your platform in the settings, click "Edit in settings.json", and add a "PATH" field like so:
"terminal.integrated.env.osx": {
"PATH": "${env:PATH}:/my/path"
}
(Replace .osx with .linux or .windows as needed.)
The expression ${env:PATH} causes the existing contents of the $PATH environment variable to be inserted. This way you can extend it without hard-coding it.
As for having the $PATH available everwhere in VS Code, so that it will
be used by extensions that call binaries, the only workaround I've found so far is this:
Configure your shell to have the
$PATHyou want. For example, I'm using Bash, and my~/.bash_profilehas the following line:PATH="$PATH:$HOME/bin"In VS Code, press ⇧⌘P and type
install 'code' commandif you haven't done so before.Quit VS Code.
Launch VS Code not by clicking its icon in the dock, but by opening Terminal.app and typing
code. Your newly set path will be active in VS Code until you quit it.If VS Code restarts, for example due to an upgrade, the
$PATHwill reset to the system default. In that case, quit VS Code and re-launch it by typingcode.
Update: VS Code on Mac and Linux now apparently tries to automatically resolve the shell environment when it is started by clicking the icon (rather than via code). It does this by temporarily starting a shell and reading the environment variables. I haven't tested this though.
If you only need the $PATH to be set in the integrated terminal, you can use VS Code's terminal.integrated.env.<platform> setting (added in version 1.15). Find the setting for your platform in the settings, click "Edit in settings.json", and add a "PATH" field like so:
"terminal.integrated.env.osx": {
"PATH": "${env:PATH}:/my/path"
}
(Replace .osx with .linux or .windows as needed.)
The expression ${env:PATH} causes the existing contents of the $PATH environment variable to be inserted. This way you can extend it without hard-coding it.
As for having the $PATH available everwhere in VS Code, so that it will
be used by extensions that call binaries, the only workaround I've found so far is this:
Configure your shell to have the
$PATHyou want. For example, I'm using Bash, and my~/.bash_profilehas the following line:PATH="$PATH:$HOME/bin"In VS Code, press ⇧⌘P and type
install 'code' commandif you haven't done so before.Quit VS Code.
Launch VS Code not by clicking its icon in the dock, but by opening Terminal.app and typing
code. Your newly set path will be active in VS Code until you quit it.If VS Code restarts, for example due to an upgrade, the
$PATHwill reset to the system default. In that case, quit VS Code and re-launch it by typingcode.
Update: VS Code on Mac and Linux now apparently tries to automatically resolve the shell environment when it is started by clicking the icon (rather than via code). It does this by temporarily starting a shell and reading the environment variables. I haven't tested this though.
In:
> Preferences: Open Settings (JSON)
add to the JSON file:
"terminal.integrated.env.windows": {
"PATH": "${env:PATH}"
},
-> terminal.integrated.env should end with .osx, .linux or .windows depending on your OS.
In order to check if it works execute in your VS Code Terminal:
# For PowerShell
echo $env:PATH
# For bash
echo "$PATH"
When I open Visual Studio Code, the default path in Terminal is C:\Users\MyPCUser
If I type Code newfile.py , then the file is created in above path. While I would like to have the file in a designated Python folder.
How to change above default path to a python folder?
Changing the default path of Visual Studio Code's integrated terminal - Stack Overflow
windows - Location of VS Code preferences - Stack Overflow
VSCode Path setup
Specifying C Compiler Path in Visual Studio Code
Short answer
Edit the user preference "terminal.integrated.cwd": "" to the path that you want the integrated terminal to open to.
Long answer
The same answer, but the long step-by-step version,
In Visual Studio Code go to:
Menu File → Preferences → Settings
Now that you are in the "User Settings", using the "Search Settings" bar across the top of the window paste or type this:
terminal.integrated.cwd
It will list the following as a result:
// An explicit start path where the terminal will be launched, this is used
as the current working directory (cwd) for the shell process. This may be
particularly useful in workspace settings if the root directory is not a
convenient cwd.
"terminal.integrated.cwd": "",
You will notice that it will not let you type here to change this setting. That is because you can't change the default setting. You instead need to change your personal settings. Here's how...
Click the pencil icon to the left of the this option and then the "Copy to Settings" option that pops-up.
You should have a split screen in which the right side of the screen has the heading Place your settings here to overwrite the Default Settings. This is the correct place for you to make changes. You might already have a few personalized settings listed here.
When you clicked "Copy to Settings" it automatically added this line for you:
"terminal.integrated.cwd": ""
Notice that whichever item is last in this list will not have a trailing comma but any items before it in the list will require one.
FYI: you could have simply typed or copy/pasted this into the personalized settings yourself, but following these steps is the process to learn for changing other preferences as needed.
Now you are able to type to set the path you want to use. Make sure to use \\ in place of \ and you do not need the trailing \. For example including this line would always start your terminal in the baz directory:
{
"terminal.integrated.cwd": "C:\\Users\\foo\\bar\\baz"
}
To apply the change, simply Save and restart Visual Studio Code.
As others have already explained, you can add a setting to change the default folder for your integrated terminal to start in. This setting also accepts Visual Studio Code variables, so to make a relative path from the root folder of your workspace you can use ${workspaceFolder}.
For example, for your terminal to always start in the subfolder mystart, your setting would be:
"terminal.integrated.cwd": "${workspaceFolder}/mystart"
According to Microsoft Docs: Settings file locations:
By default VS Code shows the Settings editor, but you can still edit the underlying settings.json file by using the Open Settings (JSON) command or by changing your default settings editor with the workbench.settings.editor setting.
Depending on your platform, the user settings file is located here:
- Windows
%APPDATA%\Code\User\settings.json- macOS
$HOME/Library/Application Support/Code/User/settings.json- Linux
$HOME/.config/Code/User/settings.jsonThe workspace setting file is located under the .vscode folder in your root folder.
Note: In case of a Multi-root Workspace, workspace settings are located inside the workspace configuration file.
According to Microsoft Docs: Persisted Zoom Level the entry you are looking for is: window.zoomLevel
For Mac users, it's:
/Users/{username}/Library/Application Support/Code/User/
and if you have a profile created in VS Code Profiles:
/Users/{username}/Library/Application Support/Code/User/profiles/{profileNumber}/
It's hidden, so try to directly do a "Go to folder" from Finder app.