TRIAL aka STATUS "NOT YET DONE"
Install OFFLINE Code Assistant by NEOZIM

Building a “Gold Standard” Local AI Environment
Neovim + Ollama + CodeCompanion.nvim

⬢ Zero telemetry · ⬢ Full local control · ⬢ Diff‑based workflow

Since you’re looking to build a professional, extension‑free AI environment, Neovim is the right choice. Unlike VS Code—where the AI is a “black box” extension—in Neovim, you are the architect. This guide walks you through a production‑ready setup using Ollama and CodeCompanion.nvim, with zero telemetry, full local control, and a diff‑based workflow.

1 Prerequisites

Ensure these tools are installed and functional on your system:

ToolVersionPurpose
Neovimv0.10.0+The editor engine
GitLatestPlugin and dependency management
OllamaLatestLocal LLM server
C Compilergcc or clangBuilds native UI components

Verify Ollama is running:
ollama serve &> /dev/null &  ·  ollama pull llama3.1 # or your preferred model

2 Bootstrap the Plugin Manager (Lazy.nvim)

Create your Neovim config file if it doesn't exist:

mkdir -p ~/.config/nvim
touch ~/.config/nvim/init.lua

Place this bootstrap code at the top of init.lua — it installs Lazy.nvim automatically on first run:

-- Bootstrap Lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git", "clone", "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath
  })
end
vim.opt.rtp:prepend(lazypath)

3 Declare Your Plugins

Pass your plugin specification to require("lazy").setup(). We include CodeCompanion.nvim and its core dependencies:

require("lazy").setup({
  {
    "olimorris/codecompanion.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim", -- Lua functions library
      "nvim-treesitter/nvim-treesitter", -- Syntax awareness
    },
    config = function()
      -- (configuration added in Step 4)
      require("codecompanion").setup({
        -- configuration goes here
      })
    end,
  },
})

4 Configure CodeCompanion for Ollama

Inside the config function from Step 3, tell CodeCompanion to use your local Ollama server — and define a system prompt to enforce a consistent technical persona.

require("codecompanion").setup({
  strategies = {
    chat = { adapter = "ollama" },
    inline = { adapter = "ollama" },
  },
  adapters = {
    ollama = function()
      return require("codecompanion.adapters").extend("ollama", {
        env = {
          url = "http://127.0.0.1:11434", -- Local endpoint
        },
        schema = {
          model = {
            default = "llama3.1", -- Must match `ollama list`
          },
        },
        -- 🔥 PRO TIP: System prompt to enforce your technical persona
        parameters = {
          system_prompt = [[
  You are a senior software architect and automation expert.
  Reply with clarity, precision, and actionable code examples.
  Avoid fluff—focus on maintainability, performance, and correctness.
  ]],
        },
      })
    end,
  },
})

Important: Make sure the model.default name matches exactly what ollama list shows.

5 Restart & Let Lazy Install

  • Restart Neovim (nvim +Lazy sync also works).
  • Lazy.nvim will download all plugins automatically.
  • Once done, you're ready to use the AI.

6 Workflow – How to Use It

Command / ActionDescription
:CodeCompanionChatOpens a dedicated chat buffer where you can converse with the AI about your codebase.
Visual Mode + :CodeCompanionSelect a code block, then run this command. Type e.g., "refactor this" or "add error handling". The plugin shows a diff preview — press Accept or Reject.
Inline EditsInside the chat, ask the AI to "apply this to the file" — it stages changes in a reviewable diff format before you save.

All context (current file, selection, etc.) is automatically passed to the AI — no manual curl required.

Why This Setup Satisfies Your Requirements

RequirementHow It's Met
Zero HardcodingThe plugin handles the JSON‑RPC protocol and context assembly automatically.
No TelemetryForcing the adapter to 127.0.0.1:11434 ensures zero bytes leave your machine.
Professional StandardDiff‑view workflows are identical to those in paid VS Code extensions — but you control the entire stack.
Customizable PersonaThe system_prompt (Step 4) lets you steer the AI's tone and depth, perfect for consistent blog‑ready output on ronin.directory.

Bonus: Advanced System Prompt Tuning

To further refine the AI's behavior, you can expand the system_prompt with:

  • Style directives: "Use declarative sentences. Prefer pure functions over classes."
  • Domain constraints: "Assume a Linux environment. Optimize for ARM64."
  • Output structure: "Always include a 'Why this works' section in your answers."

Simply update the parameters.system_prompt string and restart Neovim — no plugin reinstall needed.

Final Check

After setup, run :checkhealth in Neovim to verify all dependencies are ready. Then open a file, select some code, and test :CodeCompanion — you should see the AI respond using your local Ollama model, respecting your system prompt.

⚡ You're now a Neovim AI architect.
Happy coding — and may your diffs always be clean. 🚀

Originally written for ronin.directory · Reproduced with permission

Comments