【发布时间】:2020-09-29 18:42:19
【问题描述】:
如何在 VScode 中创建以下热键:
- 在编辑文件时(文本文件中的光标/焦点),执行最后一个终端命令
- 将光标/焦点返回到文本文件中的位置,以便我可以无缝地继续编码
这用于调试代码并通过终端有效地运行代码
【问题讨论】:
标签: visual-studio-code terminal editor shortcut hotkeys
如何在 VScode 中创建以下热键:
这用于调试代码并通过终端有效地运行代码
【问题讨论】:
标签: visual-studio-code terminal editor shortcut hotkeys
我简化了我之前的答案。设置中不需要任何内容。
您将需要像multi-command 这样的宏扩展。使用多命令,进行此键绑定:
{
"key": "alt+x", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
{
"command": "workbench.action.terminal.sendSequence",
// send an uparrow to the terminal shell
"args": {"text": "\u001b[A\u000D"},
},
"workbench.action.focusActiveEditorGroup", // return focus to last active editor
]
},
// if you want this to work only when focus is in an editor
"when": "editorFocus"
}
有关上述sendSequence 命令部分的说明,请参阅https://stackoverflow.com/a/55336498/836330(进行键绑定以运行上一个或最后一个 shell 命令)。
【讨论】:
您还可以在 Mark 命令序列的开头添加一些其他有用的命令!
{
"key": "alt+x",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.action.files.saveAll",
"workbench.action.terminal.scrollToBottom",
{
"command": "workbench.action.terminal.sendSequence",
"args": {"text": "\u001b[A\u000D"},
},
"workbench.action.focusActiveEditorGroup",
]
},
"when": "editorFocus"
}
【讨论】: