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
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
andgit log
To add this functionality:
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 yourkeybindings.json
file where you can save your custom keybinds.Inside, paste these three new keybindings:
Replace the "key" with the keyboard shortcut you want for the two behaviours.
"key": "ctrl+m"
Save
keybindings.json
How to use
My defaults are:
Simple and easy, if you are using
Terminal in VSCode
, you can useCtrl+I
to suggest it, make sure that your cursor is in terminal.I’m using following version, if you don’t see anything, please update to that corresponding.
Be noticed that Windows Terminal is not supported keyboard trigger like this yet.