Sindre
Sindre

Reputation: 140

How do I add a keyboard shortcut to activate/disable a VSCode extension?

I want to be able to turn certain extensions on and off with a keyboard shortcut. But didn't found out how to do keybindings for extension activation

Specifically I wanna do this for VSCodeVim. So that I can use it more often and become more used to using Vi

Upvotes: 2

Views: 5646

Answers (2)

starball
starball

Reputation: 51935

Some extensions contribute a dedicated command to toggle their own functionality. As for something builtin to VS Code that isn't extension specific, I'm not aware of that existing at the time of this writing. The only commands I see to enable extensions right now are workbench.extensions.action.enableAll and workbench.extensions.action.enableAllWorkspace. You could raise a feature-request issue ticket asking for a pair of commands that take a set of extension IDs to enable/disable, similar to workbench.extensions.action.showExtensionsWithIds.

I tried to create a janky workaround with that command but got stuck on moving tab navigation. Here's the failed/stuck attempt if you're curious:

{
    "key": "ctrl+b",
    "command": "runCommands",
    "args": { "commands": [
        {
            "command": "workbench.extensions.action.showExtensionsWithIds",
            "args": [["ms-vscode.makefile-tools", "twxs.cmake"]],
        },
        "list.focusFirst",
        // how to move tab focus?
    ]},
},

Upvotes: 0

isAif
isAif

Reputation: 2354

To toggle Vim mode in Vscode do the following:

  1. Use 'CTRl+Shift+P' to open vscode command palette

  2. type 'vim toggle', you will see 'Vim: Toggle Vim Mode' option

  3. select it and press enter to toggle vim mode.

To add keybinding (shortcut) for toggling :

  1. open command palette using 'Ctrl+shift+p'
  2. type 'shortcuts'
  3. select 'Preferences: Open Keyboard Shortcuts' and press enter
  4. search 'toggleVim'
  5. click on 'Keybinding' column
  6. press the buttons you want for the shortcut and press enter

Not every extension can be disabled by this method, But all extensions can be disabled or enabled for a particular workspace.

Upvotes: 10

Related Questions