vscode 扩展中自定义命令的键绑定

Key-Binding for custom command in a vscode extension

我想在我的 vs 代码扩展中为自定义命令进行键绑定。我写了下面的代码但没有用。


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'"

            }
        ]
    },

谁能帮帮我?

custom-command 是您的分机的 name 吗?

下面有错字

    "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"

            }
         ]
      }