Search code examples
key-bindingsvisual-studio-code

How do I set a keybinding for an extension in VSCode?


I am using VSCode to write a Swagger (OpenAPI) specification and I want to make use of a specific extension to aid in the writing of that specification.

The extension I have installed does not supply a key binding for me to easily invoke it with.

How do I go about adding the key binding? I have attempted to make it work by clicking File->Preferences->Keyboard Shortcuts and editing the keybindings.json file, but without success thus far.

It seems I have to discover the extension's command and I don't know where to find that, doesn't seem to be readily apparent on the extension summary page either when I click on the extensions hub, then on the extension I want to use.


Solution

  • If you open your extension's information window, you might see a Contributions tab, and in there you might see a Commands list.

    enter image description here

    From there you can find the command that you want and bind to it in your keybindings.json file or File -> Preferences -> Keyboard Shortcuts

    [
        {
            "key": "ctrl+enter",
            "command": "command.execute",
            "when": "editorTextFocus"
        }
    ]