我试图让密钥Ctrl+UpArrow
执行这两个命令
cursorUp
和
scrollLineUp
。
我希望这会有效,但它没有:
{
"key": "ctrl+up",
"command": ["cursorUp", "scrollLineUp"], // This doesn't work
"when": "editorTextFocus"
}
我如何在VSCode中执行此操作?
答案 0 :(得分:4)
目前无法进行此操作,但会跟踪相应的功能请求here。不过,您应该查看macros extension。它使您可以将不同的命令链接到单个自定义命令。然后,此自定义命令可以绑定到热键。
在您的情况下,您可以将其添加到settings.json
:
"macros": {
"myCustomCommand": [
"cursorUp",
"scrollLineUp"
]
}
然后将自定义热键添加到keybindings.json
:
{
"key": "ctrl+up",
"command": "macros.myCustomCommand"
}
答案 1 :(得分:3)
有a new way无需扩展即可实现:
运行“任务:打开用户任务”命令以创建或打开用户级任务文件。
将命令定义为单独的任务,如下所示:
{
"version": "2.0.0",
"tasks": [
{
"label": "ctrlUp1",
"command": "${command:cursorUp}"
},
{
"label": "ctrlUp2",
"command": "${command:scrollLineUp}"
},
{
"label": "ctrlUpAll",
"dependsOrder": "sequence",
"dependsOn": [
"ctrlUp1",
"ctrlUp2"
],
"problemMatcher": []
}
]
}
{
"key": "ctrl+up",
"command": "workbench.action.tasks.runTask",
"args": "ctrlUpAll",
"when": "editorTextFocus"
}
(为便于阅读,选择了“ ctrlUpNNN”标签格式,任务标签可以是任何东西。)