简体   繁体   English

用于启动配置的 vscode 键盘快捷键

[英]vscode keyboard shortcut for launch configuration

In vscode, I have a launch.json with more than one configuration.在 vscode 中,我有一个包含多个配置的 launch.json。

Is there a way to assign a keyboard shortcut to a specific configuration?, I've not been able to find any information, thanks!有没有办法为特定配置分配键盘快捷键?,我找不到任何信息,谢谢!

Almost, but not quite.差不多,但不完全。

To my knowledge there is no vs-code command to start debugging a given launch configuration.据我所知,没有 vs-code 命令可以开始调试给定的启动配置。

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.你可以做的是在workbench.action.debug.selectandstart命令上指向一个键盘快捷键,它会弹出一个对话框让你选择配置并按回车键。 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 + k Ctrl + 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).要启用此点击Ctrl + k Ctrl + s (至少这是 Windows 上的默认快捷方式,如果这对您不起作用,您可以随时在命令面板中搜索“键绑定”)。

Search for the workbench.action.debug.selectandstart command then right-click or click the edit icon to change the keybinding:搜索workbench.action.debug.selectandstart命令,然后右键单击或单击编辑图标以更改键绑定:

截屏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 .更新:我刚刚创建了一个扩展Launch Configs ,它允许您为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.因此,通过扩展,您可以将值设置为您想要运行/调试的 launch.json 配置的name 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/97921https://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.但不幸的是,不能简单地引用 launch.json 中的现有配置 - 例如通过name The referred config - here First Debugger can, but doesn't have to be in your launch.json.引用的配置 - 这里First Debugger可以,但不必在您的 launch.json 中。 In any case all the args must appear in your keybinding.在任何情况下,所有args必须出现在您的键绑定中。

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!?在这一点上,我无法让它成功找到键绑定中列出的preLaunchTask - 尽管它存在,但它总是无法找到它,并且错误弹出窗口可以将您直接带到那里!?

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.测试它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM