⚡ Free AI completion plugin powered by codeium ⚡
NeoCodeium is a plugin that provides AI completion powered by Codeium. The
primary reason for creating NeoCodeium was to address the issue of flickering
suggestions in the official plugin which was particularly annoying when dealing
with multi-line virtual text. Additionally, I desired a feature that would
allow accepting Codeium suggestions to be repeatable using the .
command
because I use it as my main completion plugin and only manually invoke
nvim-cmp.
[!Warning] While using this plugin, your code is constantly being sent to Codeium servers by their own language server in order to evaluate and return completions. Before using make sure you have read and accept the Codeium Privacy Policy. NeoCodeium has the ability to disable the server globally or for individual buffers. This plugin does not send any data to the server from disabled buffers, but the Codeium server is still running behind the scenes and we cannot guarantee that it doesn't send information while running.
Here’s an example for 💤lazy plugin manager. If you're using a different plugin manager, please refer to its documentation for installation instructions.
-- add this to the file where you setup your other plugins:
{
"monkoose/neocodeium",
event = "VeryLazy",
config = function()
local neocodeium = require("neocodeium")
neocodeium.setup()
vim.keymap.set("i", "<A-f>", neocodeium.accept)
end,
}
Now you can use Alt-f
in insert mode to accept codeium suggestions.
Enterprise users: you should receive portal and API URLs for Codeium from your company.
Once you get them, add them to your config. This way :NeoCodeium auth
will authenticate you on the right portal. For example,
{
"monkoose/neocodeium",
event = "VeryLazy",
opts = {
server = {
api_url = 'https://codeium.company.net/_route/api_server',
portal_url = 'https://codeium.company.net',
},
}
}
Note: To obtain an API token, you’ll need to run :NeoCodeium auth
.
On Windows WSL wslview
(sudo apt install wslu)
should be installed to properly open the browser.
In addition to the already mentioned accept()
function, the plugin also provides a few others:
local neocodeium = require("neocodeium")
-- Accepts the suggestion
neocodeium.accept()
-- Accepts only part of the suggestion if the full suggestion doesn't make sense
neocodeium.accept_word()
neocodeium.accept_line()
-- Clears the current suggestion
neocodeium.clear()
-- Cycles through suggestions by `n` (1 by default) items. Use a negative value to cycle in reverse order
neocodeium.cycle(n)
-- Same as `cycle()`, but also tries to show a suggestion if none is visible.
-- Mostly useful with the enabled `manual` option
neocodeium.cycle_or_complete(n)
-- Checks if a suggestion's virtual text is visible or not (useful for some complex mappings)
neocodeium.visible()
NeoCodeium doesn’t provide any keymaps, which means you’ll need to add them
yourself. While codeium.vim and
copilot.vim set the <Tab>
key as the
default key for accepting a suggestion, we recommend avoiding it as it has some
downsides to consider (although nothing is stopping you from using it):
:h command-line-window
.Suggested keymaps:
vim.keymap.set("i", "<A-f>", function()
require("neocodeium").accept()
end)
vim.keymap.set("i", "<A-w>", function()
require("neocodeium").accept_word()
end)
vim.keymap.set("i", "<A-a>", function()
require("neocodeium").accept_line()
end)
vim.keymap.set("i", "<A-e>", function()
require("neocodeium").cycle_or_complete()
end)
vim.keymap.set("i", "<A-r>", function()
require("neocodeium").cycle_or_complete(-1)
end)
vim.keymap.set("i", "<A-c>", function()
require("neocodeium").clear()
end)
NeoCodeium provides :NeoCodeium
user command, which has some useful actions:
:NeoCodeium auth
- authenticates the user and saves the API token.:NeoCodeium[!] disable
- disables completions. With the bang also stops the codeium server.:NeoCodeium enable
- enables NeoCodeium completion.:NeoCodeium[!] toggle
- toggles NeoCodeium completion. Convey the bang to disable command.:NeoCodeium disable_buffer
- disables NeoCodeium completion in the current buffer.:NeoCodeium enable_buffer
- enables NeoCodeium completion in the current buffer.:NeoCodeium toggle_buffer
- toggles NeoCodeium completion in the current buffer.:NeoCodeium open_log
- opens new tab with the log output. More information is in the logging section.:NeoCodeium chat
- opens browser with the Codeium Chat.:NeoCodeium restart
- restarts Codeium server (useful if the server stops responding for any reason).You can also use the same commands in your Lua scripts by calling:
require("neocodeium.commands").<command_name>()`
-- Examples
-- disable completions
require("neocodeium.commands").disable()
-- disable completions and stop the server
require("neocodeium.commands").disable(true)
NeoCodeium triggers several user events which can be used to trigger code. These can be used to optimize when statusline elements are updated, creating mappings only when the server is available, or modifying completion engine settings when AI completion is started or displaying hints.
NeoCodeiumServerConnecting
- triggers when a connection to the Codeium server is startingNeoCodeiumServerConnected
- triggers when a successful connection to the Codeium server is madeNeoCodeiumServerStopped
- triggers when the Codeium server is stoppedNeoCodeiumEnabled
- triggers when the NeoCodeium plugin is enabled globallyNeoCodeiumDisabled
- triggers when the NeoCodeium plugin is disabled globallyNeoCodeiumBufEnabled
- triggers when the NeoCodeium plugin is enabled for a bufferNeoCodeiumBufDisabled
- triggers when the NeoCodeium plugin is disabled for a bufferNeoCodeiumCompletionDisplayed
- triggers when NeoCodeium successfully displays a completion item as virtual textNeoCodeiumCompletionCleared
- triggers when NeoCodeium clears virtual text and completionsrequire("neocodeium").get_status()
can be used to get the some useful information about the current state.
The best use case for this output is to implement custom statusline component.
This function returns two numbers:
Status of the plugin
0 - Enabled
1 - Globally disabled with `:NeoCodeium disable`, `:NeoCodeium toggle` or with `setup.enabled = false`
2 - Buffer is disabled with `:NeoCodeium disable_buffer`
3 - Buffer is disableld when it's filetype is matching `setup.filetypes = { some_filetyps = false }`
4 - Buffer is disabled when `setup.filter` returns `false` for the current buffer
5 - Buffer has wrong encoding (codeium can accept only UTF-8 and LATIN-1 encodings)
Server status
0 - Server is on (running)
1 - Connecting to the server (not working status)
2 - Server is off (stopped)
To use output from get_status()
for in-time update it is required to invoke this function
from events
Statusline Examples
NeoCodeium offers a couple of highlight groups. Feel free to adjust them to your preference and to match your chosen color scheme:
NeoCodeiumSuggestion
- virtual text color of the plugin suggestions (default: #808080
)NeoCodeiumLabel
- color of the label that indicates the number of suggestions (default: inverted DiagnosticInfo)While running, NeoCodeium logs some messages into a temporary file. It can be
viewed with the :NeoCodeium open_log
command. By default only errors and
warnings are logged.
You can set the logging level to one of trace
, debug
, info
, warn
or
error
by exporting the NEOCODEIUM_LOG_LEVEL
environment variable.
Example:
NEOCODEIUM_LOG_LEVEL=info nvim
NeoCodeium comes with the following default options:
-- NeoCodeium Configuration
require("neocodeium").setup({
-- If `false`, then would not start codeium server (disabled state)
-- You can manually enable it at runtime with `:NeoCodeium enable`
enabled = true,
-- Path to a custom Codeium server binary (you can download one from:
-- https://github.com/Exafunction/codeium/releases)
bin = nil,
-- When set to `true`, autosuggestions are disabled.
-- Use `require'neodecodeium'.cycle_or_complete()` to show suggestions manually
manual = false,
-- Information about the API server to use
server = {
-- API URL to use (for Enterprise mode)
api_url = nil,
-- Portal URL to use (for registering a user and downloading the binary)
portal_url = nil,
},
-- Set to `false` to disable showing the number of suggestions label in the line number column
show_label = true,
-- Set to `true` to enable suggestions debounce
debounce = false,
-- Maximum number of lines parsed from loaded buffers (current buffer always fully parsed)
-- Set to `0` to disable parsing non-current buffers (may lower suggestion quality)
-- Set it to `-1` to parse all lines
max_lines = 10000,
-- Set to `true` to disable some non-important messages, like "NeoCodeium: server started..."
silent = false,
-- Set to a function that returns `true` if a buffer should be enabled
-- and `false` if the buffer should be disabled
-- You can still enable disabled by this option buffer with `:NeoCodeium enable_buffer`
filter = function(bufnr) return true end,
-- Set to `false` to disable suggestions in buffers with specific filetypes
-- You can still enable disabled by this option buffer with `:NeoCodeium enable_buffer`
filetypes = {
help = false,
gitcommit = false,
gitrebase = false,
["."] = false,
},
-- List of directories and files to detect workspace root directory for Codeium chat
root_dir = { ".bzr", ".git", ".hg", ".svn", "_FOSSIL_", "package.json" }
})
You can chat with AI in the browser with the :NeoCodeium chat
command. The
first time you open it, it requires the server to restart with some
chat-specific flags, so be patient (this usually doesn't take more than a few
seconds). After that, it should open a chat window in the browser with the
context of the current buffer. Here, you can ask some specific questions about
your code base. When you switch buffers, this context should be updated
automatically (it takes some time). You can see current chat context in the
left bottom corner.
MIT license