doc/configuration/inline.md
<p align="center"> </p>[!IMPORTANT] Only http adapters are supported for the inline interaction.
CodeCompanion provides an inline interaction for quick, direct editing of your code. Unlike the chat buffer, the inline interaction integrates responses directly into the current buffer—allowing the LLM to add or replace code as needed.
By default, CodeCompanion sets the copilot adapter for the inline interaction. You can change this to any other HTTP adapter:
require("codecompanion").setup({
interactions = {
inline = {
adapter = {
name = "anthropic",
model = "claude-haiku-4-5-20251001"
},
},
},
})
See the section on HTTP Adapters for more information.
The inline interaction supports keymaps for accepting or rejecting changes:
require("codecompanion").setup({
interactions = {
inline = {
keymaps = {
accept_change = {
modes = { n = "ga" },
description = "Accept the suggested change",
},
reject_change = {
modes = { n = "gr" },
opts = { nowait = true },
description = "Reject the suggested change",
},
},
},
},
})
In this example, ga accepts inline changes, while gr rejects them.
You can also cancel an inline request with:
require("codecompanion").setup({
interactions = {
inline = {
keymaps = {
stop = {
modes = { n = "q" },
index = 4,
callback = "keymaps.stop",
description = "Stop request",
},
},
},
},
})
The plugin comes with a number of editor context items that can be used alongside your prompt using the #{} syntax (e.g., #{my_new_context_item}). You can also add your own:
require("codecompanion").setup({
interactions = {
inline = {
editor_context = {
["my_new_context_item"] = {
---@return string
callback = "/Users/Oli/Code/my_context_item.lua",
description = "My shiny new context item",
opts = {
contains_code = true,
},
},
}
}
}
})
If the inline prompt creates a new buffer, you can also customize if this should be output in a vertical/horizontal split or a new buffer:
require("codecompanion").setup({
display = {
inline = {
layout = "vertical", -- vertical|horizontal|tab|buffer
},
}
})
Please see the Diff section on the Chat Buffer page for configuration options.