在vscode中如何设置一个键盘快捷键执行多个操作?

35

在Visual Studio Code中,是否可以将多个操作分配给一个键盘快捷键?

例如: 将光标向上移动3个位置设置为“Ctrl + w”

谢谢!


通常情况下,自 VSCode v1.77 版本开始,您无需安装扩展即可使用单个快捷键运行多个命令。请参见 https://dev59.com/gtrHpIgBRmDukGFEgMZv#75808372。 - Mark
2个回答

22

通过像Commands这样的扩展,这是可能的。[注:由帖子作者创建]

settings.json

"commands.commands": {
    "down3": {
        "sequence": [
            "cursorDown",
            "cursorDown",
            "cursorDown",
        ],
    },
},

keybindings.json

{
    "key": "ctrl+w",
    "command": "down3",
},

只需使用 keybindings.json 文件即可。

{
    "key": "ctrl+w",
    "command": "commands.run",
    "args": [
        "cursorDown",
        "cursorDown",
        "cursorDown"
    ]
},

支持宏状绑定的功能请求#871


尽管在这个特定的例子中最好使用内置命令(以避免任何跳动):

{
    "key": "ctrl+w",
    "command": "cursorMove",
    "args": {
        "to": "down",
        "by": "line",
        "value": 3
    }
}

https://code.visualstudio.com/api/references/commands


2
我将会翻译以下内容:

我使用 宏扩展

在 settings.json 中:

"macros": {
    "showGit": ["workbench.view.scm", "git-graph.view"]
}

然后在keybindings.json文件中:

{
    "key": "ctrl+shift+g",
    "command": "showGit"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接