DEV Community

01kg
01kg

Posted on • Edited on

2

VSCode Copilot Chat | How to change shortcut key?

Image description

If your hit "Enter", the prompt is sent. However, for Copilot better understanding a longer prompt, it is good to use new lines to separate paragraphs. I hope, by default, hitting "Enter" means "new line" instead of "Send prompt".

TL;DR

WARNING: GitHub Copilot Chat plugin still hasn't reached stable, so the solutions below would out of date quickly, especially the GUI one. Follow it with your own understanding.

Option 1: Using GUI

  1. VS Code -> File -> Preferences -> Keyboard Shortcuts
  2. Search workbench.action.chat.submit, change it to Ctrl + Enter or anything you like.
  3. Search workbench.action.chat.submitSecondaryAgent, change it to Ctrl + Alt + Enter or anything you like.

The result in "Keyboard Shortcuts" page:

Image description

The result in GUI:

Image description

Option 2: Using keybindings.json

(This method could not override existing keybindings)

  1. Open the Command Palette in Visual Studio Code by pressing Cmd+Shift+P on your Mac.
  2. Type Preferences: Open Keyboard Shortcuts (JSON) and select it.

Add the following JSON configuration to the keybindings.json file (GitHub Copilot Chat v0.23.1):

// Place your key bindings in this file to override the defaults
[
    // Add new keybindings
      {
        "key": "ctrl+enter",
        "command": "workbench.action.chat.submit",
        "when": "chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatLocation != 'editing-session'"
      },

    // remove default keybindings
    // without these, the default keybindings will still work
      {
        "key": "enter",
        "command": "-workbench.action.chat.submit",
        "when": "chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatLocation != 'editing-session'"
      }
    ]
Enter fullscreen mode Exit fullscreen mode

(GitHub Copilot Chat v0.22.2):

// Place your key bindings in this file to override the defaults
[
// Add new keybindings
  {
    "key": "ctrl+enter",
    "command": "workbench.action.chat.submit",
    "when": "chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatLocation != 'editing-session' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && !isApplyingChatEdits && chatLocation == 'editing-session'"
  },
  {
    "key": "ctrl+alt+enter",
    "command": "workbench.action.chat.submitSecondaryAgent",
    "when": "chatInputHasText && inChatInput && !chatInputHasAgent && !chatSessionRequestInProgress"
  },

// remove default keybindings
// without these, the default keybindings will still work
  {
    "key": "enter",
    "command": "-workbench.action.chat.submit",
    "when": "chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatLocation != 'editing-session' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && !isApplyingChatEdits && chatLocation == 'editing-session'"
  },
  {
    "key": "ctrl+enter",
    "command": "-workbench.action.chat.submitSecondaryAgent",
    "when": "chatInputHasText && inChatInput && !chatInputHasAgent && !chatSessionRequestInProgress"
  }
]
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more