'vscode keyboard shortcut for launch configuration
In vscode, I have a launch.json with more than one configuration.
Is there a way to assign a keyboard shortcut to a specific configuration?, I've not been able to find any information, thanks!
Solution 1:[1]
Almost, but not quite.
To my knowledge there is no vs-code command to start debugging a given launch configuration.
What you can do instead is point a keyboard shortcut at the workbench.action.debug.selectandstart
command which will pop-up a dialogue for you to select the configuration and hit enter. In practice this can be done very quickly as you only need to start typing the first letter or two of your launch config or use the arrows
To enable this hit Ctrl+kCtrl+s (at least this is the default shortcut on windows, you can always search for 'keybindings' in the command palette if this doesn't work for you).
Search for the workbench.action.debug.selectandstart
command then right-click or click the edit icon to change the keybinding:
Solution 2:[2]
Update: I just created an extension Launch Configs which allows you to set up a keybinding for any launch configuration in your launch.json
. Multiple keybindings for different launch configs if you wish. Example setting (in your settings.json
):
"launches": {
"RunNodeCurrentFile": "Launch File",
"RunCompound1": "Launch file and start chrome"
},
So with the extension you can set the value to the name
of your desired launch.json configuration to run/debug. And then keybindings to trigger those configurations (in your keybindings.json
).
{
"key": "alt+f",
"command": "launches.RunNodeCurrentFile"
},
{
"key": "alt+g",
"command": "launches.RunCompound1"
}
See my answer at https://github.com/microsoft/vscode/issues/97921
This keybinding works:
{
"key": "alt+j", // whatever keybinding you like
"command": "debug.startFromConfig",
"args": {
"type": "node",
"request": "launch",
"name": "First Debugger",
"program": "${workspaceFolder}/test.js",
"console": "integratedTerminal",
//"preLaunchTask": "echo Builtin Variables" // can't get it to find a pre-launch task
}
}
but unfortunately not by simply referring to an existing config in your launch.json
- by name
for example. The referred config - here First Debugger
can, but doesn't have to be in your launch.json
. In any case all the args
must appear in your keybinding.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stewart_R |
Solution 2 |