Skip to main content

AI Chat in Neovim with CodeCompanion

·364 words·2 mins
Kostiantyn Lysenko
Author
Kostiantyn Lysenko

I went looking for a good AI chat plugin for Neovim (AstroNvim specifically) — something that lets me ask questions about the codebase, get inline edits, and generate commands without leaving the editor.

What I tried
#

opencode.nvim
#

opencode.nvim looked promising, but felt rough around the edges. To ask a simple question I had to: <Leader>Oni → type the prompt → Ctrl-\ Ctrl-nCtrl-w w. Some interface lines were visually broken too. I’m sure it could all be configured and fixed, but I wanted something that just works.

CodeCompanion.nvim
#

CodeCompanion.nvim just worked. Chat, inline edits, command generation — all out of the box with minimal config.

Installing CodeCompanion in AstroNvim
#

1. Add the community module
#

In lua/community.lua:

---@type LazySpec
return {
  "AstroNvim/astrocommunity",
  { import = "astrocommunity.pack.lua" },
  { import = "astrocommunity.editing-support.codecompanion-nvim" },
}

2. Configure the adapter
#

Create lua/plugins/codecompanion.lua. CodeCompanion supports API-key-based adapters (OpenAI, Anthropic) and subscription-based ones (GitHub Copilot, Claude Code, Gemini CLI).

Here’s an example using GitHub Copilot with Claude Sonnet 4.6:

---@type LazySpec
return {
  {
    "olimorris/codecompanion.nvim",
    opts = {
      strategies = {
        chat = { adapter = { name = "copilot", model = "claude-sonnet-4.6" } },
        inline = { adapter = { name = "copilot", model = "claude-sonnet-4.6" } },
        cmd = { adapter = { name = "copilot", model = "claude-sonnet-4.6" } },
      },
    },
  },
}

The three strategies control which adapter/model is used for:

  • chat — conversational AI in a split buffer
  • inline — AI edits code directly in your current buffer
  • cmd — AI generates Neovim commands

3. Install and authenticate
#

Run :Lazy sync in Neovim.

If using the Copilot adapter, make sure you’re authenticated with GitHub Copilot (requires an active Copilot Pro subscription). Run :Copilot setup if you have copilot.vim or copilot.lua installed.

4. Usage
#

KeysAction
<Leader>AcToggle chat
<Leader>AqInline assistant
<Leader>ApAction palette

Subscription-based adapters
#

Not everything requires a separate API key. These adapters reuse existing subscriptions:

AdapterSubscription
copilotGitHub Copilot Pro
claude_codeClaude Pro
gemini_cliGemini Pro
mistral_vibeMistral Le Chat Pro

For those enlightened people who use Neovim — what do you use for AI chat?


comments powered by Disqus