vscode 启动配置的键盘快捷键

vscode keyboard shortcut for launch configuration

在 vscode 中,我有一个 launch.json 具有不止一种配置。

有没有办法为特定配置分配键盘快捷键?我找不到任何信息,谢谢!

差不多,但不完全是。

据我所知,没有 vs-code 命令可以开始调试给定的启动配置。

您可以做的是将键盘快捷键指向 workbench.action.debug.selectandstart 命令,这将弹出一个对话框供您 select 配置,然后按回车键。实际上,这可以非常快速地完成,因为您只需要开始输入启动配置的第一个或两个字母或使用箭头

启用此点击 Ctrl+kCtrl+s (至少这是 windows 上的默认快捷方式,如果这对您不起作用,您可以随时在命令面板中搜索 'keybindings')。

搜索 workbench.action.debug.selectandstart 命令,然后右键单击或单击编辑图标以更改键绑定:

更新:我刚刚创建了一个扩展 Launch Configs,它允许您为 launch.json 中的任何启动配置设置键绑定。如果您愿意,可以为不同的启动配置设置多个键绑定。示例设置(在您的 settings.json 中):

 "launches": {

  "RunNodeCurrentFile": "Launch File",
  "RunCompound1": "Launch file and start chrome"
},

因此,通过扩展,您可以将所需 launch.json 配置的值设置为 name run/debug。然后是键绑定来触发这些配置(在你的 keybindings.json 中)。

{
  "key": "alt+f",
  "command": "launches.RunNodeCurrentFile"
},
{
  "key": "alt+g",
  "command": "launches.RunCompound1"
}

https://github.com/microsoft/vscode/issues/97921

查看我的回答

此键绑定有效:

{
  "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
  }
}

但不幸的是,不能简单地引用 launch.json 中的现有配置 - 例如 name。引用的配置 - 这里 First Debugger 可以,但不一定要在你的 launch.json 中。在任何情况下,所有 args 都必须出现在您的键绑定中。