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.
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
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.
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"
}
Replace the "key" with the keyboard shortcut you want for the two behaviours.
"key": "ctrl+m"
Save keybindings.json
My defaults are: