A Vim plugin that integrates with AiChat CLI to provide multi-turn AI chat directly in Vim. Designed for Vim (not Neovim) with Python support.
- Multi-turn AI chat: Interact with AI in a dedicated scratch buffer.
- Visual selection support: Highlight text in Vim and send it directly to AiChat.
- Normal mode support: Open an empty AiChat buffer for new prompts.
- Scratch buffer: No save prompts; buffer closes normally.
- Folding: Previous AI responses are automatically folded except the latest.
- Highlighting: Different colors for user prompts and AI responses.
- Auto-scroll: Always scrolls to the latest AI response.
| Mode | Mapping | Description |
|---|---|---|
| Visual | <leader>a |
Send selected text to a new AiChat buffer. Works for linewise, characterwise, or blockwise selection. |
| Normal | <leader>a |
Open an empty AiChat buffer for a new prompt. |
| AiChat buffer | <leader>s |
Send the last user prompt to AiChat and append the response. |
:AiChatBuf– Open a new AiChat buffer.:'<,'>AiChatBuf– Open AiChat buffer with the selected line range (linewise only).:AiChatSend– Send the last prompt in the AiChat buffer to the AI.
Using Vundle
Add the following to your .vimrc:
Plugin 'BeauJoh/AiChat-vim'
Source or restart vim, then run:
:BundleInstall
Requirements
- Vim 8.2 or newer with Python support
- Python 3 (tested on Python 3.10.12)
- AiChat CLI
Note: Installation and configuration of the AiChat CLI is required separately.
This plugin is designed to work with a locally installed instance of AiChat.
Here's how I got it up and running for development (without requiring sudo):
-
Download & Extract: Download the pre-built binary from https://github.com/sigoden/aichat/releases and extract it to a local directory (e.g.,
~/.bin). -
Update PATH: Add the directory containing the
aichatbinary to your$PATHenvironment variable. Edit your.zshrcor.bashrcfile and add a line like this:export PATH=$HOME/.bin:$PATH
Remember to source your shell configuration file (e.g.,
source ~/.zshrcorsource ~/.bashrc) after making this change. -
Configure AiChat: Run
aichatin your terminal. The first time you run it, you'll be prompted to configure your AI provider.- Flexibility: AiChat supports multiple LLM providers (ChatGPT, Gemini, Claude, and potentially more!), allowing you to switch without modifying your Vim configuration or this plugin.
- API Keys: The most challenging part is usually obtaining the necessary API keys from your chosen provider.
- Changing Providers: To switch providers, simply delete your AiChat configuration file (
~/.config/aichat/config.yaml) and re-runaichatto configure a new provider.
This plugin was initially built as a personal productivity tool and is still under development. I welcome contributions!
- Bug Reports & Feature Requests: Please open an issue if you encounter any problems or have ideas for improvements.
- Pull Requests: Feel free to submit a pull request with your changes.
If you find this plugin useful, consider [buying me a beer](link to donation/buy me a coffee) to help support its development! Cheers Beau.