创建新宏(快捷方式)以在集成终端中复制粘贴和执行代码
Create New Macro (Shortcut) to Copy Paste and Execute Code in the Integrated Terminal
问题
我经常做的一个操作是在编辑器上highlight/select编码,然后粘贴到集成终端上执行。虽然我使用 Ctrl + c
、Ctrl + backtick
、Ctrl + Shift + v
和 Enter
的速度非常快,但它非常烦人且重复。有没有办法为此配置宏或快捷方式?
解决方案(失败)尝试
This Github thread and 显示如何创建在不同集成终端之间切换的快捷方式。我希望在我的案例中发生类似的事情(我在下面的示例中使用 Ctrl + Shift + u
),例如:
[
{
"key" : "ctrl+shift+k",
"command" : "workbench.action.terminal.focusNext"
},
{
"key" : "ctrl+shift+j",
"command" : "workbench.action.terminal.focusPrevious"
},
{
"key" : "ctrl+shift+u",
"command" : "ctrl+c+ctrl+`+ctrl+shift+v+enter"
},
]
没有 VS 代码扩展
有一个命令:workbench.action.terminal.runSelectedText
,它已经完成了您想要的操作,默认情况下未绑定到任何键盘。
[刚好看到sendSequence
命令]:
如果您不走另一条路,此键绑定将 运行 终端中的选定文本:
{
"key": "alt+t",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "${selectedText}\u000D"
}
},
\u000D
是 return。
** [菲利普添加] :::
使用 VS 代码扩展(宏序列配置)
VS Code目前不允许连接快捷方式,所以,如果你想在集成终端上执行代码和专注于它,你将不得不安装一个宏延期。
对此有多种选择。但是,建议使用 multi-command (don't go for first results like macros,其中一些非常 过时)。
要创建上述快捷方式,请在 settings.json
文件中创建一系列命令:
"multiCommand.commands": [ // Copy Paste to the Integrated Terminal and also Focus on it
{
"command": "multiCommand.copyPasteTerminalAndFocus",
"sequence": [
{
"command" : "workbench.action.terminal.sendSequence",
"args" : {"text" : "${selectedText}\u000D"}
},
"workbench.action.terminal.focus"
]
},
]
然后在keybindings.json
文件中为其创建一个快捷方式:
{
"key": "alt+y",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.copyPasteTerminalAndFocus" }
},
问题
我经常做的一个操作是在编辑器上highlight/select编码,然后粘贴到集成终端上执行。虽然我使用 Ctrl + c
、Ctrl + backtick
、Ctrl + Shift + v
和 Enter
的速度非常快,但它非常烦人且重复。有没有办法为此配置宏或快捷方式?
解决方案(失败)尝试
This Github thread and Ctrl + Shift + u
),例如:
[
{
"key" : "ctrl+shift+k",
"command" : "workbench.action.terminal.focusNext"
},
{
"key" : "ctrl+shift+j",
"command" : "workbench.action.terminal.focusPrevious"
},
{
"key" : "ctrl+shift+u",
"command" : "ctrl+c+ctrl+`+ctrl+shift+v+enter"
},
]
没有 VS 代码扩展
有一个命令:workbench.action.terminal.runSelectedText
,它已经完成了您想要的操作,默认情况下未绑定到任何键盘。
[刚好看到sendSequence
命令]:
如果您不走另一条路,此键绑定将 运行 终端中的选定文本:
{
"key": "alt+t",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "${selectedText}\u000D"
}
},
\u000D
是 return。
** [菲利普添加] :::
使用 VS 代码扩展(宏序列配置)
VS Code目前不允许连接快捷方式,所以,如果你想在集成终端上执行代码和专注于它,你将不得不安装一个宏延期。
对此有多种选择。但是,建议使用 multi-command (don't go for first results like macros,其中一些非常 过时)。
要创建上述快捷方式,请在 settings.json
文件中创建一系列命令:
"multiCommand.commands": [ // Copy Paste to the Integrated Terminal and also Focus on it
{
"command": "multiCommand.copyPasteTerminalAndFocus",
"sequence": [
{
"command" : "workbench.action.terminal.sendSequence",
"args" : {"text" : "${selectedText}\u000D"}
},
"workbench.action.terminal.focus"
]
},
]
然后在keybindings.json
文件中为其创建一个快捷方式:
{
"key": "alt+y",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.copyPasteTerminalAndFocus" }
},