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 Scenario
- Open
main.go
in nvim. - Write package and import statements.
- Implement the main function initially.
- Write a comment for the fizzBuzz function.
- Encounter difficulties while implementing the fizzBuzz function.
- collama.nvim suggests an implementation.
- Accept the suggested implementation.
- Format the code and save.
- Exit nvim.
- Execute
main.go
Requirements
- Ollama
- curl
Quick start
- Install the requirements.
- Install
collama.nvim
using your preferred package manager. - Run
ollama pull codellama:7b-code
. - Add
require('collama.preset.example').setup({ model = 'codellama:7b-code' })
to your init.lua. - Add
vim.keymap.set('i', '<M-j>', require('collama.copilot').accept)
to your init.lua. - Open a file in nvim and enter insert mode. Wait for a while.
- 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,
},
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,
},
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,
},
</details>