Automatically generate commit messages using GitHub Copilot when opening git commits in Neovim.
When you press C (uppercase) in LazyGit to create a commit, this plugin automatically generates a commit message based on your staged changes using CopilotChat.
- Automatic commit message generation when opening
gitcommitbuffers - Uses CopilotChat to analyze staged changes and generate meaningful commit messages
- Follows commitizen convention by default
- Configurable prompts for different commit message styles
- Manual trigger command for regenerating messages
- Health check integration (
:checkhealth auto-commit-message)
- Neovim 0.9+
- CopilotChat.nvim - Chat interface for GitHub Copilot
- copilot.lua - GitHub Copilot integration
- neovim-remote (
nvr) - For LazyGit integration - Treesitter parsers -
markdownandmarkdown_inline
neovim-remote:
pip install neovim-remoteTreesitter parsers (in Neovim):
:TSInstall markdown markdown_inline{
"ryancraigdavis/AutoCommitMessage.nvim",
dependencies = {
"CopilotC-Nvim/CopilotChat.nvim",
},
ft = "gitcommit",
opts = {},
}use {
"ryancraigdavis/AutoCommitMessage.nvim",
requires = {
"CopilotC-Nvim/CopilotChat.nvim",
},
config = function()
require("auto-commit-message").setup()
end,
}require("auto-commit-message").setup({
-- Enable/disable auto-generation on gitcommit filetype
enabled = true,
-- Prompt sent to CopilotChat for generating commit messages
prompt = 'Write commit message for the change with commitizen convention. '
.. 'Write clear, informative commit messages that explain the "what" and "why" '
.. 'behind changes, not just the "how". '
.. 'Return ONLY the commit message, no explanation or markdown formatting.',
-- Only use staged changes (true) or all changes (false)
staged_only = true,
-- Delay in ms before triggering generation (allows buffer to fully load)
defer_delay = 100,
-- Show notification when commit message is inserted
notify = true,
-- Auto-close CopilotChat window after generation
auto_close_chat = true,
-- Keymap for manual trigger (nil = disabled)
-- Example: "<leader>gcm"
keymap = nil,
})You can customize the prompt for different commit message styles:
Conventional Commits:
prompt = "Write a commit message following Conventional Commits specification. "
.. "Format: <type>(<scope>): <description>. "
.. "Types: feat, fix, docs, style, refactor, test, chore. "
.. "Return ONLY the commit message.",Gitmoji:
prompt = "Write a commit message using gitmoji convention. "
.. "Start with an appropriate emoji. "
.. "Return ONLY the commit message.",For this plugin to work with LazyGit, you need to configure LazyGit to open files in the parent Neovim instance using nvr.
~/.config/lazygit/config.yml:
os:
edit: 'nvr --servername $NVIM --remote-wait-silent {{filename}}'
editAtLine: 'nvr --servername $NVIM --remote-wait-silent +{{line}} {{filename}}'
editAtLineAndWait: 'nvr --servername $NVIM --remote-wait-silent +{{line}} {{filename}}'
editInTerminal: falseReplace nvr with the full path if it's not in your PATH (e.g., /home/user/.local/bin/nvr).
If you're using lazygit.nvim:
{
"kdheepak/lazygit.nvim",
lazy = true,
cmd = { "LazyGit" },
keys = {
{ "<leader>gs", "<cmd>LazyGit<cr>", desc = "LazyGit" },
},
config = function()
vim.g.lazygit_floating_window_scaling_factor = 0.9
vim.g.lazygit_use_neovim_remote = 1
end,
}- Open Neovim in a git repository
- Open LazyGit (e.g.,
<leader>gs) - Stage your changes (select files, press
space) - Press
C(uppercase, Shift+C) to commit with editor - Wait for CopilotChat to generate the commit message
- Edit the message if needed
- Save and quit (
:wq) to complete the commit
Note: Lowercase c in LazyGit opens a simple inline input and won't trigger the editor or this plugin.
| Command | Description |
|---|---|
:AutoCommitMessage |
Manually generate a commit message |
:AutoCommitMessageEnable |
Enable auto-generation |
:AutoCommitMessageDisable |
Disable auto-generation |
Run :checkhealth auto-commit-message to verify your setup. It checks for:
- neovim-remote (nvr) installation
- CopilotChat.nvim presence
- copilot.lua presence
- Treesitter markdown parsers
- LazyGit configuration
User presses <leader>gs
│
▼
LazyGit opens in floating terminal
│
▼
User stages files and presses 'C' (uppercase)
│
▼
LazyGit invokes: nvr --servername $NVIM --remote-wait-silent COMMIT_EDITMSG
│
▼
COMMIT_EDITMSG opens in parent Neovim (new buffer)
│
▼
Neovim detects filetype = "gitcommit"
│
▼
Plugin autocmd fires, checks if first line is empty
│
▼
CopilotChat.ask() called with staged diff
│
▼
Copilot generates commit message
│
▼
Callback inserts message into COMMIT_EDITMSG buffer
│
▼
User edits if needed, then :wq
│
▼
nvr returns control to LazyGit
│
▼
LazyGit completes the commit
- Verify
nvris installed:which nvr - Check LazyGit config uses correct nvr path
- Ensure
$NVIMis set (runecho $NVIMin Neovim's:terminal)
Install treesitter parsers:
:TSInstall markdown markdown_inline- Check
:messagesfor errors - Verify CopilotChat is working:
:CopilotChatCommitStaged - Run
:checkhealth auto-commit-message
- Run
lazygit --print-config-dirto verify config location - Check config syntax in
config.yml - Make sure you're pressing uppercase
C, not lowercasec
MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.