Assigning keyboard shortcuts to VS Code tasks

I like keyboard shortcuts, actually can’t get enough of them. After a life time with Eclipse, old habits die hard and I find myself re-discovering this over and over, so it’s time I wrote it down. Note to self: how to assign a key combination to a VS code task.

Add your task to .vscode/tasks.json, eg. for my latest pet project, eg.

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile F99",
            "type": "shell",
            "command": ".vscode/build-f99.sh",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        },
        {
            "label": "Run F99",
            "type": "shell",
            "command": ".vscode/run-dosbox.sh",
            "group": "test",
            "presentation": {
                "reveal": "always",
                "focus": false,
                "panel": "new"
            }
        }
    ]
}

Then CRTL + P -> “Preferences: Open Keyboard Shortcuts (JSON)” -> assign key combinations to your tasks. Note that the “args” property needs to be exactly the same name as the task label.

[
    {
        "key": "ctrl+alt+9",
        "command": "workbench.action.tasks.runTask",
        "args": "Run F99"
    },
    {
        "key": "ctrl+alt+0",
        "command": "workbench.action.tasks.runTask",
        "args": "Compile F99"
    }
]

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.