skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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:

    • Ctrl+; (Keybinding #1) -> Opens the source control view on the side, and gets copilot to fill in the suggested commit message in the box at the top.
    • Ctrl+# (Keybinding #2 & #3) -> Commits the message currently in the box, and returns focus either to:
      • the Integrated Terminal, if the shortcut was pressed while the focus (your text cursor) was in the terminal.
      • The Editor (the file currently open).

  2. Simple and easy, if you are using Terminal in VSCode, you can use Ctrl+I to suggest it, make sure that your cursor is in terminal.

    enter image description here

    enter image description here

    I’m using following version, if you don’t see anything, please update to that corresponding.

     - Version: 1.245.1217
     - Build: nightly
     - Editor: vscode/1.95.3
    

    Be noticed that Windows Terminal is not supported keyboard trigger like this yet.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search