ollama.nvim is a Neovim plugin that allows users to interact with the Ollama language model directly from within Neovim. This plugin provides a simple interface for sending queries to a pre-configured model and displaying the output within the editor.
Before using this plugin, ensure you have the following installed:
-
Ollama: Download and install Ollama from Ollama's official website.
- Follow the instructions on the website to install it on your system.
- Once installed, you need to create or download a model using a
Modelfileor a pre-built model. - You can run the model with the following command:
Replace
ollama run model-name
model-namewith the name of your model.
-
Neovim: Ensure that you have Neovim installed with Lua support (Neovim 0.5 or later).
You can install ollama.nvim using the Lazy.nvim plugin manager. Add the following to your ollama.lua configuration:
return {
"ASoldo/ollama.nvim",
}After adding the plugin, sync your plugin manager to install it.
Once ollama.nvim is installed, you can map a key to invoke the plugin or call it directly from the Neovim command line.
Add the following to your Neovim configuration to map a key (e.g., bo) to open the Ollama interface:
vim.api.nvim_set_keymap("n", "<Leader>bo", [[<cmd>lua require("ollama").start()<CR>]], { noremap = true, silent = true, desc = "Open Ollama" })or
mappings = {
n = {
["<Leader>bo"] = { function() require("ollama").start() end, desc = "Open Ollama", noremap = true, silent = true },
},
},This mapping allows you to press bo in normal mode to start interacting with the Ollama model.
Alternatively, you can invoke the plugin directly from the Neovim command line:
:lua require("ollama").start()This command will prompt you for input and then display the output generated by the Ollama model.
Start the Plugin: Use the key mapping or the direct command to start the Ollama plugin in Neovim.
Enter Your Query: After invoking the plugin, a prompt will appear where you can type your query. Once you are done with typing and still in Insert mode press Shift+Enter to confirm and send the query.
View the Output: The response from the Ollama model will be displayed in a floating window within Neovim.
This plugin makes it easy to interact with powerful language models directly from your editor, streamlining your workflow and enhancing your productivity.

