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!
Alternatively, you can run your configuration through the Command Palette (Ctrl+Shift+P) by filtering on Debug: Select and Start Debugging or typing 'debug ' and selecting the configuration you want to debug. In addition, the debug status appears in the Status Bar showing the active debug configuration.
You can also open the Settings editor from the Command Palette (Ctrl+Shift+P) with Preferences: Open Settings or use the keyboard shortcut (Ctrl+,).
To launch the Define Keybinding widget, press Ctrl+K Ctrl+K. The widget listens for key presses and renders the serialized JSON representation in the text box and below it, the keys that VS Code has detected under your current keyboard layout.
You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.action.tasks.runTask command, and define the Task as args .
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With