我可以确定通过键盘快捷键触发的命令在Visual Studio Code中是如何确定的吗?

huangapple go评论62阅读模式
英文:

How can I determine the command triggered by a keyboard shortcut in Visual Studio Code?

问题

Situation

我日常使用VIM和IntelliJ,最近安装了VS Code来尝试最新的"Copilot Chat"功能。为了迁移我的按键绑定,我安装了"IntelliJ IDEA Keybindings"扩展。然而,我遇到了一个问题,按下"Return"或"Enter"键会弹出"查找"输入框并搜索下一个出现的内容,而不是执行预期的创建新行的操作。

Problem

我需要找到一种方法来确定在VS Code中特定快捷键何时触发以及触发哪个命令。我已经搜索了可以帮助我识别与键盘快捷键相关联的命令的解决方案或扩展,但我尚未找到合适的解决方案。拥有这个功能将使我更容易重新映射快捷键并排除意外行为。

Attempted Solution

最初,我考虑构建一个扩展,该扩展会在编辑器底部的状态栏中显示最后触发的命令名称。然而,我意识到这种方法虽然有趣,但可能不是我时间的实际用途,哈哈。

Request

我正在寻找一种解决方案,以确定在VS Code中由键盘快捷键触发的命令。具体来说,我想知道是否有现有的扩展或方法可以在状态栏中显示触发的命令的名称。这些信息将极大地帮助我重新映射快捷键并理解任何意外的行为。

英文:

Situation

I use VIM and IntelliJ on a daily basis, and I recently installed VS Code to try out the newest "Copilot Chat" features. To port over my keybindings, I installed the "IntelliJ IDEA Keybindings" extension. However, I encountered an issue where pressing the "Return" or "Enter" key brings up the "Find" input field and searches for the next occurrence, instead of performing the expected action of creating a new line.

Problem

I need to find a way to determine when and which command is triggered by a specific keyboard shortcut in VS Code. I have searched for solutions or extensions that could help me identify the command associated with a keyboard shortcut, but I haven't found a suitable solution yet. Having this capability would make it easier for me to remap shortcuts and troubleshoot unexpected behavior.

Attempted Solution

Initially, I considered building an extension that would display the last triggered command's name in the status bar at the bottom of the editor. However, I realized that this approach, though fun, might not be a practical use of my time, haha.

Request

I am seeking assistance in finding a solution to determine the command triggered by a keyboard shortcut in VS Code. Specifically, I would like to know if there is an existing extension or method that can display the name of the command triggered in the status bar. This information would greatly aid me in remapping shortcuts and understanding any unexpected behavior.

答案1

得分: 1

你可以选择:

  • 使用命令面板中的 Preferences: Open Keyboard Shortcuts 命令打开键盘快捷方式编辑器界面,然后使用 "Record Keys" 按钮(在Windows和Linux上绑定为 alt+k)来搜索感兴趣的按键绑定。或者

  • 打开你的 keybindings.json 文件,并使用查找小部件(ctrl/cmd+f)来搜索按键绑定序列,并查看它绑定到哪个命令。


如果这没有产生结果,你也可以使用 VS Code 键绑定故障排除文档(和 wiki)中的提示:使用 Developer: Toggle Keyboard Shortcuts Troubleshooting 命令,这将导致有关键盘快捷方式的事件日志被记录到输出面板。

以下是来自 wiki 的一个示例:

[KeybindingService]: / Received  keydown event - modifiers: [meta], code: MetaLeft, keyCode: 91, key: Meta
[KeybindingService]: | Converted keydown event - modifiers: [meta], code: MetaLeft, keyCode: 57 ('Meta')
[KeybindingService]: \ Keyboard event cannot be dispatched.
[KeybindingService]: / Received  keydown event - modifiers: [meta], code: Slash, keyCode: 191, key: /
[KeybindingService]: | Converted keydown event - modifiers: [meta], code: Slash, keyCode: 85 ('/')
[KeybindingService]: | Resolving meta+[Slash]
[KeybindingService]: \ From 2 keybinding entries, matched editor.action.commentLine, when: editorTextFocus && !editorReadonly, source: built-in.

在这里你可以看到它显示了它接收到的键盘事件,以及它匹配到的命令。

英文:

You can either

  • open the keyboard shortcut editor UI by using the Preferences: Open Keyboard Shortcuts command in the command palette, and then use the "Record Keys" button (bound to <kbd>alt</kbd>+<kbd>k</kbd> on Windows and Linux) to search for the keybinding of interest. Or

  • open your keybindings.json file and use the find widget (<kbd>ctrl/cmd</kbd>+<kbd>f</kbd>) to search for the keybinding sequence and see what command it's bound to.


If that's not bearing fruit, you can also use the tips in VS Code's keybinding troubleshooting docs (and wiki): Use the Developer: Toggle Keyboard Shortcuts Troubleshooting command, which will cause event logs about keyboard shortcuts to be logged to the Output Panel.

Here's an example from the wiki:

> none
&gt; [KeybindingService]: / Received keydown event - modifiers: [meta], code: MetaLeft, keyCode: 91, key: Meta
&gt; [KeybindingService]: | Converted keydown event - modifiers: [meta], code: MetaLeft, keyCode: 57 (&#39;Meta&#39;)
&gt; [KeybindingService]: \ Keyboard event cannot be dispatched.
&gt; [KeybindingService]: / Received keydown event - modifiers: [meta], code: Slash, keyCode: 191, key: /
&gt; [KeybindingService]: | Converted keydown event - modifiers: [meta], code: Slash, keyCode: 85 (&#39;/&#39;)
&gt; [KeybindingService]: | Resolving meta+[Slash]
&gt; [KeybindingService]: \ From 2 keybinding entries, matched editor.action.commentLine, when: editorTextFocus &amp;&amp; !editorReadonly, source: built-in.
&gt;

where you can see it shows what keyboard events it receives, and what command it matches it to.

答案2

得分: 0

你可以从“首选项”菜单选项中查看所有的键盘快捷键。

Linux/Windows:Ctrl + K Ctrl + S

Mac:Command + K Command + S

你可以在这里编辑键绑定。关于如何更新或调试键盘快捷键的详细信息可以在官方文档中找到。

英文:

You can view all of the keyboard shortcuts from the Preferences menu option.

Linux/Windows: Ctrl + K Ctrl + S

Mac: Command + K Command + S.

You can edit the key bindings here. You'll also find detailed information in the official documentation on how to update or debug issues with keyboard shortcuts.

huangapple
  • 本文由 发表于 2023年5月28日 10:50:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76349751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定