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 f
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:
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 settings:
"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.
{
"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.
At this point I can't get it to successfully find the preLaunchTask
listed in the keybinding - it always fails to find it although it exists and the error popup can take you directly there!?
I'll raise that as an issue depending on any response at the issue listed at the top of this answer. Caveat: there may be other parts of a launch config that don't currently work from a keybinding. Test them.