gitvisual-studio-codekeyboard-shortcutsgithub-copilot

Is there a command or keyboard shortcut to request the Copilot suggested commit message in the terminal?


Stars button makes copilot write a commit message

I've seen the sparkle icon in the terminal for adding the suggestion, though this requires two mouse clicks which then pastes into the terminal line git commit -m "[Copilot suggestion here...].

Is there a way to activate this via a keyboard shortcut, or a command? E.g. if you are staging files via something like git add -p you are already using the keyboard as opposed to the mouse, so it would be a great help if there was a keyboard shortcut for requesting the commit message suggestion once all files are staged.


Solution

  • Thanks to @Alfred Luu's idea of using keybindings.

    When you are staging commits in the integrated terminal, it's useful to have copilot suggest the commit message, allow you to make any edits, and then commit- without needing the mouse and returning the focus to the terminal for further commands like git status and git log

    To add this functionality:

    1. In VSCode open your keyboard shortcuts to add a new shortcut. You can do this by pressing f1 and then type Preferences: Open Keyboard Shortcuts (JSON). This will open your keybindings.json file where you can save your custom keybinds.

    2. Inside, paste these three new keybindings:

        {
            "key": "ctrl+oem_1",
            "command" : "runCommands",
            "args": {
                "commands": [
                    "workbench.view.scm",
                    "github.copilot.git.generateCommitMessage",
                ]
            }
        },
        {
            "key" : "ctrl+oem_7",
            "command" : "runCommands",
            "args": {
                "commands": [
                    "git.commit",
                    "workbench.action.focusActiveEditorGroup",
                ]
            },
            "when": "!terminalFocus"
        },
        {
            "key": "ctrl+oem_7",
            "command": "runCommands",
            "args": {
                "commands": [
                    "git.commit",
                    "workbench.action.terminal.focus",
                ]
            },
            "when": "terminalFocus"
        }
    
    1. Replace the "key" with the keyboard shortcut you want for the two behaviours.

      • E.g.: "key": "ctrl+m"
    2. Save keybindings.json

    How to use

    My defaults are: