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

Mik*_*kel 6 copy-paste visual-studio-code

我想拥有Ctrl+ C复制和Ctrl+ Shift+ C发送Ctrl+ C(中断)。

我弄清楚了上半年

{
    "key": "ctrl+c",
    "command": "workbench.action.terminal.copySelection",
    "when": "terminalFocus"
}
Run Code Online (Sandbox Code Playgroud)

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

小智 29

上面的答案都很好。我花了很长时间才弄清楚这些片段到底应该放在哪里。在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"
    },
]
Run Code Online (Sandbox Code Playgroud)

  • 这应该是公认的答案,因为它不会留下任何解释和“你弄清楚在哪里插入这些行”。 (3认同)
  • 这个答案比公认的答案要好得多。 (2认同)

Mar*_*ark 16

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

  {
    "key": "ctrl+shift+c",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": "\u0003"
    },
    "when": "terminalFocus"
  }
Run Code Online (Sandbox Code Playgroud)

  • 如果您正在寻找快速到达此处的方法,可以使用“keybindings.json”文件。通过“首选项:打开键盘快捷键 (JSON)”轻松访问 (2认同)

Aal*_*abi 6

如果您为在终端中选择的文本添加条件,则可以对两者使用 Ctrl+C。这样,Ctrl+C 仅在选择文本时复制,如果未选择文本则发送 SIGINT。

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

{
   "key": "ctrl+c",
   "command": "workbench.action.terminal.copySelection",
   "when": "terminalFocus && terminalProcessSupported && terminalTextSelected"
}
Run Code Online (Sandbox Code Playgroud)

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

{
   "key": "ctrl+v",
   "command": "workbench.action.terminal.paste",
   "when": "terminalFocus && terminalProcessSupported"
},
Run Code Online (Sandbox Code Playgroud)