Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Ctrl+C=copy and Ctrl+Shift+C=interrupt in VSCode terminal

I'd like to have Ctrl+C copy and Ctrl+Shift+C send Ctrl+C (interrupt).

I figured out the first half

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

But how do I do the second half? Is there a command to send an arbitrary key press to the terminal?

like image 538
Mikel Avatar asked Jul 22 '17 17:07

Mikel


People also ask

How do you copy VS code in terminal?

Copy & paste# Linux: Ctrl+Shift+C and Ctrl+Shift+V; selection paste is available with Shift+Insert. macOS: Cmd+C and Cmd+V. Windows: Ctrl+C and Ctrl+V.

How do I enable copy and paste in VSCode?

Click on Site Settings. Click View permissions and data stored across sites. Select the entry for the site that is associated with your VS Code server. Scroll down until you find a Clipboard permission, and select Allow from the provided dropdown menu to the right of the permission.

How do I change the terminal shortcut in VSCode?

Go to File → Preferences → Keyboard Shortcuts or just press Ctrl + k + Ctrl + s.


2 Answers

With Visual Studio Code 1.28.0 there is a command, workbench.action.terminal.sendSequence, to send arbitrary keypresses to the terminal. See Send text from a keybinding to the terminal.

  {
    "key": "ctrl+shift+c",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": "\u0003"
    },
    "when": "terminalFocus"
  }
like image 174
Mark Avatar answered Sep 28 '22 03:09

Mark


Answers above are all good. It took me long time to figure out exactly where to put these snippets. In VSCode go to File | Preferences | Keyboard Shortcuts. Switch to json text view by pressing small icon on top-right: Open Keyboard Shortcuts (JSON) and edit setting file: keybindings.json

Example 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"
    },
]
like image 28
Rav Avatar answered Sep 28 '22 04:09

Rav