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:
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/nvimtouch ~/.config/nvim/init.lua
Place this bootstrap code at the top of init.lua — it installs Lazy.nvim automatically on first run:
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:
{
"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.
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 syncalso works). - Lazy.nvim will download all plugins automatically.
- Once done, you're ready to use the AI.
6 Workflow – How to Use It
All context (current file, selection, etc.) is automatically passed to the AI — no manual curl required.
Why This Setup Satisfies Your Requirements
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.
Originally written for ronin.directory · Reproduced with permission
Comments
Post a Comment