Yes, it is possible to perform variable expansion in keybindings.json and tasks.json/inputs when using VSCode.
In keybindings.json, you can use the ${var}
syntax to reference any variable defined in the workspace or the user settings. For example, you could define a variable myFolderPath
in the user settings, and reference it in a keybinding like this:
{
"key": "ctrl+alt+o",
"command": "workbench.action.openFolder",
"args": {"fileUri": "${myFolderPath}"}
}
In tasks.json and inputs, you can use the ${input:...}
syntax to prompt the user for input values, and the ${...}
syntax to reference other variables or environment variables. For example, you could prompt the user for an input value and use it in a task like this:
{
"label": "Copy file",
"type": "shell",
"command": "cp",
"args": [
"${fileToCopy}",
"${destinationFolder}"
],
"inputs": [
{
"id": "fileToCopy",
"type": "promptString",
"description": "Enter the path of the file to copy"
},
{
"id": "destinationFolder",
"type": "promptString",
"description": "Enter the path of the destination folder"
}
]
}
Note that variable expansion is not supported in all areas of VSCode, so be sure to check the documentation for the specific feature you are using to see if variable expansion is supported.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-12-05 11:00:00 +0000
Seen: 11 times
Last updated: Jul 30 '21
What is the process for installing SASS/Compass in the DDEV web container?
Is it possible to create and execute a file without having to type the file name twice?
How can you obtain the sha1 of the most recent commit in a git repository using C#?
What is the process for initializing Java UDFs in Spark?
How can I use crontab to initiate and modify the libcamera-vid RTSP stream on my Raspberry Pi?
Is it possible to repair a file within a docker container that has failed to start?
What is an effective way to edit HTML strings using PowerShell?