
Leverage llm, a CLI utility and Python library for interacting with Large Language Models, from your Neovim editor.
- Install the llm CLI
- Set the API key for the LLM provider of your choice
-- lazy.nvim
{
"cmpadden/llm.nvim",
keys= {
{ "<leader>x", ":LLM<cr>", mode="v" },
},
cmd= {
"LLM",
},
opts= {
-- `llm` flag configuration parametersmodel="claude-3.5-haiku", -- TEXT Model to usesystem=nil, -- TEXT System prompt to usecontinue=nil, -- Continue the most recent conversation.conversation=nil, -- TEXT Continue the conversation with the given ID.template=nil, -- TEXT Template to useparam=nil, -- <TEXT TEXT>... Parameters for templateoption=nil, -- <TEXT TEXT>... key/value options for the model-- nvim-specific configuration parametersinsert_as_comment=true-- BOOL Insert the prompt response as a comment
}
}Select text, and send it to LLM with your key binding of choice. For the example
of <leader>x, you can visually select a line or paragraph, send it to LLM, and
the response will be inserted below your cursor.
vip<leader>x
The following user commands have been made available. This allows you to handle sessions so that you can send snippets to LLM, and ask follow-up questions with persisted context.
| Command | Parameters | Description |
|---|---|---|
| LLM | string? | Prompt LLM with visual selection and/or an additional query |
If all you wish to do is to pass text to llm from your Neovim session, then you may be better off defining a key binding like so:
vim.keymap.set("v", "<leader>x", ':!LLM -e -r<CR>')However, llm.nvim intends to offer some quality of life improvements over such a bindings.