180

Using Visual Studio Code what is the procedure to:

  • Remap a built in command's keyboard shortcut. For example, say, Open File (default is Ctrl+O, it's unlikely that anyone would actually change this, but the same process should probably apply for any built in shortcut).

  • Remap an extension command's keyboard shortcut, say the Bookmark extension's toggle-bookmark (default Ctrl+Alt+K)

IN 2015, this involved editing configuration JSON files, but I don't know which one, or how. In 2021 there's a new UI, how do I find it?

0

13 Answers 13

252

Click File -> Preferences -> Keyboard shortcuts. Use the tab that opens up to edit and find available key bindings and assign them. Screenshot of VS Code Keyboard Shortcuts window

Open the keybindings.json file using the button in the tab-bar (screenshot below)

button to open keyboards.json


Historical Note: In very early versions of visual studio code, you would Click File -> Preferences -> Keyboard shortcuts and you would get JSON like this keybindings.json:

// Place your key bindings in this file to overwrite the defaults
[
    { "key": "ctrl+o", "command": "workbench.action.files.openFile" },

    { "key": "ctrl+alt+k", "command": "bookmarks.toggle", "when": "editorTextFocus" }
]

6
  • 16
    For mac users click Code instead of File.
    – Gwater17
    Commented Jun 17, 2017 at 2:35
  • Is there an easy way to copy keyboard shortcuts from VS?
    – Hrvoje T
    Commented Dec 6, 2018 at 8:01
  • 2
    Click on {} icon next to the Split Editor Icon to open keybindings.json
    – Shayan
    Commented Mar 13, 2019 at 11:45
  • 11
    For those of you looking for the {} it now looks like a document icon with an rounded arrow coming out of the left side. A shame their documentation fails to mention this.
    – frumbert
    Commented Aug 19, 2019 at 4:43
  • This answer originally told you to edit some JSON, updated May 2021 to show the modern VS Code Keyboard Shortcuts UI.
    – Warren P
    Commented May 14, 2021 at 21:58
55

If you want to change the advance settings of keyboard shortcut such as when then you can follow these steps:

Update:(Thanks @phdoerfler for pointing it out that icon has changed)

File->Preferences->Keyboard Shortcuts Click on icon on top right corner that says "Open Keyboard Shortcuts(JSON)" to open JSON version and place the keybinding.

Image showing icon

You can find this in Documentation here.

5
  • 7
    The icon changed. It's no longer a {} but a page with an arrow pointing onto it. The tooltip reads "Open Keyboard Shortcuts (JSON)". You can see it in the top right corner of this screenshot: code.visualstudio.com/assets/docs/getstarted/keybinding/…
    – phdoerfler
    Commented Oct 6, 2019 at 19:25
  • 1
    this only shows defaults, is the pattern really to edit defaults? I don't think it was before. Where is the custom keybindings.json stored? It is gone now.
    – safetyduck
    Commented Jan 6, 2020 at 12:34
  • @mathtick did you find the default keybindings.json? Cannot find it, only my own keybinding json.
    – Timo
    Commented Jan 2, 2021 at 16:44
  • @Timo I think I did by just searching. I have some keybindings.json file. The most confusing thing is that I think there are different locations that can get picked up ... and I was in some repo that had many copies of different keybindings.json.
    – safetyduck
    Commented Jan 2, 2021 at 20:53
  • 1
    The json file based editing method appears to be gone completely now in May 2021.
    – Warren P
    Commented May 14, 2021 at 22:01
27

The way to open the JSON file changed yet again in a recent version.

You need to click the middle of the three buttons in the tab bar.

enter image description here

You only need to do that if the change you need isn't possible on the normal settings screen.

2
  • This is still here in May 2021 but you can edit WHEN conditions without going in here.
    – Warren P
    Commented May 14, 2021 at 22:04
  • Seems it has changed yet again and can't figure out where they've now hidden the only way to actually edit key bindings.
    – MrYellow
    Commented May 15, 2023 at 23:09
23

On Windows:

  • go to File -> Preferences -> Keyboard shortcuts,
  • or press Ctrl+K, then Ctrl+S,
  • or edit %UserProfile%\AppData\Roaming\Code\User\keybindings.json file

On Mac:

  • go to Code -> Preferences -> Keyboard shortcuts,
  • or press Cmd+K, then Cmd+S

Keep in mind you can type things like shift ctrl c in the Search input in Keyboard Shortcuts panel to find commands by their keybindings.

Here you can find documentation which among other stuff contains also information about what When conditions you can use.

1
  • the WHEN condition editing is now visually done. The JSON editing parts are probably no longer relevant.
    – Warren P
    Commented May 14, 2021 at 22:03
7
  1. ctrl + shift + p
  2. Type open keyboard shortcut in the search bar

enter image description here

  1. It opens keyboard Shortcuts. Here you can customize shortcuts.

(For extra info follow from 4th point)

  1. There at the top right corner click on open keyboard shortcuts (JSON) (Refer to the image)

json icon

  1. There you can modify the key, command, and when. That is also cool.

I tried

{
    "key": "ctrl+a",
    "command": "workbench.action.terminal.selectAll",
    "when": "terminalFocus && !isMac"
}

by this now I can select all in vscode terminal

6

The latest version of Visual Studio Code 1.11.0 provides a rich and easy keyboard shortcuts editing experience using a new Keyboard Shortcuts editor. Read more here on their website.

2
  • The "rich and easy" UI is hamstrung and does not allow many types of edits.
    – MrYellow
    Commented May 15, 2023 at 23:10
  • Update: In the latest version of VSCode on MAC, it's rather: Code -> Settings -> Keyboard shortcuts or Cmd+K, then Cmd+S shortcut
    – josyanne
    Commented Jan 16 at 14:55
5

FYI on mac the keybindings.json file sits there:

/Users/your_user_name/Library/Application Support/Code/User/keybindings.json

4

I will not repeat others answers! And if like me! You get to install a mapping extension!

My prefered is Visual studio keys map

And the question would have been how you select it! How you change it ! Can we install multiples! And select between them!

First here some useful links about key binding and shortcuts

https://code.visualstudio.com/docs/getstarted/keybindings

https://code.visualstudio.com/docs/getstarted/tips-and-tricks

And before any, know that you can get to the keymaps extension by using the bottom left settings button for settings context menu! As in the picture bellow:

enter image description here

or through file>Preferences>keymap

enter image description here

Then you have to install one of the keymaps

enter image description here

The thing to know is that it will take place and make the changes right away!

What if you install another?

The new one take over! Or some mix! I couldn't tell! And you may have problems!

How you change from one to another?

Remove the old ! remove the new one! And install it again! That's the way that i found it works! Disabling and reenabling didn't work!

And better always let only one installed at a time!

Unfortunitly as by Now 2020-05-08 no options to select between keys mapping exist!

Undo a keymap

Just remove! You may need to restart the editor!

Restart the editor

Also note that if you uninstalled all and reinstalled the one you want! And changes didn't take place! Close the editor and reopen it! That's help!

I hope that's help and may be save you some searching time!

And sure in the future we will have better handling! As vscode is just keeping getting more awesome and awesome! So an option to select and better handling will is expected to be added! And we will wait for it!

1

On Windows: Ctrl + K, then S

On Mac: + K then + S

This opens Keyboard Shortcuts Editor. It's searchable/filterable by either shortcut name or the key combination itself (example: type "ctrl" to see all bindings to the CTRL key.)

Image: vscode search keyword shortcuts panel

0

To change keybord shortcut bindings in vs go to settings > Keyboard shortcuts

enter image description here

Then You will see this kind of page. In this red color box as I highlighted here you can insert the features such as delete, delete left these kind of activities you can search and then you can edit the keybindings as you wish.

enter image description here

also when you get your mouse pointer near some command it shows pen type icon to edit that specific key. Like this

enter image description here

Bu clicking that one you can add preferred key bindings as well like this.

enter image description here

0

On a Mac, if you prefer the same behavior for the home and end keys as in ubuntu, which is to go to the beginning or end of the line when these keys are pressed, edit your keybindings.json file like this

[
  {
    "key": "home",
    "command": "cursorLineStart",
    "when": "editorTextFocus"
  },
  {
    "key": "end",
    "command": "cursorLineEnd",
    "when": "editorTextFocus"
  },
]
0

On Windows:

  • window icon, type %APPDATA%
  • now, search for keybindins.json file
  • from microsoft quick reference to create/modify shortcuts

On Linux / OSx

I didnt do that but, I guess you can find for the keybindins.json file too

find /usr/bin/code -name keybindins.json

If you can't get the right path, do that:

whereis vscode
or
wheis code
-1
  1. Open Key Shortcuts from Preferences -> Keyboard Shortcuts
  2. Search for the action in search field
  3. Right click on one of the results and select "Show same keybindings"
  4. Delete the conflicting key binding!

Not the answer you're looking for? Browse other questions tagged or ask your own question.