DEV Community

01kg
01kg

Posted on • Edited on

VSCode Copilot Chat | How to change shortcut key? (updates to GitHub Copilot Chat v0.26.7)

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.26.7):

// Place your key bindings in this file to override the defaults
[

    /// ask mode

    {
        "key": "ctrl+enter",
        "command": "workbench.action.chat.submit",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput && chatMode == 'ask' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatMode == 'ask' || chatInstructionsAttached && chatRequestIsPaused && inChatInput && chatMode == 'ask' || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress && chatMode == 'ask'"
    },
    {
        "key": "enter",
        "command": "-workbench.action.chat.submit",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput && chatMode == 'ask' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatMode == 'ask' || chatInstructionsAttached && chatRequestIsPaused && inChatInput && chatMode == 'ask' || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress && chatMode == 'ask'"
    },
    {
        "key": "alt+enter",
        "command": "workbench.action.chat.submitWithCodebase",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput || chatInputHasText && inChatInput && !chatSessionRequestInProgress || chatInstructionsAttached && chatRequestIsPaused && inChatInput || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress"
    },
    {
        "key": "ctrl+enter",
        "command": "-workbench.action.chat.submitWithCodebase",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput || chatInputHasText && inChatInput && !chatSessionRequestInProgress || chatInstructionsAttached && chatRequestIsPaused && inChatInput || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress"
    },


    /// edit & agent mode


    {
        "key": "enter",
        "command": "-workbench.action.edits.submit",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput && chatMode != 'ask' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatMode != 'ask' || chatInstructionsAttached && chatRequestIsPaused && inChatInput && chatMode != 'ask' || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress && chatMode != 'ask'"
    },
    {
        "key": "ctrl+enter",
        "command": "workbench.action.edits.submit",
        "when": "chatInputHasText && chatRequestIsPaused && inChatInput && chatMode != 'ask' || chatInputHasText && inChatInput && !chatSessionRequestInProgress && chatMode != 'ask' || chatInstructionsAttached && chatRequestIsPaused && inChatInput && chatMode != 'ask' || chatInstructionsAttached && inChatInput && !chatSessionRequestInProgress && chatMode != 'ask'"
    },
]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)