在 VSCode 终端中制作 Ctrl+C=copy 和 Ctrl+Shift+C=interrupt
Make Ctrl+C=copy and Ctrl+Shift+C=interrupt in VSCode terminal
我想要 Ctrl+C 复制和 Ctrl+Shift+C发送Ctrl+C(中断).
前半部分我想通了
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
}
但是下半场我该怎么办?是否有向终端发送任意按键的命令?
使用 Visual Studio 代码 1.28.0 有一个命令,workbench.action.terminal.sendSequence
,用于向终端发送任意按键。请参阅 Send text from a keybinding to the terminal。
{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u0003"
},
"when": "terminalFocus"
}
如果您为在终端中选择的文本添加条件,则可以同时使用 Ctrl+C。这样,如果选择了文本,则 Ctrl+C 进行复制,如果未选择文本,则发送 SIGINT:
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus && terminalProcessSupported && terminalTextSelected"
}
如果你也想让 Ctrl+V 在终端中工作
{
"key": "ctrl+v",
"command": "workbench.action.terminal.paste",
},
上面的回答都很好。我花了很长时间才弄清楚将这些片段放在哪里。在 VSCode 中转到 文件 | 首选项 | 键盘快捷键。按右上角的小图标切换到json文本视图:打开键盘快捷键(JSON)并编辑设置文件:keybindings.json
示例keybindings.json:
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
},
{
"key": "ctrl+v",
"command": "workbench.action.terminal.paste",
"when": "terminalFocus"
},
{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u0003"
},
"when": "terminalFocus"
},
]
我想要 Ctrl+C 复制和 Ctrl+Shift+C发送Ctrl+C(中断).
前半部分我想通了
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
}
但是下半场我该怎么办?是否有向终端发送任意按键的命令?
使用 Visual Studio 代码 1.28.0 有一个命令,workbench.action.terminal.sendSequence
,用于向终端发送任意按键。请参阅 Send text from a keybinding to the terminal。
{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u0003"
},
"when": "terminalFocus"
}
如果您为在终端中选择的文本添加条件,则可以同时使用 Ctrl+C。这样,如果选择了文本,则 Ctrl+C 进行复制,如果未选择文本,则发送 SIGINT:
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus && terminalProcessSupported && terminalTextSelected"
}
如果你也想让 Ctrl+V 在终端中工作
{
"key": "ctrl+v",
"command": "workbench.action.terminal.paste",
},
上面的回答都很好。我花了很长时间才弄清楚将这些片段放在哪里。在 VSCode 中转到 文件 | 首选项 | 键盘快捷键。按右上角的小图标切换到json文本视图:打开键盘快捷键(JSON)并编辑设置文件:keybindings.json
示例keybindings.json:
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
},
{
"key": "ctrl+v",
"command": "workbench.action.terminal.paste",
"when": "terminalFocus"
},
{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u0003"
},
"when": "terminalFocus"
},
]