Is it possible to assign different shortcuts to different tasks in VS Code?

As of VS Code 1.10, you can use the workbench.action.tasks.runTask command in your keybindings, and pass in the task's name as your argument.

The VS Code task documentation gives this example:

{
    "key": "ctrl+h",
    "command": "workbench.action.tasks.runTask",
    "args": "build"
}

As of VSCode 1.19 (Feb 2018):

In /myproject/.vscode/tasks.json you need to add a label (formerly, now deprecated: taskName) to your npm task.

(I named my label the same as the package.json script I intend to run. But that's just personal style, not technical need):

    {
        "label": "ui",
        "type": "npm",
        "script": "ui"
    }

Then you reference that task by its label in your user keybindings /home/johndoe/.config/Code/User/keybindings.json:

{"key": "ctrl+r",
    "command": "workbench.action.tasks.runTask",
    "args": "ui"
},

In case you wondered: No, there are no project-level keybinding in vscode. Reasons here


I just submitted a PR for this: https://github.com/Microsoft/vscode/pull/10676

So once it's merged you will have the ability to assign any task to a keyboard shortcut.


Yes there is one other property that can be used to bind a shortcut. Its name is isTestCommand. If set to true it bind Ctrl+Shift+T to the task. We do have an internal work item to allow to bind arbitrary short cuts to tasks.