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:
This plugin will give you a partner who will one-shot new features in your codebase:
https://github.com/pasky/claude.vim/assets/18439/73ffcaac-d5b4-4508-b9fa-077c189d2c93
You can let it refactor your code if it's a bit messy, and have an ongoing discussion about it:
https://github.com/pasky/claude.vim/assets/18439/625060ca-600f-4774-adbe-ec93f94a30e9
You can ask it to modify or extend just a selected piece of your code:
https://github.com/pasky/claude.vim/assets/18439/71544b57-e87d-4dd4-a7e6-4051fa080d18
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:
:help windows
) - at least <C-W><C-W>
to cycle between active windows:help diff
) - at least d
o
to accept the change under cursor:help folding
) - at least z
o
to open a fold (chat interaction) and z
c
to close it: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:
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.
<Leader>ci
- shortcut for :'<,'>ClaudeImplement ...
<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 windowYou:
line (and/or indented(!) below it)<C-]>
(in insert or normal mode) to send your message and get a replyYou 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.