简体   繁体   English

如何在 VS Code 中为一个命令添加多个键盘快捷键?

[英]How to add multiple keyboard shortcuts to one command in VS Code?

How can I add multiple keyboard shortcuts to a single command in VS Code?如何在 VS Code 中为单个命令添加多个键盘快捷键?

As an example (from the comments), ctrl + 0 & ctrl + 1 should both do the same command/action.作为示例(来自评论), ctrl + 0ctrl + 1都应该执行相同的命令/操作。 So completely separate shortcuts doing the same command.因此,完全独立的快捷方式执行相同的命令。

Let's say there are 2 bindings to close window like so:假设有 2 个绑定可以关闭 window,如下所示:

在此处输入图像描述

Let's say we want to add one more keybinding like CMD+K, CMD+1.假设我们想再添加一个键绑定,例如 CMD+K、CMD+1。 You could do that by right-clicking a command and choosing copy like so:您可以通过右键单击命令并选择复制来做到这一点,如下所示:

在此处输入图像描述

Then, click on an icon on the top right corner to open keyboard shortcuts JSON.然后,单击右上角的图标以打开键盘快捷键 JSON。 The icon has an curved arrow on a page:该图标在页面上有一个弯曲的箭头:

在此处输入图像描述

Your user-defined keybindings.JSON will show up.您的用户定义的 keybindings.JSON 将出现。 Type this in it:在里面输入这个:

// Place your key bindings in this file to override the defaults
[
    {
        "key": "cmd+k cmd+1",
        "command": "workbench.action.closeWindow"
    }
]

Save and close.保存并关闭。

Now you will see 3 keybindings for the action like so:现在您将看到 3 个用于该操作的键绑定,如下所示:

在此处输入图像描述

Now, try your new keybinding.现在,试试你的新键绑定。

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

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