This vim plugin integrates Claude deeply into your Vim workflow - rather than working in the clunky web Claude Chat, actually chat about and hack together on your currently opened vim buffers.
Claude is your pair programmer. You chat about what to build or how to debug problems, and Claude offers opinions while seeing your actual code, or goes ahead and proposes the modifications - high level, or just straight writes the code.
This plugin is NOT:
- "code completion" like Github Copilot or Codeium. (You can use these together with claude.vim!) This plugin rather provides a chat / instruction centric interface.
- CLI coding framework. It is much more optimized for human collaboration than e.g. aider or dravid. You may want to agree on design decisions before Claude writes code. And it is going to need feedback and change review in order to be helpful. This is why the access to chat history and the vimdiff interface are the killer features.
This plugin will give you a partner who will one-shot new features in your codebase:
chat-feature.mp4
You can let it refactor your code if it's a bit messy, and have an ongoing discussion about it:
chat-refactor.mp4
You can ask it to modify or extend just a selected piece of your code:
implement-blinking.mp4
It can use Claude Tools interface - it will open files and execute vim commands as needed.
It can also (with your case-by-case consent) evaluate Python expression when figuring out what you asked:
And it can execute complex tasks by first reading documentation, then cloning git respositories, browsing the directory tree, etc.
Actually, the current version can execute also shell script. And it can help you also with sysadmin tasks, not just coding.
And ultimately, Claude.vim can act as pretty much a full text terminal replacement of Claude.ai or ChatGPT. And it will search the web if it doesn't know something.
Sonnet 3.5 is not yet good enough to completely autonomously perform complex tasks. This is why you can chat with it, review and reject its changes and tool execution attempts, etc. You still do the "hard thinking" and decide and tell it what to do.
That said, about 95% of the code of this plugin has been written by Claude Sonnet 3.5, and most of the time already "self-hosted" within the plugin.
NOTE: This is early alpha software. It is expected to rapidly evolve...
and not just in backwards compatible way. Stay in touch with the maintainer
if you are using it (pasky
on libera IRC, or @xpasky on Twitter / X, or just
via github issues or PRs).
First, install using your favourite package manager, or use Vim's built-in package support.
Vim:
mkdir -p ~/.vim/pack/pasky/start
cd ~/.vim/pack/pasky/start
git clone https://github.com/pasky/claude.vim.git
Neovim:
mkdir -p ~/.config/nvim/pack/pasky/start
cd ~/.config/nvim/pack/pasky/start
git clone https://github.com/pasky/claude.vim.git
To allow web access, install elinks or felinks (e.g. brew install felinks
).
To allow Google access, you first need to open elinks manually, navigate to
https://www.google.com/search?q=lala
and select and press one of the buttons
in the cookie consent (then, quit it using q
).
Obtain your Claude API key by signing up at https://console.anthropic.com/ . Anthropic might give you a free $5 credit to get you started, which is plenty for many hours of hacking (depending on your mode of usage).
NOTE: This is a cloud service that costs actual money based on the amount of tokens consumed and produced. Be careful when working with big content, observe your usage / billing dashboard on Anthropic etc.
Set your Claude API key in your .vimrc:
let g:claude_api_key = 'your_api_key_here'
(You can also use AWS Bedrock as your Claude provider instead - in that case, set let g:claude_use_bedrock = 1
instead.)
You can edit the keybindings as follows:
let g:claude_map_implement = "<Leader>ci"
let g:claude_map_open_chat = "<Leader>cc"
let g:claude_map_send_chat_message = "<C-]>"
let g:claude_map_cancel_response = "<Leader>cx"
First, a couple of vim concepts you should be roughly familiar with:
- Switching between windows (
:help windows
) - at least<C-W><C-W>
to cycle between active windows - Diff mode (
:help diff
) - at leastd
o
to accept the change under cursor - Folds (
:help folding
) - at leastz
o
to open a fold (chat interaction) andz
c
to close it - Leader (
:help leader
) - if you are unsure, most likely\
is the key to press whenever<Leader>
is mentioned (but on new keyboards,§
or±
might be a nice leader to set)
Claude.vim currently offers two main interaction modes:
- Simple implementation assistant
- Chat interface
In this mode, you select a block of code and ask Claude to modify it in some way; Claude proposes the change and lets you review and accept it.
- Select code block in visual mode. (Note that this selection is all Claude "sees", with no additional context! Therefore, select liberally, e.g. a whole function.)
<Leader>ci
- shortcut for:'<,'>ClaudeImplement ...
- Enter your instruction (e.g. "Fix typos" or "Factor out common code" or "Add error handling" or "There's some bug here") as a ClaudeImplement parameter in the command mode
- Review and accept proposed changes in diff mode
- Switch to the scratch window (
<C-W>l
) and:q
it.
In this mode, you chat with Claude. You can chat about anything, really,
but the twist is that Claude also sees the full content of all your buffers
(listed in :buffers
- roughly any files you currently have open in your vim).
<Leader>cc
- shortcut for opening Claude chat window- Enter a message on the
You:
line (and/or indented(!) below it) <C-]>
(in insert or normal mode) to send your message and get a reply- Read the reply in the Claude window etc.
- If Claude proposes a code change, diff mode automatically pops up to apply it whenever possible.
You can e.g. ask Claude how to debug or fix a bug you observe, or ask it to propose implementation of even fairly complex new functionality. For example:
You: Can you write a short README.md for this plugin, please?
Claude:
Here's a draft README.md for the Claude Vim plugin:
```markdown
# Claude Vim Plugin
A Vim plugin for integrating Claude, an AI assistant, directly into your Vim workflow.
...
Previous interactions are automatically folded for easy orientation (Claude can be a tad bit verbose), but the chat history is also visible to Claude when asking it something. However, you can simply edit the buffer to arbitrarily redact the history (or just delete it).
NOTE: For every single Claude Q&A roundtrip, full chat history and full content of all buffers is sent. This can consume tokens FAST. (Even if it is not too expensive, remember that Claude also imposes a total daily token limit.) Prune your chat history regularly.