在VSCode终端中使Ctrl + C = copy和Ctrl + Shift + C =中断



我想让 Ctrl+C复制和 Ctrl+Shift+C 发送Ctrl+C(中断(。

我想通了上半场

{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
}

但是我该怎么做下半场呢? 是否有向终端发送任意按键的命令?

在Visual Studio Code 1.28.0中,有一个命令,workbench.action.terminal.sendSequence,用于向终端发送任意按键。 请参阅将文本从键绑定发送到终端

{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "u0003"
},
"when": "terminalFocus"
}

上面的答案都很好。我花了很长时间才弄清楚将这些片段放在哪里。在VSCode中,转到"文件">|">偏好|键盘快捷键。按右上角的小图标切换到json 文本视图打开键盘快捷键 (JSON(并编辑设置文件:keybindings.json

示例键绑定.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+C 仅在选择了文本时进行复制,如果未选择文本,则发送 SIGINT。

将以下内容添加到keybindings.jsonCtrl+Shift+P>Open Keyboard Shortcuts (JSON)

{
"key": "ctrl+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus && terminalProcessSupported && terminalTextSelected"
}

如果您还想使 Ctrl+V 在终端中工作

{
"key": "ctrl+v",
"command": "workbench.action.terminal.paste",
"when": "terminalFocus && terminalProcessSupported"
},

这些是在OSX上对我有用的绑定,我使用Karabiner像Windows机器一样映射我的键盘快捷键。所以控制键是命令。

[
{
"key": "cmd+shift+c",
"command": "workbench.action.terminal.copySelection",
"when": "terminalFocus"
},
{
"key": "cmd+v",
"command": "workbench.action.terminal.paste",
"when": "terminalFocus"
},
{
"key": "cmd+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "u0003"
},
"when": "terminalFocus"
},
]

最新更新