57

In Visual Studio Code, the Ctrl-k shortcut is bound to clearing the terminal.

I've configured bash as my terminal in Windows and would like it to behave as the traditional Emacs key bindings, that is, to make it kill the end of the line.

I've tried to disable the default key binding with this configuration in the user settings, but it didn't work:

"commandsToSkipShell": [
        "workbench.action.terminal.clear"
      ]

How to make the terminal obey my 20 years trained muscle memory?

neves
  • 33,186
  • 27
  • 159
  • 192

5 Answers5

103

If you have years of muscle memory of Unix shell and want to prevent VSCode to capture your keyboard shortcuts, turn off allowChords. In newer VSCode version you can simply open File -> Preferences -> User (tab), search for allowChords and uncheck it.

Or you can edit your %APPDATA%\Code\User\settings.json file and put this:

   "terminal.integrated.allowChords": false

Now a lot of terminal shortcuts will just work:

  • Ctrl+K for killing till the end of the line,
  • Ctrl-Y pastes the killed line from above
  • Ctrl+R searches for your commands in your history,
  • and Ctrl+A goes to the beginning of the line

I have another answer in this thread, but I think this is a better solution. Here is the documentation.

See other answers if you want to fix just the Ctrl-K behavior.

neves
  • 33,186
  • 27
  • 159
  • 192
  • 7
    I wish I could upvote this twice! Thank you. – nycynik Dec 19 '20 at 22:45
  • 1
    I'd like to point out that VS Code even says in the description of that configuration "setting this to false is particularly useful when you want ctrl+k to go to your shell (not VS Code)." – jdferreira Apr 08 '21 at 10:57
  • 1
    OK. But there is no escape sequence to send the control characters to the terminal without changing the VS Code default behaviour? Something like **Ctrl+V** in vi or bash to insert the next control character literally (to not interpret it). – pabouk - Ukraine stay strong Nov 18 '21 at 14:11
  • This fixed an issue I was having trying to use VIM digraphs (https://vimhelp.org/digraph.txt.html) in the integrated terminal. Thanks! – Tom Jan 15 '22 at 20:44
  • 2
    i feel like a chiropractor released years of tension from my life – Shankara Narayana Feb 16 '22 at 13:35
  • I've never used chords. I'm curious what I'm missing out on. If I turn it back on can I play a masterpiece symphony? – ADJenks May 03 '22 at 21:26
  • This still kept ctrl+w active. – A. K. Aug 16 '22 at 18:06
  • I feel sorry for myself for not searching for this fix earlier thinking it would be too hard to fix‍♂️. All I had to do was untick a checkmark in settings! – Thamme Gowda Dec 20 '22 at 00:42
30

Ran into the same problem. Adding this snippet to keybindings.json worked:

{
  "key": "ctrl+k",
  "command": "deleteAllRight",
  "when": "terminalFocus"
}
Jakob Odersky
  • 1,371
  • 11
  • 23
  • this worked for me, chords are still active, but I'm able to clear the terminal using ctrl+k without triggering chords like my muscle memory wants it to. – AgrahamLincoln Jan 10 '20 at 17:44
  • This is great, as it actually does a proper kill and `Ctrl+Y` afterwards works as well! – Andrew Mao Mar 02 '20 at 20:40
  • 1
    As of 2020, this is the correct answer now. Find keyboard.json file with Shift-Ctrl-P and searching for `keybindings` – neves Apr 03 '20 at 23:05
  • FYI: if you've never opened `keybindings.json` before, it won't show up in search; what you're looking for is `Preferences: Open Keyboard Shortcuts (JSON)`. – parttimeturtle Feb 18 '21 at 22:19
6

Just discovered it! You need to put a minus sign before the configuration. Edit %APPDATA%\Code\User\settings.json and enter this key:

"terminal.integrated.commandsToSkipShell": [
    "-workbench.action.terminal.clear"
  ]

It looks like the config option was renamed, so I edited to what is working for me now (Nov 2018).

neves
  • 33,186
  • 27
  • 159
  • 192
  • This does not work. From the [documentation](https://code.visualstudio.com/docs/editor/integrated-terminal#_chord-keybindings-in-the-terminal): "By default, when a chord keybinding is the highest priority keybinding, it will always skip the terminal shell (bypassing `terminal.integrated.commandsToSkipShell`) and be evaluated by VS Code instead of the terminal." – Cameron Tacklind Jul 15 '21 at 00:36
1

For those looking this up as of November 2019, just copy and paste the following into your keybindings.json file:

{
    "key": "ctrl+k",
    "command": "-workbench.action.terminal.clear",
    "when": "terminalFocus"
},
  • Is it normal that I still have to press `ctrl+k` twice? – nachtigall Nov 13 '19 at 09:14
  • I changed this from user settings and then added the “-“ in keybindings.json. It might be there is still another key binding associated with “workbench.action.clear” that needs to be removed. You could also try saving the json file as if the key binding was normally, applying them manually and saving again. – CodeParking Nov 14 '19 at 14:38
  • this doesn't answer the question: it *clears* the terminal, whereas the question is on how to *kill until the end of the line.* – Jakob Odersky Nov 23 '19 at 18:31
  • This is the original setting for clearing terminal, but adding the minus before “workbook” is supposed to just clear to end of line from cursor location. I’m pretty sure it was working fine for me on Linux Mint, but I’ll try testing it again tomorrow. – CodeParking Nov 25 '19 at 00:28
  • I tried this and didn't notice any difference, using ctrl+k in the terminal still triggers the chords. – AgrahamLincoln Jan 10 '20 at 17:43
1

I solved this problem by changing the following settings:

  • Check: Terminal › Integrated: Send Keybindings To Shell
  • Uncheck: Terminal › Integrated: Allow Chords

All my Emacs keybindings now work in the VSCode Terminal.

Hope this helps someone.