Home > Blockchain >  Key-Binding for custom command in a vscode extension
Key-Binding for custom command in a vscode extension

Time:02-22

I want to do key-binding for custom command in my vs-code extension. I have written below code but not working.


import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    const savecommand = 'custom-command.key-binding';

    const saveComamndHandler = vscode.commands.registerCommand(savecommand, () => {

        vscode.window.showInformationMessage("Saved file");

    });

    context.subscriptions.push(saveComamndHandler);

}

package.json:

    "main": "./dist/extension.js",
    "activationEvents": [
        "onCommand:custom-command.key-binding"
    ],
    "categories": [
        "Keymaps"
    ],
    "contributes": {
        "keybindings": [
            {
                "key": "ctrl s",
                "command": "custom-command.key-binding'"

            }
        ]
    },

can anyone help me?

CodePudding user response:

Is custom-command the name of your extension?

You have a typo below

    "contributes": {

         "keybindings: [
            {
                "key": "ctrl s",

                // I see you have a stray single quote in the following line
                // "command": "custom-command.key-binding'"

                "command": "custom-command.key-binding"

            }
         ]
      }
  • Related