Skip to content

Using the Inline Assistant

As per the Getting Started guide, the inline assistant enables you to code directly into a Neovim buffer. Simply run :CodeCompanion <your prompt>, or make a visual selection to send that as context to the LLM alongside your prompt.

For convenience, you can call prompts from the prompt library via the assistant. For example, :'<,'>CodeCompanion /tests would ask the LLM to create some unit tests from the selected text.

Variables

TIP

To ensure the LLM has enough context to complete a complex ask, it's recommended to use the #buffer variable

The inline assistant allows you to send context alongside your prompt via the notion of variables:

  • #buffer - shares the contents of the current buffer
  • #chat - shares the LLM's messages from the last chat buffer

Simply include them in your prompt. For example :CodeCompanion #buffer add a new method to this file. Multiple variables can be sent as part of the same prompt. You can even add your own custom variables as per the configuration.

Adapters

You can specify a different adapter to that in the configuration (strategies.inline.adapter) when sending an inline prompt. Simply include the adapter name as the first word in the prompt. For example :<','>CodeCompanion deepseek can you refactor this?. This approach can also be combined with variables.

Classification

One of the challenges with inline editing is determining how the LLM's response should be handled in the buffer. If you've prompted the LLM to "create a table of 5 common text editors" then you may wish for the response to be placed at the cursor's position in the current buffer. However, if you asked the LLM to "refactor this function" then you'd expect the response to replace a visual selection. The plugin uses the inline LLM you've specified in your config to determine if the response should:

  • replace - replace a visual selection you've made
  • add - be added in the current buffer at the cursor position
  • before - to be added in the current buffer before the cursor position
  • new - be placed in a new buffer
  • chat - be placed in a chat buffer

Diff Mode

By default, an inline assistant prompt will trigger the diff feature, showing differences between the original buffer and the changes made by the LLM. This can be turned off in your config via the display.diff.provider table. You can also choose to accept or reject the LLM's suggestions with the following keymaps:

  • ga - Accept an inline edit
  • gr - Reject an inline edit

These keymaps can also be changed in your config via the strategies.inline.keymaps table.

Released under the MIT License.