VSCode Copilot Chat | How to change shortcut key?

01kg - Aug 20 - - Dev Community

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

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.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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .