Skip to content

goropikari/ollama.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ollama.nvim

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.

Features

  • 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.

Installation

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.

Usage

Key Bindings

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>
  • Clear Session:
    • Insert Mode: <C-l>
    • Normal Mode: <C-l>
  • New Session:
    • Insert Mode: <C-n>
    • Normal Mode: <C-n>
  • Close Window:
    • Normal Mode: q
  • Toggle Help:
    • Normal Mode: ?

API

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.

Saving and Restoring Sessions

Sessions are automatically saved upon Neovim exit and restored on startup. The save_path option specifies the path where session data is stored.

Telescope integration

Commands

List Sessions

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()
Available Actions
  • Open Session: Press <CR> to open the selected session.
  • Delete Session: Press <C-x> in normal or insert mode to delete the selected session.

List Models

To list available models and set a default model:

:Telescope ollama models

It can be invoked directly:

require('telescope').extensions.ollama.models()
Available Actions
  • Set Default Model: Press <CR> to set the selected model as the default for new sessions.

License

This extension is released under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published