使用插件配置vscode快捷键支持多command命令

作者:matrix 被围观: 1,178 次 发布时间:2022-09-12 分类:零零星星 | 一条评论 »

这是一个创建于 586 天前的主题,其中的信息可能已经有所发展或是发生改变。

配置快捷键运行多条命令,目前没有看到官方的解决方案,使用三方插件支持

测试环境:

Mac vscode 默认语言

multi-command插件

https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command

先安装multi-command~

打开配置页

打开vscode命令面板按F1或者command + shift + p

搜索 open keyboard shortcuts,选择Open Keyboard Shortcuts (JSON)

图片5545-vscode cmd-k快捷键清空信息

我之前有次修改过cmd-k快捷键,目的是清空code-runner插件运行的命令行信息(清屏)。
vscode默认的cmd-k执行场景有限,当初是把触发条件when修改为终端或者编辑器获取焦点就行。

...
{
"key": "cmd+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus && terminalProcessSupported || editorFocus"
}
...

但是现在需要terminaloutput都执行清空,也就是执行两条命令。我尝试了多次都失败了,最后也只好乖乖安装插件搞定。

自定义快捷键

按照上面操作,正常打开keybindings.json文件,
或者自己打开配置文件默认路径:

~/Library/Application Support/Code/User/keybindings.json

我需要执行多个消息清空的命令,按下面配置即可

// 将键绑定放在此文件中以覆盖默认值auto[]
[
//...
{
"key": "cmd+k",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.terminal.clear",
"workbench.output.action.clearOutput",
]
},
"when": "terminalFocus && terminalProcessSupported || editorFocus"
},
//...
]

说明:
command参数执行插件入口命令extension.multiCommand.execute
sequence参数配置需要执行的命令(按序执行)
when参数控制触发条件

配置完成之后,会立即生效~ 这样就可以了

找到自己的command

你自定义的快捷键可能会用到vscode的其他命令,可以使用下面方法找到完整command命令

  • 打开vscode命令面板按F1或者command + shift + p

  • 搜索命令关键字

  • 点击右侧设置按钮

图片5558-使用插件配置vscode快捷键支持多command命令

  • 右键Copy Command ID

图片5558-使用插件配置vscode快捷键支持多command命令2

参考:

when参数可用context:
https://code.visualstudio.com/api/references/when-clause-contexts

不使用插件的方法:

VS Code: bind one key to multiple commands without an extension

其他文章:
本文固定链接:https://www.hhtjim.com/vscode%e5%bf%ab%e6%8d%b7%e9%94%ae%e9%85%8d%e7%bd%ae%e6%94%af%e6%8c%81%e5%a4%9acommand%e5%91%bd%e4%bb%a4.html
matrix
本文章由 matrix 于2022年09月12日发布在零零星星分类下,目前没有通告,你可以至底部留下评论。
转载请注明:使用插件配置vscode快捷键支持多command命令-HHTjim'S 部落格
关键字:

有1条评论 »

  1. 谷歌优化 谷歌优化 2022-10-10 9:48:47 +0800#1

    好的学到了

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!