Environment variables in Linux are supported now in VSCode (although I don't know since when or which version exactly). I have VSCode for Linux 1.73.1.
You can now use the following (just like in the question above):
{
"java.home": "${env:HOME}/.sdkman/candidates/java/8.0.222.hs-adpt/"
}
Answer from Hechi on Stack OverflowEnvironment Variable interpolation in settings.json
Support using environment variables in settings.json
environment variables no longer valid in workspace settings.json or tasks.json
Using environmental variable in settings.json
Videos
Could anyone tell me why this doesn't work?
{
"roc-lang.language-server.exe": "${env:ROC_LANGUAGE_SERVER_PATH}",
// If you'd like to format Roc files on save
"editor.formatOnSave": true
}This is in the workspace settings.json for a project. When I look at the plugin's output, it's treating that exact string as the path, rather than resolving it to the value of the environmental variable. A few other things to note:
-
If I instead use the literal string that is the value of the variable, it works fine.
-
I am able to echo that variable in vs code's terminal, so I know it's available.
-
I am on on linux with a reasonably recent version of vs code.
Thanks.
EDIT: Maybe this is just a limitation of the roc language plugin, that it isn't programmed to resolve the variable?
I am trying to override the default python interpreter for a specific workspace. I have created a .vscode directory in the folder with the following two files:
settings.json:
{
"python.envFile": "${workspaceFolder}/.vscode/.env",
"python.defaultInterpreterPath": "${env:MY_PYTHON_PATH}/bin/python",
}.vscode/.env:
MY_PYTHON_PATH=/path/to/my/python/interpreter
But the python interpreter is actually getting set to /bin/python - which implies that ${env:MY_PYTHON_PATH} is just empty.
Any ideas what is going wrong here?
Currently you cannot set variables in the settings.json file.
The current open issue for VS Code to implement this feature is here: https://github.com/microsoft/vscode/issues/2809
It has yet to have a PR and the opening of the issue occurred Feb 2016, but with comments within the last 2 months.
Quoting from the same docs which were linked in the question post (asker just needed to scroll down) https://code.visualstudio.com/docs/editor/variables-reference#_is-variable-substitution-supported-in-user-and-workspace-settings :
Is variable substitution supported in User and Workspace settings?
The predefined variables are supported in a select number of setting keys in
settings.jsonfiles such as the terminalcwd,env,shellandshellArgsvalues. Some settings likewindow.titlehave their own variables:"window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}"Refer to the comments in the Settings editor (
Ctrl+,) to learn about setting specific variables.
Even quoting from the very first sentence in that entire document:
Visual Studio Code supports variable substitution in Debugging and Task configuration files as well as some select settings. Variable substitution is supported inside some key and value strings in
launch.jsonandtasks.jsonfiles using${variableName}syntax.
If you want to be able to use variables freely in settings.json, then see Support variables when resolving values in settings #2809, give it a thumbs up to show support for it, and subscribe to it to get notified about discussion and progress. Please avoid making comments there like "+1" / "bump" / "still not implemented??!!1?!?1".