Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

ollama-vim

A Neovim plugin for AI-assisted code editing using Ollama. Cursor-style cmd+k experience in your terminal.

Features

  • Edit Mode (<leader>k): Select code, describe changes, preview diff, apply
  • Chat Mode (<leader>K): Multi-turn conversation about selected code with /edit command to apply changes
  • Model Switcher (<leader>M): Quick switch between configured models

Requirements

  • Neovim 0.10+ (uses vim.system for async HTTP)
  • Ollama running locally (ollama serve)
  • A model available. The default is glm-5.3-flash:cloud; select it with the model switcher or set vim.g.ollama_model.

Installation

lazy.nvim

{
  "ParthSareen/vimollama",
  keys = {
    { "<leader>k", mode = "v", desc = "Ollama Edit" },
    { "<leader>K", mode = "v", desc = "Ollama Chat" },
    { "<leader>M", desc = "Ollama Model" },
  },
}

vim-plug

Plug 'ParthSareen/vimollama'

Manual

Clone to your Neovim packages directory:

git clone https://github.com/ParthSareen/vimollama ~/.local/share/nvim/site/pack/plugins/start/ollama-vim

Usage

Edit Mode (<leader>k)

  1. Select code in visual mode
  2. Press <leader>k
  3. Type your edit instruction (e.g., "add error handling")
  4. Review the diff preview
  5. Press Enter or y to apply, Esc or q to cancel

Chat Mode (<leader>K)

  1. Select code in visual mode
  2. Press <leader>K
  3. Ask questions about the code
  4. Continue the conversation (history is maintained)
  5. Type /edit <instruction> to modify the code
  6. Review and apply changes
  7. Press Esc or q to close chat

Configuration

-- Optional: override the default model
vim.g.ollama_model = "glm-5.3-flash:cloud"

-- Optional: override models for the switcher
-- By default, the switcher uses Ollama model recommendations.
vim.g.ollama_models = { "glm-5.3-flash:cloud", "qwen3-coder:480b-cloud" }

-- Optional: customize keymaps (defaults shown)
vim.g.ollama_keymap = "<leader>k"        -- edit mode
vim.g.ollama_chat_keymap = "<leader>K"   -- chat mode
vim.g.ollama_model_keymap = "<leader>M" -- model switcher

-- Optional: custom Ollama endpoint (default: localhost:11434)
vim.g.ollama_endpoint = "http://localhost:11434/api/generate"
vim.g.ollama_chat_endpoint = "http://localhost:11434/api/chat"

-- Optional: custom system prompts
vim.g.ollama_system_prompt = "Your custom edit prompt..."
vim.g.ollama_chat_system_prompt = "Your custom chat prompt..."
vim.g.ollama_chat_edit_system_prompt = "Your custom chat-edit prompt..."

Commands

  • :OllamaEdit - Start edit mode (visual mode)
  • :OllamaChat - Start chat mode (visual mode)
  • :OllamaModel - Open model switcher

Highlight Groups

Customize the appearance by setting these highlight groups:

vim.api.nvim_set_hl(0, "OllamaPreviewAdd", { fg = "#a6e3a1" })    -- added lines
vim.api.nvim_set_hl(0, "OllamaPreviewDel", { fg = "#f38ba8" })    -- deleted lines
vim.api.nvim_set_hl(0, "OllamaPreviewHeader", { fg = "#89b4fa" }) -- diff headers
vim.api.nvim_set_hl(0, "OllamaChatCode", { fg = "#6c7086" })      -- code context
vim.api.nvim_set_hl(0, "OllamaChatUser", { fg = "#89b4fa" })      -- user messages
vim.api.nvim_set_hl(0, "OllamaChatAssistant", { fg = "#a6e3a1" }) -- assistant messages

Custom Mappings

If you prefer to set up your own keymaps, disable the defaults and use the <Plug> mappings:

vim.g.ollama_no_maps = true  -- disable default keymaps

-- Then map manually:
vim.keymap.set("x", "<leader>k", "<Plug>(ollama-edit)")
vim.keymap.set("x", "<leader>K", "<Plug>(ollama-chat)")
vim.keymap.set("n", "<leader>M", "<Plug>(ollama-model)")

Available <Plug> mappings:

  • <Plug>(ollama-edit) - Edit mode (visual)
  • <Plug>(ollama-chat) - Chat mode (visual)
  • <Plug>(ollama-model) - Model switcher (normal)

License

MIT

About

Ollama in nvim! Use local and cloud models to chat and edit with your code

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages