Generate Commit Messages with Ollama in Neovim

Generate conventional commit messages from staged diffs using Ollama. Run it locally for privacy and offline, or use cloud models for speed.

Generate Commit Messages with Ollama in Neovim

Maybe you are already writing commit messages inside vim. Whether it’s via git commit, lazygit, fugitive, or any other terminal-based git client - the commit buffer opens in your editor. The friction isn’t the tool, it’s coming up with a good message.

Cloud AI commit generators solve that by sending your staged diffs to an API. That works, but it means your code leaves your machine every time you commit.

I wrote generate-commit-message.nvim to keep the entire workflow inside vim. It reads your staged diffs, runs them through Ollama, and inserts a conventional commit message directly into the commit buffer.

Run it locally and nothing leaves your machine. Works offline. No API keys to manage, no billing, no rate limits. The trade-offs: you need decent hardware, and generation takes longer than cloud models. For commit messages though, the difference is seconds.

Quick Start

Install Ollama and pull a model:

ollama pull gemma4

Then install the plugin. With for example lazy.nvim:

{
  "martinhjartmyr/generate-commit-message.nvim",
  opts = {
    summary_model = "gemma4",
    commit_model = "gemma4",
    auto_trigger = true,
  },
}

The plugin defaults to http://localhost:11434/api/generate - everything stays local out of the box.

How It Works

Two phases:

  1. Per-file summaries - Each staged file’s diff is sent to Ollama for a brief summary. Parallel for cloud URLs, sequential for local.
  2. Combined message - Summaries are combined, commit type detected (fix, feat, refactor, chore), and a conventional commit message is generated.

The result lands directly in your commit buffer.

Usage

Stage your changes and open a commit buffer:

git add -A
git commit

Press <leader>cm to generate and insert the message. Or run the command from anywhere:

:GenerateCommitMessage

Auto-Trigger

With auto_trigger = true, the plugin detects when you open an empty gitcommit buffer and generates the message immediately. No keybinding needed - open the commit buffer and the message is generated.

Configuration

All options are optional:

require("generate_commit_message").setup({
  summary_model = "gemma4",
  commit_model = "gemma4",
  max_file_diff = 4000,
  auto_trigger = true,
  ollama_url = "http://localhost:11434/api/generate",
  api_key = nil,
  num_ctx = 8192,
})

api_key falls back to $OLLAMA_API_KEY if set. Leave it nil for local usage.

Cloud Models

If you prefer speed or don’t have the hardware for local models, the plugin works with Ollama’s cloud API too:

require("generate_commit_message").setup({
  summary_model = "gemini-3-flash-preview",
  commit_model = "gemini-3-flash-preview",
  ollama_url = "https://ollama.com/api/chat",
})

Set OLLAMA_API_KEY in your environment. The plugin switches to the messages API format automatically for cloud URLs.

Source

MIT licensed: github.com/martinhjartmyr/generate-commit-message.nvim

More Articles