ollama.nvim
is a Neovim plugin that provides a chat-based interface within Neovim, allowing users to communicate with an AI model running on a local or remote server.
- Multiple Sessions: Create and manage multiple chat sessions.
- Save/Restore State: Automatically saves session state, including message history, to a JSON file on exit and restores it on startup.
Install with your preferred plugin manager, for example, using lazy.nvim
:
{
'goropikari/ollama.nvim',
dependencies = {
-- 'nvim-telescope/telescope.nvim' -- for telescope integration
},
opts = {
-- default config
base_url = 'http://localhost:11434',
chat = {
model = 'codegemma',
},
window = {
layout = 'left', -- 'float', 'left', 'right', 'above', 'below'
width = 0.5, -- fractional width of parent
height = 0.5, -- fractional height of parent
-- Options below only apply to floating windows
relative = 'editor',
border = 'single', -- 'none', single', 'double', 'rounded', 'solid', 'shadow'
title = 'Ollama Chat', -- title of chat window
},
save_path = vim.fn.stdpath('state') .. '/ollama.nvim/state.json',
},
}
The chat
configuration specifies the model and API URL of your backend service.
In ollama.nvim
, you can interact with the chat interface using the following key mappings:
- Submit Message:
- Insert Mode:
<C-s>
- Normal Mode:
<C-s>
- Insert Mode:
- Clear Session:
- Insert Mode:
<C-l>
- Normal Mode:
<C-l>
- Insert Mode:
- New Session:
- Insert Mode:
<C-n>
- Normal Mode:
<C-n>
- Insert Mode:
- Close Window:
- Normal Mode:
q
- Normal Mode:
- Toggle Help:
- Normal Mode:
?
- Normal Mode:
The main API functions in ollama.nvim
are:
require('ollama').open_chat()
: Opens the chat window for the current session.require('ollama').new_session()
: Starts a new session and opens the chat window.require('ollama').clear_session()
: Clears the current chat session.
Sessions are automatically saved upon Neovim exit and restored on startup. The save_path
option specifies the path where session data is stored.
To list and manage chat sessions, use the following command in Neovim:
:Telescope ollama list
It can be invoked directly:
require('telescope').extensions.ollama.list()
- Open Session: Press
<CR>
to open the selected session. - Delete Session: Press
<C-x>
in normal or insert mode to delete the selected session.
To list available models and set a default model:
:Telescope ollama models
It can be invoked directly:
require('telescope').extensions.ollama.models()
- Set Default Model: Press
<CR>
to set the selected model as the default for new sessions.
This extension is released under the MIT License.