A Vim plugin that provides an interface to the
llm command-line tool for accessing Large
Language Models.
- Execute llm templates on visually selected text
- Tab completion for available templates
- Visual diff presentation of changes
- Accept or reject modifications interactively
- Vim 8.0+ or Neovim
llmtool
Plug 'path/to/llm.vim'Plugin 'path/to/llm.vim'Copy or symlink this directory to your ~/.vim/pack/<plugins>/start/ directory.
:[range]Llm <template> [<prompt>...][range]: Optional line range (e.g.,1,10or use visual mode). If omitted, uses the entire buffer.<template>: Name of an llm template (supports tab completion)<prompt>: Optional additional prompt text
- Select text in visual mode (press
vorV) - Execute the command:
:'<,'>Llm summarizeor with an additional prompt:
:'<,'>Llm summarize make it conciseSimply run the command without a range:
:Llm summarize-
A diff view opens showing:
- Left pane: Original text
- Right pane: Modified text from llm
-
Review the changes and either:
- Type
:LlmAcceptAllto apply all changes - Type
dpon a hunk to accept that specific hunk - Type
<Leader>qto discard and close
- Type
The plugin provides tab completion for template names. After typing :Llm,
press <Tab> to cycle through available templates.
To see available templates, run:
uv tool run llm templates listYou can create custom templates for the llm tool. Refer to the llm documentation for details on creating templates.
Example:
llm --save fix-grammar "Fix grammar and spelling in the following text"Main command to execute llm on selected text.
Syntax:
:[range]Llm <template> [<prompt>...]Examples:
:Llm summarize " Process entire buffer
:1,10Llm summarize " Process lines 1-10
:'<,'>Llm fix-grammar " Process visual selection
:'<,'>Llm translate translate to SpanishThe following commands are available in the diff view buffer:
Accept all changes and apply them to the original buffer.
Syntax:
:LlmAcceptAllKeybinding: <Leader>a
Accept the current hunk (change under cursor) and push it to the original buffer.
Syntax:
:LlmAcceptHunkKeybinding: dp
After accepting a hunk, use ]c to jump to the next hunk.
Close the diff view without accepting any remaining changes.
Syntax:
:LlmCloseKeybinding: <Leader>q
The plugin can be customized with the following options in your .vimrc or init.vim:
Path or command to invoke the llm tool. Default: 'llm'
Example:
" Use a specific path to llm
let g:llm_command = '/usr/local/bin/llm'
" Use llm via uv tool run
let g:llm_command = 'uv tool run llm'Enable line wrapping in diff view buffers. Default: 1 (enabled)
Example:
" Disable line wrap in diff views
let g:llm_diff_wrap = 0
" Enable line wrap in diff views (default)
let g:llm_diff_wrap = 1Make sure the llm tool is properly installed:
uv tool install llm
# Or with pipx:
pipx install llmCheck that llm is working correctly:
echo "test" | llm -t <template>Ensure that the llm command produces output. Some templates may require specific parameters or model configuration.
This plugin is released into the public domain.