Variables reference
Visual Studio Code supports variable substitution in Debugging and Task configuration files, and for some select settings. Variable substitution is supported inside some key and value strings in launch.json and tasks.json files by using the ${variableName} syntax.
Predefined variables
The following predefined variables are supported:
| Variable | Description |
|---|---|
| ${userHome} | Path of the user's home folder |
| ${workspaceFolder} | Path of the folder opened in VS Code |
| ${workspaceFolderBasename} | Name of the folder opened in VS Code without any slashes (/) |
| ${file} | Currently opened file |
| ${fileWorkspaceFolder} | Currently opened file's workspace folder |
| ${relativeFile} | Currently opened file relative to workspaceFolder |
| ${relativeFileDirname} | Currently opened file's dirname relative to workspaceFolder |
| ${fileBasename} | Currently opened file's basename |
| ${fileBasenameNoExtension} | Currently opened file's basename with no file extension |
| ${fileExtname} | Currently opened file's extension |
| ${fileDirname} | Currently opened file's folder path |
| ${fileDirnameBasename} | Currently opened file's folder name |
| ${cwd} | Task runner's current working directory upon the startup of VS Code |
| ${lineNumber} | Currently selected line number in the active file |
| ${columnNumber} | Currently selected column number in the active file |
| ${selectedText} | Currently selected text in the active file |
| ${execPath} | Path to the running VS Code executable |
| ${defaultBuildTask} | Name of the default build task |
| ${pathSeparator} | Character used by the operating system to separate components in file paths |
| ${/} | Shorthand for ${pathSeparator} |
Predefined variables example
Suppose that you have the following conditions:
- A file located at
/home/your-username/your-project/folder/file.extopened in your editor; - The directory
/home/your-username/your-projectopened as your root workspace.
This leads to the following values for each of the variables:
- ${userHome}:
/home/your-username - ${workspaceFolder}:
/home/your-username/your-project - ${workspaceFolderBasename}:
your-project - ${file}:
/home/your-username/your-project/folder/file.ext - ${fileWorkspaceFolder}:
/home/your-username/your-project - ${relativeFile}:
folder/file.ext - ${relativeFileDirname}:
folder - ${fileBasename}:
file.ext - ${fileBasenameNoExtension}:
file - ${fileExtname}:
.ext - ${fileDirname}:
/home/your-username/your-project/folder - ${fileDirnameBasename}:
folder - ${lineNumber}: line number of the cursor
- ${columnNumber}: column number of the cursor
- ${selectedText}: text selected in your code editor
- ${execPath}: location of Code.exe
- ${pathSeparator}:
/on macOS or linux,\on Windows
Use IntelliSense inside string values for tasks.json and launch.json to get a full list of predefined variables.
Platform and workspace considerations
Platform-specific behavior
Some predefined variables may resolve differently depending on the operating system:
- On Windows, file paths use backslashes (
\). When composing paths in JSON files such astasks.jsonorlaunch.json, ensure backslashes are properly escaped (for example:"${workspaceFolder}\\subdir"). - On macOS and Linux, file paths use forward slashes (
/).
It's recommended to use ${pathSeparator} or ${/} to make configurations portable across platforms.
Variables that contain spaces
Variable substitution replaces a variable with its string value. It doesn't add quotes or split the result on spaces. The configuration property that contains the variable determines how the resolved value is interpreted.
For an array property such as args in many launch.json configurations, define each argument as a separate array element. A variable-based path that contains spaces remains one string in its array element:
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js",
"args"