The Claude Neovim Plugin is a powerful integration that allows seamless interaction with Anthropic's Claude AI directly within Neovim. It provides advanced features for code generation, conversation management, and AI-assisted workflow.
- Neovim
- Python 3.8+
pynvim
packageanthropic
package- Anthropic API key
Run the setup.sh
script to install the dependencies and add the plugin to your
Neovim configuration.
cd <repository directory>
bash setup.sh
export ANTHROPIC_API_KEY=<your-api-key>
OR
- Install dependencies:
pip install pynvim anthropic
export ANTHROPIC_API_KEY=<your-api-key>
- Add the plugin to your Neovim configuration
Following installation, run nvim, type :UpdateRemotePlugin
and press ,
close nvim, and then reopen it.
Add your Anthropic API key to your .bashrc
or .zshrc
if you want to use the
plugin without setting the ANTHROPIC_API_KEY
environment variable.
:Claude
(:Cl
): Send current conversation to Claude:ClaudeModel
(:CM
): Select AI model:ClaudeModels
: List available models
:WriteCode
(:WC
): Extract and save code blocks from last response:BufferCode
(:BC
): Open code blocks in new buffers
:CopyPrompt
(:CP
): Copy current system prompt to a new buffer:ReplacePrompt
: Replace system prompt with buffer contents
:MaxTokens
(:MT
): Show or change the maximum number of tokens:TokenCount
(:TC
): Respond with the number of tokens in the current buffer
:Truncate
(:Tr
): Toggle truncation of the conversation
:ClaudeSettings
(:CS
): Load, save, or reset Claude settings
Reference other buffers using :b<number>
syntax when talking to Claude.
This will pull in the contents of the buffer into the conversation before
sending it to Claude.
The plugin uses a configurable system prompt that guides Claude's responses, focusing on code quality, formatting, and best practices.
Customize behavior by editing system_prompt.txt
or using :Cp
and :Rp
commands.
- Automatic filename generation for code blocks
- Conversation history tracking
- Multi-model support
- Open Neovim.
- Write a prompt and use
:Cl
to send it to Claude. - Use
:Wc
to save any generated code to a file in the current directory with a name suggested by Claude. - Use
:Bc
to open code in buffers - Modify and iterate
The plugin will automatically wrap new content with <user>
tags and will
save the conversation to a file in the current directory with a name suggested
by Claude.
It saves after every round, except that limitations within Neovim
will prevent the last response from Claude from being saved, so use :w
to
save the file after the last round.
You can continue any existing conversation by opening its corresponding file in claude.
If you don't like a response from Claude, you can delete it, modify your last prompt, and send it again. You can also modify Claude's side of the conversation anywhere in the file. This will "Gaslight" Claude into thinking that it wrote the responses the way you changed it.
Use :Cp
to copy the system prompt to a new buffer, modify it, and then
use :Rp <buffer number>
to replace the system prompt with the new contents.
Try adding this to the end of the system prompt to see what happens:
End every response with "I feel pretty!"
Run
python -m unittest discover -s tests
Claude Neovim Plugin - AI integration for Neovim Copyright (C) [2024] [P. Scott DeVos]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
[Contribution Guidelines]