https://code.visualstudio.com/docs/editor/variables-reference
Predefined variables
The following predefined variables are supported:
- ${workspaceFolder} - the path of the folder opened in VS Code
- ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
- ${file} - the current opened file
- ${relativeFile} - the current opened file relative to
workspaceFolder
- ${relativeFileDirname} - the current opened file's dirname relative to
workspaceFolder
- ${fileBasename} - the current opened file's basename
- ${fileBasenameNoExtension} - the current opened file's basename with no file extension
- ${fileDirname} - the current opened file's dirname
- ${fileExtname} - the current opened file's extension
- ${cwd} - the task runner's current working directory on startup
- ${lineNumber} - the current selected line number in the active file
- ${selectedText} - the current selected text in the active file
- ${execPath} - the path to the running VS Code executable
- ${defaultBuildTask} - the name of the default build task
Predefined variables examples
Supposing that you have the following requirements:
- A file located at
/home/your-username/your-project/folder/file.ext
opened in your editor; - The directory
/home/your-username/your-project
opened as your root workspace.
So you will have the following values for each variable:
- ${workspaceFolder} -
/home/your-username/your-project
- ${workspaceFolderBasename} -
your-project
- ${file} -
/home/your-username/your-project/folder/file.ext
- ${relativeFile} -
folder/file.ext
- ${relativeFileDirname} -
folder
- ${fileBasename} -
file.ext
- ${fileBasenameNoExtension} -
file
- ${fileDirname} -
/home/your-username/your-project/folder
- ${fileExtname} -
.ext
- ${lineNumber} - line number of the cursor
- ${selectedText} - text selected in your code editor
- ${execPath} - location of Code.exe
Tip: Use IntelliSense inside string values for
tasks.json
andlaunch.json
to get a full list of predefined variables.
Variables scoped per workspace folder
By appending the root folder's name to a variable (separated by a colon), it is possible to reach into sibling root folders of a workspace. Without the root folder name, the variable is scoped to the same folder where it is used.
For example, in a multi root workspace with folders Server
and Client
, a ${workspaceFolder:Client}
refers to the path of the Client
root.