25

The Atom editor has a command that is bound to 'ctrl-.' that is called the keybinding resolver:

enter image description here

Once you activate key-resolver mode, any key you subsequently press will tell you what command(s) are bound to it, in all possible contexts, and show you which command/context "wins out". You then toggle the mode off by pressing ctrl-g.

This is useful for when you want to know if a key binding is free, or if a key key binding isn't doing what you expect.

Here's an example output for when I press ctrl-n in an editor context , where I can see that the emacs keybinding 'next-line' is taking precedence:

enter image description here

Emacs also has a similar feature with it's ctrl-h k (help keys) command.

Yes, I can usually glean the information I need by browsing the Default Keyboard Shortcuts and keybindings.json, but this can be hard to do if a key is bound in a lot of different contexts.

Is there a feature similar to this in VSCode?

Community
  • 1
  • 1
vt5491
  • 2,254
  • 2
  • 22
  • 34
  • https://stackoverflow.com/questions/47304223/how-can-i-find-what-command-a-keybinding-is-bound-too-easily?noredirect=1#comment81572072_47304223 – tgerdin Nov 16 '17 at 16:31
  • hey, nice dark&light theme !! Is it public? What is its name ? Thank you! – Ciprian Tomoiagă Sep 11 '18 at 10:13
  • I added an answer that goes over this, but I'm guessing the [Developer: Toggle Keyboard Shortcuts Troubleshooting](https://code.visualstudio.com/docs/getstarted/keybindings#_troubleshooting-keybindings) feature was added much later after this question was asked. – Erdős-Bacon Sep 01 '21 at 17:55

4 Answers4

15

Unfortunately not and as far as I know it currently can't be done using extensions API. The feature request for this feature can be found here.

Visual Studio Code evaluates keybindings as follows:

  • the rules are evaluated from bottom to top.
  • the first rule that matches, both the key and in terms of when, is accepted.
  • no more rules are processed.
  • if a rule is found and has a command set, the command is executed.

The additional User/keybindings.json rules are appended at runtime to the bottom of the default rules, thus allowing them to overwrite the default rules.

For now you can check what is bound to a specific key using Quick Outline Preferences: Open Keyboard Shortcuts. To open this view, press ++P on Mac or Ctrl+Shift+P on Windows & Linux, and look for this option.

enter image description here

Looking at the development pace this might be doable as extension or included in vscode in upcoming months.

Pro Q
  • 4,391
  • 4
  • 43
  • 92
Jakub Synowiec
  • 5,719
  • 1
  • 29
  • 37
8

Not sure when the feature was added, but now in the Keyboard Shortcuts menu reached via Ctrl+K, Ctrl+S, you can click the small keyboard icon in the right of the search field, or alternatively press Alt+K, to Record Keys

Record Keys button

vscode will capture the key command you enter and display results for it, rather than having to enter text description of the key command in correct syntax, which is almost like the keybinding resolver in atom.

Koleok
  • 511
  • 4
  • 4
4

I think it's less full-featured, but the command Developer: Toggle Keyboard Shortcuts Troubleshooting in VS Code does a rough equivalent of this. See these docs here: https://code.visualstudio.com/docs/getstarted/keybindings#_troubleshooting-keybindings

Here's an example of the kind of output you'll see (as of Sep 1, 2021): enter image description here

Unlike the Atom version, it's only showing the first matched entry (which is matched according to the keybinding precedence rules), but at least it's some info.

It can also be hard to tell all the when clauses that matter. For that, take a look these docs: https://code.visualstudio.com/api/references/when-clause-contexts#inspect-context-keys-utility (context keys are the when clauses in this case). Knowing the active when clauses, the exact key-combination, and then looking at the Keyboard Shortcuts page and sorting it by precedence for the pertinent key-combo should ultimately give the same functionality, just more hassle than getting that info in Atom.

Erdős-Bacon
  • 748
  • 8
  • 16
1

A simple way to find out the keybindings is to look for it in the Advanced key binding editor.

Go to Keyboard shortcuts (File -> Preferences -> Keyboard Shortcuts or ctrl + k, ctrl + s) and press "For the Advanced customizations open and edit keybinding.json". screen shot

After that, a 2 tabbed window will be opened and in there you can find (using ctrl + f obviously) the wanted key. screen shot

upe
  • 1,862
  • 1
  • 19
  • 33
Aharon Ohayon
  • 1,171
  • 1
  • 17
  • 20