Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions doc/codecompanion.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*codecompanion.txt* For NVIM v0.11 Last change: 2026 February 01
*codecompanion.txt* For NVIM v0.11 Last change: 2026 February 02

==============================================================================
Table of Contents *codecompanion-table-of-contents*
Expand Down Expand Up @@ -1593,6 +1593,50 @@ See the section on |codecompanion-configuration-adapters-acp| and
|codecompanion-configuration-adapters-http| for more information.


COMPLETION ~

By default, CodeCompanion will determine if you have one of blink.cmp
<https://github.com/saghen/blink.cmp>, nvim-cmp
<https://github.com/hrsh7th/nvim-cmp>, or coc.nvim
<https://github.com/neoclide/coc.nvim> installed, selecting it as the default
provider. Failing this, the default completion engine will be used.

You can override this with:

>lua
require("codecompanion").setup({
interactions = {
chat = {
opts = {
completion_provider = "blink", -- blink|cmp|coc|default
}
}
}
})
<


PREFIXES

You can also customize the prefixes that trigger completions for
|codecompanion-usage-chat-buffer-slash-commands|,
|codecompanion-usage-chat-buffer-tools| and
|codecompanion-usage-chat-buffer-variables|:

>lua
require("codecompanion").setup({
opts = {
triggers = {
acp_slash_commands = "\\",
slash_commands = "/",
tools = "@",
variables = "#",
},
},
})
<


DIFF ~


Expand Down Expand Up @@ -1664,8 +1708,8 @@ SLASH COMMANDS ~
file
Slash Commands
<https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L114>
(invoked with `/`) let you dynamically insert context into the chat buffer,
such as file contents or date/time.
(invoked with `/` by default) let you dynamically insert context into the chat
buffer, such as file contents or date/time.

The plugin supports providers like telescope
<https://github.com/nvim-telescope/telescope.nvim>, mini_pick
Expand All @@ -1689,7 +1733,7 @@ Tools
<https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L55>
perform specific tasks (e.g., running shell commands, editing buffers, etc.)
when invoked by an LLM. Multiple tools can be grouped together. Both can be
referenced with `@` when in the chat buffer:
referenced with `@` (by default), when in the chat buffer:

>lua
require("codecompanion").setup({
Expand Down Expand Up @@ -1931,10 +1975,10 @@ VARIABLES ~

Variables
<https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L90>
are placeholders inserted into the chat buffer (using `#`). They provide
contextual code or information about the current Neovim state. For instance,
the built-in `#buffer` variable sends the current buffer’s contents to the
LLM.
are placeholders inserted into the chat buffer (using `#` by default). They
provide contextual code or information about the current Neovim state. For
instance, the built-in `#{buffer}` variable sends the current buffer’s
contents to the LLM.

You can even define your own variables to share specific content:

Expand Down
41 changes: 38 additions & 3 deletions doc/configuration/chat-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,41 @@ require("codecompanion").setup({

See the section on [ACP](/configuration/adapters-acp) and [HTTP](/configuration/adapters-http) for more information.

## Completion

By default, CodeCompanion will determine if you have one of [blink.cmp](https://github.com/saghen/blink.cmp), [nvim-cmp](https://github.com/hrsh7th/nvim-cmp), or [coc.nvim](https://github.com/neoclide/coc.nvim) installed, selecting it as the default provider. Failing this, the default completion engine will be used.

You can override this with:

```lua
require("codecompanion").setup({
interactions = {
chat = {
opts = {
completion_provider = "blink", -- blink|cmp|coc|default
}
}
}
})
```

### Prefixes

You can also customize the prefixes that trigger completions for [slash commands](/usage/chat-buffer/slash-commands), [tools](/usage/chat-buffer/tools) and [variables](/usage/chat-buffer/variables):

```lua
require("codecompanion").setup({
opts = {
triggers = {
acp_slash_commands = "\\",
slash_commands = "/",
tools = "@",
variables = "#",
},
},
})
```

## Diff

<img src="https://github.com/user-attachments/assets/8d80ed10-12f2-4c0b-915f-63b70797a6ca" alt="Diff"/>
Expand Down Expand Up @@ -193,7 +228,7 @@ The decorator function also has access to the adapter in the chat buffer alongsi
> [!IMPORTANT]
> Each slash command may have their own unique configuration so be sure to check out the [config.lua](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua) file

[Slash Commands](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L114) (invoked with `/`) let you dynamically insert context into the chat buffer, such as file contents or date/time.
[Slash Commands](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L114) (invoked with `/` by default) let you dynamically insert context into the chat buffer, such as file contents or date/time.

The plugin supports providers like [telescope](https://github.com/nvim-telescope/telescope.nvim), [mini_pick](https://github.com/echasnovski/mini.pick), [fzf_lua](https://github.com/ibhagwan/fzf-lua) and [snacks.nvim](https://github.com/folke/snacks.nvim). By default, the plugin will automatically detect if you have any of those plugins installed and duly set them as the default provider. Failing that, the in-built `default` provider will be used. Please see the [Chat Buffer](/usage/chat-buffer/index) usage section for information on how to use Slash Commands.

Expand Down Expand Up @@ -287,7 +322,7 @@ Credit to [@lazymaniac](https://github.com/lazymaniac) for the [inspiration](htt

## Tools

[Tools](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L55) perform specific tasks (e.g., running shell commands, editing buffers, etc.) when invoked by an LLM. Multiple tools can be grouped together. Both can be referenced with `@` when in the chat buffer:
[Tools](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L55) perform specific tasks (e.g., running shell commands, editing buffers, etc.) when invoked by an LLM. Multiple tools can be grouped together. Both can be referenced with `@` (by default), when in the chat buffer:

```lua
require("codecompanion").setup({
Expand Down Expand Up @@ -676,7 +711,7 @@ require("codecompanion").setup({

## Variables

[Variables](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L90) are placeholders inserted into the chat buffer (using `#`). They provide contextual code or information about the current Neovim state. For instance, the built-in `#buffer` variable sends the current buffer’s contents to the LLM.
[Variables](https://github.com/olimorris/codecompanion.nvim/blob/main/lua/codecompanion/config.lua#L90) are placeholders inserted into the chat buffer (using `#` by default). They provide contextual code or information about the current Neovim state. For instance, the built-in `#{buffer}` variable sends the current buffer’s contents to the LLM.

You can even define your own variables to share specific content:

Expand Down
7 changes: 4 additions & 3 deletions lua/codecompanion/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

local codecompanion = require("codecompanion")
local config = require("codecompanion.config")
local triggers = require("codecompanion.triggers")

local _cached_adapters = nil

Expand Down Expand Up @@ -40,7 +41,7 @@ return {
cmd = "CodeCompanion",
callback = function(opts)
-- Detect the user calling a prompt from the prompt library
if opts.fargs[1] and string.sub(opts.fargs[1], 1, 1) == "/" then
if opts.fargs[1] and string.sub(opts.fargs[1], 1, 1) == triggers.mappings.slash_commands then
-- Get the prompt minus the slash
local prompt = string.sub(opts.fargs[1], 2)

Expand Down Expand Up @@ -103,13 +104,13 @@ return {

-- Add prompt library items
vim.iter(prompt_aliases):each(function(k)
table.insert(completions, "/" .. k)
table.insert(completions, triggers.mappings.slash_commands .. k)
end)

-- Add inline variables
for key, _ in pairs(config.interactions.inline.variables) do
if key ~= "opts" then
table.insert(completions, "#{" .. key .. "}")
table.insert(completions, string.format("%s{" .. key .. "}", triggers.mappings.variables))
end
end

Expand Down
8 changes: 7 additions & 1 deletion lua/codecompanion/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ If you are providing code changes, use the insert_edit_into_file tool (if availa
opts = {
acp = {
enabled = true, -- Enable ACP command completion
trigger = "\\", -- Trigger character for ACP commands
},
},
},
Expand Down Expand Up @@ -1002,6 +1001,13 @@ The user is working on a %s machine. Please respond with system specific command
---@return boolean
send_code = true,

triggers = {
acp_slash_commands = "\\",
slash_commands = "/",
tools = "@",
variables = "#",
},

job_start_delay = 1500, -- Delay in milliseconds between cmd tools
submit_delay = 2000, -- Delay in milliseconds before auto-submitting the chat buffer
},
Expand Down
6 changes: 4 additions & 2 deletions lua/codecompanion/interactions/chat/keymaps/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local async = require("plenary.async")
local completion = require("codecompanion.providers.completion")
local config = require("codecompanion.config")
local triggers = require("codecompanion.triggers")

local ts = require("codecompanion.utils.treesitter")
local ui_utils = require("codecompanion.utils.ui")
local utils = require("codecompanion.utils")
Expand Down Expand Up @@ -217,9 +219,9 @@ M.completion = {
if item.label then
-- Add bracket wrapping for variables and tools like cmp/blink do
if item.type == "variable" then
item.word = string.format("#{%s}", item.label:sub(2))
item.word = string.format("%s{%s}", triggers.mappings.variables, item.label:sub(2))
elseif item.type == "tool" then
item.word = string.format("@{%s}", item.label:sub(2))
item.word = string.format("%s{%s}", triggers.mappings.tools, item.label:sub(2))
else
item.word = item.label
end
Expand Down
3 changes: 2 additions & 1 deletion lua/codecompanion/interactions/chat/tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local tool_filter = require("codecompanion.interactions.chat.tools.filter")
local config = require("codecompanion.config")
local log = require("codecompanion.utils.log")
local regex = require("codecompanion.utils.regex")
local triggers = require("codecompanion.triggers")
local ui_utils = require("codecompanion.utils.ui")
local utils = require("codecompanion.utils")

Expand All @@ -28,7 +29,7 @@ local api = vim.api
local show_tools_processing = config.display.chat.show_tools_processing

local CONSTANTS = {
PREFIX = "@",
PREFIX = triggers.mappings.tools,

NS_TOOLS = "CodeCompanion-tools",
AUTOCMD_GROUP = "codecompanion.tools",
Expand Down
4 changes: 3 additions & 1 deletion lua/codecompanion/interactions/chat/variables/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
local config = require("codecompanion.config")
local triggers = require("codecompanion.triggers")

local log = require("codecompanion.utils.log")
local regex = require("codecompanion.utils.regex")

local CONSTANTS = {
PREFIX = "#",
PREFIX = triggers.mappings.variables,
}

---Check a message for any parameters that have been given to the variable
Expand Down
3 changes: 2 additions & 1 deletion lua/codecompanion/interactions/inline/variables/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
local config = require("codecompanion.config")
local log = require("codecompanion.utils.log")
local regex = require("codecompanion.utils.regex")
local triggers = require("codecompanion.triggers")

local CONSTANTS = {
PREFIX = "#",
PREFIX = triggers.mappings.variables,
}

---@class CodeCompanion.Inline.Variable
Expand Down
20 changes: 11 additions & 9 deletions lua/codecompanion/providers/completion/blink/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

local completion = require("codecompanion.providers.completion")
local config = require("codecompanion.config")
local triggers = require("codecompanion.triggers")

--- @class blink.cmp.Source
local M = {}
Expand All @@ -11,11 +12,12 @@ function M.new()
end

function M:get_trigger_characters()
local triggers = { "/", "#", "@" }
local trigger_chars = { triggers.mappings.slash_commands, triggers.mappings.tools, triggers.mappings.variables }
if config.interactions.chat.slash_commands.opts.acp.enabled then
table.insert(triggers, config.interactions.chat.slash_commands.opts.acp.trigger or "\\")
table.insert(trigger_chars, triggers.mappings.acp_slash_commands)
end
return triggers

return trigger_chars
end

function M:enabled()
Expand All @@ -38,7 +40,7 @@ function M:get_completions(ctx, callback)
}

-- Slash commands
if trigger_char == "/" then
if trigger_char == triggers.mappings.slash_commands then
callback({
context = ctx,
is_incomplete_forward = false,
Expand Down Expand Up @@ -68,7 +70,7 @@ function M:get_completions(ctx, callback)
})

-- Variables
elseif trigger_char == "#" then
elseif trigger_char == triggers.mappings.variables then
callback({
context = ctx,
is_incomplete_forward = false,
Expand All @@ -80,7 +82,7 @@ function M:get_completions(ctx, callback)
kind = vim.lsp.protocol.CompletionItemKind.Variable,
label = item.label:sub(2),
textEdit = {
newText = string.format("#{%s}", item.label:sub(2)),
newText = string.format("%s{%s}", triggers.mappings.variables, item.label:sub(2)),
range = edit_range,
},
documentation = {
Expand All @@ -94,7 +96,7 @@ function M:get_completions(ctx, callback)
})

-- Tools
elseif trigger_char == "@" then
elseif trigger_char == triggers.mappings.tools then
callback({
context = ctx,
is_incomplete_forward = false,
Expand All @@ -106,7 +108,7 @@ function M:get_completions(ctx, callback)
kind = vim.lsp.protocol.CompletionItemKind.Struct,
label = item.label:sub(2),
textEdit = {
newText = string.format("@{%s}", item.label:sub(2)),
newText = string.format("%s{%s}", triggers.mappings.tools, item.label:sub(2)),
range = edit_range,
},
documentation = {
Expand All @@ -120,7 +122,7 @@ function M:get_completions(ctx, callback)
})

-- ACP commands
elseif trigger_char == (config.interactions.chat.slash_commands.opts.acp.trigger or "\\") then
elseif trigger_char == triggers.mappings.acp_slash_commands then
local acp_cmds = completion.acp_commands(ctx.bufnr)
local items = vim
.iter(acp_cmds)
Expand Down
6 changes: 3 additions & 3 deletions lua/codecompanion/providers/completion/cmp/acp_commands.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local cc_config = require("codecompanion.config")
local completion = require("codecompanion.providers.completion")

local trigger = require("codecompanion.triggers").mappings.acp_slash_commands

local source = {}

function source.new(config)
Expand All @@ -12,12 +14,10 @@ function source:is_available()
end

function source:get_trigger_characters()
local trigger = cc_config.interactions.chat.slash_commands.opts.acp.trigger or "\\"
return { trigger }
end

function source:get_keyword_pattern()
local trigger = cc_config.interactions.chat.slash_commands.opts.acp.trigger or "\\"
local escaped = vim.pesc(trigger)
return escaped .. [[\w\+]]
end
Expand Down Expand Up @@ -52,7 +52,7 @@ function source:execute(item, callback)
local line = vim.api.nvim_get_current_line()

-- Remove the trigger character and partial command
local before = line:sub(1, col):gsub("\\%w*$", "")
local before = line:sub(1, col):gsub(string.format("%s%w*$", trigger), "")
local after = line:sub(col + 1)
local new_line = before .. text .. after

Expand Down
Loading