Visual Studio Code make a keybind for a right-click menu button

Viewed 554

For example, in VS Code, I can right click on a variable, select Peek > Peek Type Definition.

How can I make a keybinding for this (currently there is no keybinding set)? How can I even find the appropriate command for the keybindings.json file, if the "Peek Type Definition" button is not mapped to anything?

2 Answers

Go to the Gear Icon in the lower right. click it and select Keyboard Shortcuts. It will open the Keyboard Shortcuts editor.

In that editor's input box at the top, type peek type and you will get 2 entries shown. One is:

Peek Type Definition
editor.action.peekTypeDefinition

That command does not have a default shortcut, but you can make one yourself.

If you hover over that entry, a + sign will appear to its left, click it and an input dialog opens where you can enter your chosen keybinding.

It will make a keybinding in your keybindings.json like

{
  "key": "alt+5",                 // whatever you chose here
  "command": "editor.action.peekTypeDefinition"
}

When you right click, the window that pops up is called the context menu. Some keyboards have a context menu button. Unfortunately, VSCode does not use this as the command in the keyboard shortcuts, so there is no way to do this through the keyboard shortcuts menu.

Alternatively, you could use SharpKeys, a utility that lets you remap keys on your keyboard. Personally, I have my right alt key mapped to the context menu button. In SharpKeys, the context menu button does not have a name, so it is just called Special: Application (E0_5D). This allows you to right click from the keyboard.

In the screenshot below, you can see the remap in the highlighted section. enter image description here

Related