A keybindings.json per workspace in Visual Studio Code

Not a perfect solution, but I found a workaround to create a keybinding that can be activated at a workspace level.

In the workspace .vscode/settings.json file, set a new setting to true. (Because the setting is not registered by vscode or any extension, it will be displayed faded out in the editor – This is OK):

  "workspaceKeybindings.myAwesomeTask.enabled": true // setting can be anything you want

Then create the keyboard shortcut in the user keybindings.json, and add a “when” condition for the setting you created:

{ 
  "key": "ctrl+; ctrl+n",
  "command": "workbench.action.tasks.runTask",
  "args": "My Awesome Task",
  "when": "config.workspaceKeybindings.myAwesomeTask.enabled" // Must be "config.{settingName}"
},

This keybinding can be set as active in any workspaces you want.

Leave a Comment