Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

VS Code allows multiple tasks to be defined in the ["tasks"] array in tasks.json and the one with the property isBuildCommand: true gets given the keyboard shortcut Ctrl+Shift+B by default.

I would like to assign different keyboard shortcuts to each of the tasks I've created. Is this possible, and if so how?

All I've found so far is the ability to assign a shortcut to the command workbench.action.tasks.runTask which will popup a menu of all the tasks in alphabetical order that I can up/down arrow through. I would like to configure Code to run each task directly with one key combination.

like image 349
Jonathan Corwin Avatar asked May 05 '15 15:05

Jonathan Corwin


People also ask

How do I create a custom shortcut in VS Code?

All keyboard shortcuts in VS Code can be customized via the keybindings. json file. To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and select the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar. This will open your keybindings.

How do I make multiple cursors in VS Code?

For multi-line selection, Ctrl+Alt+Down / ⌘+Alt+Shift+Down will extend your selection or cursor position to the next line.


1 Answers

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" } 
like image 148
tdhsmith Avatar answered Sep 18 '22 15:09

tdhsmith