VS Code 快捷键绑定多个命令
⌨️

VS Code 快捷键绑定多个命令

Tags
VS Code
IDE
Published
April 25, 2023
Author
举个例子,当我们使用 VS Code 进行代码格式化时,它并不会自动对 import 进行排序。如果我们设置两个快捷键来实现这个功能,可能会比较繁琐。
 
但是,在 VS Code v1.77 更新后,我们可以利用 runCommands 命令,在不依赖第三方扩展的情况下实现同一个快捷键执行多个命令。
 
keybindings.json 如下
{ "key": "alt+f", "command": "runCommands", "args": { "commands": [ "editor.action.formatDocument", "editor.action.organizeImports" ] }, "when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor" }
 
顺便贴一个 VS Code 中快捷键配置 when 的官方文档。