Nic*_*ick 12 key-bindings visual-studio-code
我在VS代码中有以下键绑定,它切换活动文档和内置终端之间光标的位置:
// Toggle between terminal and editor focus
{
"key": "oem_8",
"command": "workbench.action.terminal.focus"
},
{
"key": "oem_8",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
Run Code Online (Sandbox Code Playgroud)
在我单击快捷键将光标移动到终端之前,我首先要保存活动文件.
因此,我想运行文件保存命令,在搜索谷歌后,我相信是:workbench.action.files.save
我该怎么办?我已经尝试在"命令"行的末尾添加上面的代码片段,但它没有奏效.
干杯
Ash*_*ark 17
有一种方法可以在没有任何扩展的情况下运行一系列命令。这是通过使用任务。我喜欢这种方法,因为它允许定义一个命令,该命令在工作区范围内,而不是在全局范围内。这个想法取自这篇博客文章。示例tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "cmd-1",
"command": "${command:workbench.action.files.save}"
},
{
"label": "cmd-2",
"command": "${command:workbench.action.terminal.focus}"
},
{
"label": "cmd-All",
"dependsOrder": "sequence",
"dependsOn": [
"cmd-1",
"cmd-2"
],
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后,keybindings.json您只需将热键绑定到任务即可:
{
"key": "oem_8",
"command": "workbench.action.tasks.runTask",
"args": "cmd-All"
}
Run Code Online (Sandbox Code Playgroud)
请注意,定义任务时,您可以借助输入变量将参数传递给命令。
Mar*_*ark 16
您需要像宏这样的扩展来从一个键绑定运行多个命令.
在你的settings.json中:
"macros": {
// give it whatever name you what
"saveAndFocusTerminal" : [
"workbench.action.files.save",
"workbench.action.terminal.focus"
]
}
Run Code Online (Sandbox Code Playgroud)
并在你的keybindings.json中:
{
"key": "oem_8",
// use your name from above here
"command": "macros.saveAndFocusTerminal"
},
Run Code Online (Sandbox Code Playgroud)
运行多个命令的另一个扩展:Commands
{
"key": "oem_8",
"command": "commands.run",
"args": [
"workbench.action.files.save",
"workbench.action.terminal.focus"
],
"when": "editorTextFocus"
}
Run Code Online (Sandbox Code Playgroud)
我做了这个扩展。这很棒。
| 归档时间: |
|
| 查看次数: |
3078 次 |
| 最近记录: |