Local AI coding assistant for Vim 9 powered by Ollama.
vim9-ollama is a modern Vim9script plugin that integrates local LLMs into Vim.
It provides AI-powered chat, code rewriting, code review, and inline code completion.
All AI inference runs locally using Ollama, so your code never leaves your machine.
- 🧠 Local AI coding assistant
- ⚡ Written in modern Vim9script
- 🔌 Autoload architecture for fast startup
- 💬 Chat with LLM about your code
- ✏️ Rewrite / refactor selected code
- 🔍 Code review and suggestions
- 🤖 Inline AI completion (experimental)
- ⚙️ Fully configurable models and prompts
- Vim ≥ 9.0
- Ollama
Install Ollama:
curl -fsSL https://ollama.com/install.sh | shStart the Ollama server:
ollama serveDownload recommended models:
ollama pull starcoder2:3b
ollama pull qwen2.5-coder:3bUsing vim-plug:
Plug 'greeschenko/vim9-ollama'Restart Vim.
The plugin will automatically start the Ollama server on Vim startup.
The plugin can be configured via global Vim variables.
Example configuration:
let g:ollama_api = "http://localhost:11434/api/generate"
let g:ollama_models = {
\ "complete": {
\ "name": "starcoder2:3b",
\ "stream": v:false,
\ "options": {
\ "num_predict": 256,
\ "temperature": 0.2
\ },
\ "prompt_template": [
\ "```{filetype}",
\ "{filecontext}",
\ "{input}<|cursor|>{instruction}"
\ ]
\ },
\
\ "change": {
\ "name": "qwen2.5-coder:3b",
\ "stream": v:true,
\ "options": {
\ "temperature": 0.1,
\ "num_predict": 512
\ }
\ },
\
\ "chat": {
\ "name": "qwen2.5-coder:3b",
\ "stream": v:true,
\ "options": {
\ "temperature": 0.3
\ }
\ }
\ }You can customize:
- model names
- temperature
- token limits
- prompt templates
Ask a question about the current file or code context.
:OllamaAsk Explain this function
The response will appear in a split window.
Select code in visual mode and run:
:OllamaChange Refactor this function
Examples:
:OllamaChange Improve readability
:OllamaChange Add logging
:OllamaChange Convert this to Go generics
The selected code will be replaced with the modified version.
Select code and run:
:OllamaRead What could be improved here?
This displays AI comments in a separate buffer.
Inline completion works similarly to GitHub Copilot.
Press:
Ctrl + L
This sends the current context to the model and shows a ghost suggestion below the cursor.
Press again to request another suggestion.
Press:
Ctrl + F
The suggested code will be inserted into the buffer.
The plugin sends a Fill-in-the-Middle (FIM) prompt to the model.
Example input:
fmt.Printf(<|cursor|>"hello")The model generates the missing code at the cursor position.
The plugin uses modern Vim9 autoload architecture.
vim9-ollama
├─ plugin
│ └─ vim9ollama.vim
│
└─ autoload
└─ vim9ollama.vim
plugin/defines commands and key mappingsautoload/contains implementation- functions load only when used
This keeps Vim startup fast.
Restart the server:
:call ollama.StartServer()
Or manually:
pkill ollama
ollama servePlanned improvements:
- streaming inline completion
- better FIM prompts
- async UI updates
- multi-buffer context
- configurable keymaps
- model selection per filetype
MIT
Olex Hryshchenko https://github.com/greeschenko