Rach Smith's Notes & Nuggets

Quickly toggle Copilot suggestions on and off with your keyboard

note : development Added August 25, 2022

Overall, [[Maybe I'm in the sweet spot for GitHub Copilot|I'm a fan of GitHub Copilot]]. Sometimes I just want it to get out of the way. I wanted to figure out how to toggle it off and on again with my keyboard.

At first I figured I could assign the extension's enable/disable command to a VSCode keyboard shortcut.

keybindings.json
[
  {
    "key": "ctrl+c",
    "command": "github.copilot.toggleCopilot",
    "when": "editorFocus"
  }
]

But then when I went to use the shortcut to disable it, the extension popped up this confirmation dialog in the corner. The focus was still in the editor so there was no way to select 'Disable Globally' without using my mouse. Super annoying.

a dialog message asking \
why?

I went to the [GitHub community discussions] to see if anyone had requested a change to this behaviour. It turns out there were multiple posts asking about this, but one of them included a workaround from Dan Davidson.

It turns out we can attach a keyboard command to update the workspace setting github.copilot.inlineSuggest.enable. When that setting is set to false, Copilot will stop with the inline suggestions.

By using the Settings Cycler extension (first time I'd heard about this one, btw) we can assign a keyboard shortcut to toggle the setting on and off. Here's mine (I chose to use ctrl+c):

keybindings.json
{
  "key": "ctrl+c",
  "command": "settings.cycle.copilot",
  "when": "editorFocus"
}
settings.json
"settings.cycle": [{
   id": "copilot",
     "overrideWorkspaceSettings": true,
     "values": [{
       "github.copilot.inlineSuggest.enable": false
     },
     {
       "github.copilot.inlineSuggest.enable": true
     }
  ]},
],

Comments

Comments are closed. You can still reply by email.

  • Daniel Worthington

    Thanks Rach! This is great, and Settings Cycler is very cool. I ended up having it toggle my cursor shape too so I have a visual indication of whether Copilot is on or off.

    • Rach Smith OP

      ooooh. Sometimes I find myself wondering if it is on or off... toggling the cursor is a great idea! Thanks!

  • Simon Boehm

    This was helpful to me! However, there's now an easier way to do it, without using an extra extension:

    Put this in keybindings.json:

      {
        "command": "github.copilot.toggleCopilot",
        "key": "cmd+shift+x"
      },
    

    When you wrote this post the command didn't exist yet.