Home

Awesome

collama.nvim

Note: This repository is still a work in progress. The interface is subject to change without notice.

collama.nvim is a Neovim plugin that leverages Ollama to provide source code completion capabilities similar to GitHub Copilot.

Demo

demo

Demo Scenario

  1. Open main.go in nvim.
  2. Write package and import statements.
  3. Implement the main function initially.
  4. Write a comment for the fizzBuzz function.
  5. Encounter difficulties while implementing the fizzBuzz function.
  6. collama.nvim suggests an implementation.
  7. Accept the suggested implementation.
  8. Format the code and save.
  9. Exit nvim.
  10. Execute main.go

Requirements

Quick start

  1. Install the requirements.
  2. Install collama.nvim using your preferred package manager.
  3. Run ollama pull codellama:7b-code.
  4. Add require('collama.preset.example').setup({ model = 'codellama:7b-code' }) to your init.lua.
  5. Add vim.keymap.set('i', '<M-j>', require('collama.copilot').accept) to your init.lua.
  6. Open a file in nvim and enter insert mode. Wait for a while.
  7. Press <M-j> to accept the suggested code.

Installation

lazy.nvim

  {
    'yuys13/collama.nvim',
    lazy = false,
    config = function()
      require('collama.preset.example').setup { model = 'codellama:7b-code' }
      -- map accept key
      vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)
    end,
  },

Custom Configuration Example

  {
    'yuys13/collama.nvim',
    lazy = false,
    config = function()
      ---@type CollamaConfig
      local config = {
        base_url = 'http://localhost:11434/api/',
        model = 'codellama:7b-code',
      }

      local augroup = vim.api.nvim_create_augroup('my_collama_augroup', { clear = true })

      -- auto execute debounced_request
      vim.api.nvim_create_autocmd({ 'InsertEnter', 'CursorMovedI', 'TextChangedI' }, {
        group = augroup,
        callback = function()
          require('collama.copilot').debounced_request(config, 1000)
        end,
      })
      -- auto cancel
      vim.api.nvim_create_autocmd({ 'InsertLeave', 'VimLeavePre' }, {
        group = augroup,
        callback = function()
          require('collama.copilot').clear()
        end,
      })
      -- map accept key
      vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)
    end,
  },
<details> <summary>More customization</summary>

Custom Notification

nvim-notify

  {
    'yuys13/collama.nvim',
    lazy = false,
    config = function()
      require('collama.preset.example').setup { model = 'codellama:7b-code' }
      -- map accept key
      vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)

      require('collama.logger').setup(require('notify').notify)
    end,
  },

nvim-notify

fidget.nvim

  {
    'yuys13/collama.nvim',
    lazy = false,
    config = function()
      require('collama.preset.example').setup { model = 'codellama:7b-code' }
      -- map accept key
      vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)

      require('collama.logger').setup(require('fidget').notify)
    end,
  },

fidget

vim.notify

  {
    'yuys13/collama.nvim',
    lazy = false,
    config = function()
      require('collama.preset.example').setup { model = 'codellama:7b-code' }
      -- map accept key
      vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)

      require('collama.logger').setup(vim.notify)
    end,
  },

vim.notify

</details>