62

Is there any way to set two keyboard shortcuts for one action in VS code? For example, I want to move the cursor to the left by pressing left arrow key or Alt+A.

Is it possible to add multiple keybindings to a shortcut?

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
Younghoon Jeong
  • 753
  • 1
  • 5
  • 7
  • As far as I know, you need to make a custom macro for both to get that to work. – ifconfig Jul 29 '17 at 00:01
  • I have edited your question for the sole purpose of making it more likely to show up in search engines. This is exactly what I was looking for and the below answer is also exactly what I was looking for. But it took me a while of searching for different phrases and scrolling to find this. – FreelanceConsultant Dec 04 '22 at 09:53

2 Answers2

103

Edit: Starting from 1.52 it's possible from keybindings GUI:

keybindings gui context menu add keybinding


What stops you from editing keybindings.json?

{
    "key": "left",
    "command": "cursorLeft",
    "when": "textInputFocus"
},
{
    "key": "alt+a",
    "command": "cursorLeft"
}

It can be opened from Command Palette Preferences: Open Keyboard Shortcuts (JSON)

Or by clicking the file icon from keybindings GUI page:

enter image description here

Alex
  • 59,571
  • 22
  • 137
  • 126
  • It works. To access keybindings.json one can access the settings and click on the link – aless80 Jan 10 '19 at 05:03
  • 14
    it would be _kinda_ helpful if your answer actually mentioned _how_ you add multiple keybindings. The answer is: create multiple entries, one per desired key. But that's not obvious; it could just as easily have been one entry with a delimited list for key. – Michael Johnston May 01 '19 at 18:27
10

Updating the previous answer and adding tiny more details, atleast in the current 2020 version it seems like after changing the keybindings (atleasy cursor up & down), VSCode creates an entry in the JSON file that can be accessed from Alex's answer. The JSON will contain the new entry you made but also the changed entry with a '-' negative sign on the key instruction. Just remove the '-' negative sign and both your keybindings should work like a charm! Obviously don't forget to save!

Yashank
  • 743
  • 2
  • 7
  • 23
  • In version 1.53.2 there is no such json file, nor does the Keyboard Shortcuts GUI have any link above the 'Type to search in keybindings' text entry :( – Razzle Jul 24 '21 at 15:12
  • 1
    That's weird... Don't you see any 'keyboard shortcut JSON' option in the menu tabs? I switched to sublime now so cannot check myself. – Yashank Jul 24 '21 at 15:49
  • 1
    +1 for being able to escape from VSCode.. i recently took intellij for a spin and realised how large the chasm is between VSCode and real developer tools.. – Razzle Jul 27 '21 at 20:54