Visual Studio Code Variables Reference (2023)

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.json and tasks.json files using ${variableName} syntax.

Predefined variables

The following predefined variables are supported:

  • ${userHome} - the path of the user's home folder
  • ${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
  • ${fileWorkspaceFolder} - the current opened file's workspace folder
  • ${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
  • ${fileExtname} - the current opened file's extension
  • ${fileDirname} - the current opened file's folder path
  • ${fileDirnameBasename} - the current opened file's folder name
  • ${cwd} - the task runner's current working directory upon the startup of VS Code
  • ${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
  • ${pathSeparator} - the character used by the operating system to separate components in file paths

Predefined variables examples

Supposing that you have the following requirements:

  1. A file located at /home/your-username/your-project/folder/file.ext opened in your editor;
  2. The directory /home/your-username/your-project opened as your root workspace.

So you will have the following values for each variable:

  • ${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
  • ${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
  • ${pathSeparator} - / on macOS or linux, \ on Windows

Tip: Use IntelliSense inside string values for tasks.json and launch.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.

Environment variables

You can also reference environment variables through the ${env:Name} syntax (for example, ${env:USERNAME}).

{ "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}/app.js", "cwd": "${workspaceFolder}", "args": ["${env:USERNAME}"]}

Configuration variables

You can reference VS Code settings ("configurations") through ${config:Name} syntax (for example, ${config:editor.fontSize}).

Command variables

If the predefined variables from above are not sufficient, you can use any VS Code command as a variable through the ${command:commandID} syntax.

A command variable is replaced with the (string) result from the command evaluation. The implementation of a command can range from a simple calculation with no UI, to some sophisticated functionality based on the UI features available via VS Code's extension API. If the command returns anything other than a string, then the variable replacement will not complete. Command variables must return a string.

An example of this functionality is in VS Code's Node.js debugger extension, which provides an interactive command extension.pickNodeProcess for selecting a single process from the list of all running Node.js processes. The command returns the process ID of the selected process. This makes it possible to use the extension.pickNodeProcess command in an Attach by Process ID launch configuration in the following way:

{ "configurations": [ { "type": "node", "request": "attach", "name": "Attach by Process ID", "processId": "${command:extension.pickNodeProcess}" } ]}

When using a command variable in a launch.json configuration, the enclosing launch.json configuration is passed as an object to the command via an argument. This allows commands to know the context and parameters of the specific launch.json configuration when they are called.

Input variables

Command variables are already powerful but they lack a mechanism to configure the command being run for a specific use case. For example, it is not possible to pass a prompt message or a default value to a generic "user input prompt".

This limitation is solved with input variables which have the syntax: ${input:variableID}. The variableID refers to entries in the inputs section of launch.json and tasks.json, where additional configuration attributes are specified. Nesting of input variables is not supported.

The following example shows the overall structure of a tasks.json that makes use of input variables:

{ "version": "2.0.0", "tasks": [ { "label": "task name", "command": "${input:variableID}" // ... } ], "inputs": [ { "id": "variableID", "type": "type of input variable" // type specific configuration attributes } ]}

Currently VS Code supports three types of input variables:

  • promptString: Shows an input box to get a string from the user.
  • pickString: Shows a Quick Pick dropdown to let the user select from several options.
  • command: Runs an arbitrary command.

Each type requires additional configuration attributes:


  • description: Shown in the quick input, provides context for the input.
  • default: Default value that will be used if the user doesn't enter something else.
  • password: Set to true to input with a password prompt that will not show the typed value.


  • description: Shown in the quick pick, provides context for the input.
  • options: An array of options for the user to pick from.
  • default: Default value that will be used if the user doesn't enter something else. It must be one of the option values.

An option can be a string value or an object with both a label and value. The dropdown will display label: value.


  • command: Command being run on variable interpolation.
  • args: Optional option bag passed to the command's implementation.

Below is an example of a tasks.json that illustrates the use of inputs using Angular CLI:

{ "version": "2.0.0", "tasks": [ { "label": "ng g", "type": "shell", "command": "ng", "args": ["g", "${input:componentType}", "${input:componentName}"] } ], "inputs": [ { "type": "pickString", "id": "componentType", "description": "What type of component do you want to create?", "options": [ "component", "directive", "pipe", "service", "class", "guard", "interface", "enum" ], "default": "component" }, { "type": "promptString", "id": "componentName", "description": "Name your component.", "default": "my-new-component" } ]}

Running the example:

Visual Studio Code Variables Reference (1)

The following example shows how to use a user input variable of type command in a debug configuration that lets the user pick a test case from a list of all test cases found in a specific folder. It is assumed that some extension provides an extension.mochaSupport.testPicker command that locates all test cases in a configurable location and shows a picker UI to pick one of them. The arguments for a command input are defined by the command itself.

{ "configurations": [ { "type": "node", "request": "launch", "name": "Run specific test", "program": "${workspaceFolder}/${input:pickTest}" } ], "inputs": [ { "id": "pickTest", "type": "command", "command": "extension.mochaSupport.testPicker", "args": { "testFolder": "/out/tests" } } ]}

Command inputs can also be used with tasks. In this example, the built-in Terminate Task command is used. It can accept an argument to terminate all tasks.

{ "version": "2.0.0", "tasks": [ { "label": "Terminate All Tasks", "command": "echo ${input:terminate}", "type": "shell", "problemMatcher": [] } ], "inputs": [ { "id": "terminate", "type": "command", "command": "workbench.action.tasks.terminate", "args": "terminateAll" } ]}

Common questions

Details of variable substitution in a debug configuration or task

Variable substitution in debug configurations or tasks is a two pass process:

  • In the first pass, all variables are evaluated to string results. If a variable occurs more than once, it is only evaluated once.
  • In the second pass, all variables are substituted with the results from the first pass.

A consequence of this is that the evaluation of a variable (for example, a command-based variable implemented in an extension) has no access to other substituted variables in the debug configuration or task. It only sees the original variables. This means that variables cannot depend on each other (which ensures isolation and makes substitution robust against evaluation order).

Is variable substitution supported in User and Workspace settings?

The predefined variables are supported in a select number of setting keys in settings.json files such as the terminal cwd, env, shell and shellArgs values. Some settings like window.title have their own variables:

 "window.title": "${dirty}${activeEditorShort}${separator}${rootName}${separator}${appName}"

Refer to the comments in the Settings editor (⌘, (Windows, Linux Ctrl+,)) to learn about setting specific variables.

Why isn't ${workspaceRoot} documented?

The variable ${workspaceRoot} was deprecated in favor of ${workspaceFolder} to better align with Multi-root Workspace support.

Why aren't variables in tasks.json being resolved?

Not all values in tasks.json support variable substitution. Specifically, only command, args, and options support variable substitution. Input variables in the inputs section will not be resolved as nesting of input variables is not supported.

How can I know a variable's actual value?

One easy way to check a variable's runtime value is to create a VS Code task to output the variable value to the console. For example, to see the resolved value for ${workspaceFolder}, you can create and run (Terminal > Run Task) the following simple 'echo' task in tasks.json:

{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "echo ${workspaceFolder}" } ]}



How do I enable find all references in Visual Studio Code? ›

The Find All References command is available on the context (right-click) menu of the element you want to find references to. Or, if you're a keyboard user, press Shift + F12.

How do you change all occurrences of variable name in VS Code? ›

Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.

How to set env variable in Visual Studio Code? ›

  1. Open the start search.
  2. Type in “env” and choose “Edit the system environment variables”
  3. Choose “Environment Variables…”
  4. Set the environment variables: MSYSTEM=MINGW64. CHERE_INVOKING=1. Add C:\msys64\usr\bin to PATH.

How do I see the value of a variable in Visual Studio Code? ›

Display a data tip

Set a breakpoint in your code, and start debugging by pressing F5 or selecting Debug > Start Debugging. When paused at the breakpoint, hover over any variable in the current scope. A data tip appears, showing the name and current value of the variable.

How do I fix missing references in Visual Studio? ›

To fix a broken project reference, correct the reference path by following these steps: In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then select Reference Paths .

How do I find unnecessary references in Visual Studio? ›

Right click on a project name or dependencies node in Solution Explorer. Select Remove Unused References. The Remove Unused References dialog will open displaying references that have no usage in source code.

How do you select all the same variables in VS Code? ›

Multiple selections (multi-cursor)
  1. Ctrl+D selects the word at the cursor, or the next occurrence of the current selection.
  2. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text. ...
  3. Column (box) selection.

How do I select all variables with the same name in VS Code? ›

Shift+Ctrl+L will select all the reference of a1. And Ctrl+D will select the next reference.

How do I replace all instances in Visual Studio? ›

You can access replacement options by choosing the button next to the Find text box. To make one replacement at a time, choose the Replace Next button next to the Replace text box. To replace all matches, choose the Replace All button.

How do I set environment path variables? ›

  1. In Search, search for and then select: System (Control Panel)
  2. Click the Advanced system settings link.
  3. Click Environment Variables. ...
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. ...
  5. Reopen Command prompt window, and run your java code.

How do I change Environment Variables in code? ›

Update environment variables
  1. Go to Power Apps, and then select your CoE environment.
  2. Open the CoE Admin Command Center app.
  3. Select Environment Variables, and update the current value.
Feb 8, 2023

How do I find all instances of a variable in Visual Studio? ›

Press Ctrl-K then Ctrl-R, this will find all references to the method (or object, variable, etc.) This may apply only to Productivity power tools, though.

How to see value of Environment Variables in Visual Studio? ›

In Visual Studio, we can set ASPNETCORE_ENVIRONMENT in the debug tab of project properties. Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below.

How do you check the value within a variable? ›

To check if a variable contains a value that is a string, use the isinstance built-in function. The isinstance function takes two arguments. The first is your variable. The second is the type you want to check for.

How do I add references to Visual Studio code? ›

  1. Click on NuGet Package Manager: Add Package.
  2. Enter package filter e.g. (Enter your assembly reference here)

How to add a DLL reference to a project in Visual Studio Code? ›

Referencing DLLs
  1. In the Solution Explorer pane, right-click your project, then click Add Reference.
  2. In the Add Reference window, click the Browse tab.
  3. In the drop-down list, find the folder for FileNet. ...
  4. Select the DLL file.
  5. Click OK.

How do I add references to Visual Studio solution? ›

Add a reference
  1. In Solution Explorer, right-click the References or Dependencies node, and then choose either Add Project Reference, Add Shared Project Reference, or Add COM Reference from the context menu. ...
  2. Select a reference to add, and then select OK.
Mar 9, 2023

How do I remove unnecessary usings in Visual Studio? ›

CTRL + K + E Will sort and remove your unused usings.

How do I remove unused imports in Visual Studio code? ›

  1. Open the Command Palette ( Ctrl/Cmd + Shift + P )
  2. Search for Remove Unused Imports.
Jan 10, 2023

What is Ctrl KD in Visual Studio code? ›

Currently it is assigned to "Move last selection to next find match", but you can easily assign it for formatting code.
  • File > Preferences > Keyboard shortcuts (or CTRL + K, CTRL, + S.
  • Search for "Format Document", or "editor.action.formatDocument" and re assign the keyboard shortcut to CTRL + K, CTRL + D.
Jan 19, 2018

How do you select all occurrences of find match? ›

Ctrl + Shift + L to select all items that match.

How to assign the same value to all three variables in one code line? ›

You can assign the same value to multiple variables by using = consecutively. For example, this is useful when initializing multiple variables with the same value.

How do you select multiple variables in VS? ›

17 Answers
  1. Ctrl + Alt + click : Add a secondary caret.
  2. Ctrl + Alt + double-click : Add a secondary word selection.
  3. Ctrl + Alt + click + drag : Add a secondary selection.
  4. Shift + Alt + . : Add the next matching text as a selection.
  5. Shift + Alt + ; : Add all matching text as selections.

How do I find and replace all occurrences in all files in Visual Studio? ›

On the Edit menu, expand Find and Replace. Choose Replace in Files. If the Find and Replace window is already open, on the toolbar, choose Replace in Files.

How do I replace all instances simultaneously? ›

Try it!
  1. Select Replace or press Ctrl + H. ...
  2. In the Find what box, type the text you want to search for.
  3. Select Find Next to see where the text appears in your file. ...
  4. In the Replace with box, type the text you want.
  5. Select Replace to change the text or select Replace All to change all instances of this text in your file.

How do I replace all instances? ›

Go to Home > Replace. Enter the word or phrase you want to replace in Find what. Enter your new text in Replace with. Choose Replace All to change all occurrences of the word or phrase.

Why can't I edit environment variables? ›

The first of your problems could be that you don't have Admin rights. To set or edit this function, you must be the Administrator of the system. 2. If you are the Admin, yet the edit function is greyed out, try accessing the Environment Variables by accessing the Control Panel from the Start menu.

Which command is required to change the existing value of variables? ›

The Change Environment Variable (CHGENVVAR) command changes the value for an existing environment variable.

What is the default environment variables for path? ›

Windows 10 default environment variables
VariableWindows 10
39 more rows
Nov 18, 2022

How do I find my environment variable path? ›

Select Start, select Control Panel. double click System, and select the Advanced tab. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it.

How to set Visual Studio path in environment variables? ›

In the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.

What are environment variables in code? ›

An environment variable is a variable whose value is set outside the program, typically through functionality built into the operating system or microservice. An environment variable is made up of a name/value pair, and any number may be created and available for reference at a point in time.

What is an example of an environment variable? ›

Examples of environment variables include: PATH : a list of directory paths. When the user types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command.

How do I access instance variables? ›

Instance variables can be accessed directly by calling the variable name inside the class. However, within static methods (when instance variables are given accessibility), they should be called using the fully qualified name. ObjectReference. VariableName.

How do you view set variables? ›

On Windows

Select Start > All Programs > Accessories > Command Prompt. In the command window that opens, enter set. A list of all the environment variables that are set is displayed in the command window.

How do I check all Environment Variables? ›

The most used command to displays the environment variables is printenv . If the name of the variable is passed as an argument to the command, only the value of that variable is displayed. If no argument is specified, printenv prints a list of all environment variables, one variable per line.

Which command can be used to determine value of a variable? ›

The DEFINE Command. The DEFINE command is used to define a new user variable and assign it a value. DEFINE may also be used to display the value of a specific user variable or to display the values of all user variables.

What is it called when you find the value of a variable? ›

Hence, finding the value of a variable in a linear equation that satisfies the equation is called a root of the equation.

How do you check if a variable contains a number? ›

In JavaScript, there are two ways to check if a variable is a number : isNaN() – Stands for “is Not a Number”, if variable is not a number, it return true, else return false. typeof – If variable is a number, it will returns a string named “number”.

How do I find problems in all files in VS Code? ›

You can click on the summary or press Ctrl+Shift+M to display the PROBLEMS panel with a list of all current errors. If you open a file that has errors or warnings, they will be rendered inline with the text and in the overview ruler.

How do I find all functions in VS Code? ›

To list the functions and methods in VS Code:
  1. Open a file.
  2. On Windows and Linux, press: Ctrl + Shift + O (the letter o , not zero).
  3. On macOS: press CMD + Shift + O (the letter o , not zero).

How do I find and replace all references in Visual Studio? ›

You can find and replace text in the Visual Studio editor by using Find and Replace (Ctrl+F or Ctrl+H) or Find/Replace in Files (Ctrl+Shift+F or Ctrl+Shift+H). You can also find and replace some instances of a pattern by using multi-caret selection.

How do I remove reference count from VS Code? ›

Go in Tools > Environment > Text editor > Codelens. and then disable them .

How do I see all typescript errors in project VS Code? ›

You can also just open the settings in the VSCode UI and search for "experimental typescript" and the Enable Project Diagnostics setting showing will show up. After clicking on the checkbox, it started worked for me.

How do I see all errors in Visual Studio? ›

To display the Error List, choose View > Error List, or press Ctrl+\+E.

How do I find all merge conflicts in Visual Studio code? ›

If there are any merge conflicts when you're pulling changes or trying to merge two branches, Visual Studio lets you know in the Git Changes window, in the Git Repository window, and on any files that have conflicts. The Git Changes window shows a list of files with conflicts under Unmerged Changes.


Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated: 10/17/2023

Views: 6502

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.