Martin Hjärtmyr

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

Trading from your terminal: setting up Hermes Agent with Montrose

Trading from your terminal: setting up Hermes Agent with Montrose

How I connected my Hermes Agent to Montrose for terminal-based portfolio tracking, trade tickets, and automated daily summaries.

Adding Umami analytics to the OpenClaw morning brief

Adding Umami analytics to the OpenClaw morning brief

An agent skill that fetches traffic data from Umami, and how it fits into a daily automated briefing.

Setting up Google Calendar sync for OpenClaw

Setting up Google Calendar sync for OpenClaw

How I set up read-only Google Calendar sync for my personal AI assistant running on a home server VM.

Better Clipboard Handling in Claude Code

Better Clipboard Handling in Claude Code

A plugin that makes clipboard operations in Claude Code more reliable and natural to use.

Get notified when Claude Code needs your input

Get notified when Claude Code needs your input

Stop constantly checking your terminal. Set up notifications that alert you when Claude Code is ready for your input.

Auto-format generated Code with Claude Code Hooks

Auto-format generated Code with Claude Code Hooks

How to set up a PostToolUse hook in Claude Code to automatically run prettier after every file edit or write operation.

PWA Web Share Target on Android: The Absolute URL Fix

PWA Web Share Target on Android: The Absolute URL Fix

Getting the Web Share Target API to work on Android PWAs can be frustrating. Your manifest looks correct, but the app never appears in the share sheet. Here is what finally worked.

Standard function keys on external keyboards in MacOS

Standard function keys on external keyboards in MacOS

Configure Karabiner Elements to use standard function keys on external keyboards while keeping media keys on your MacBook.

How to Clear Cloudflare Cache using a webhook

How to Clear Cloudflare Cache using a webhook

Automatically purge Cloudflare cache using webhooks and API tokens.