AI-Powered Assistance Directly in Vim or Neovim using OpenAI's GPT API
You can install Vim-GPT with a one-liner:
curl -s https://raw.githubusercontent.com/rfilipo/Vim-GPT/main/install.sh | bashwget -qO- https://raw.githubusercontent.com/rfilipo/Vim-GPT/main/install.sh | bashThis script installs:
- System dependencies (build tools, SSL, SQLite, etc.)
pyenvand the latest stable Python- OpenAI's Python SDK
- This plugin under
~/.vim/pack/plugins/start/vim-gpt(or for Neovim, compatible path) - Your API key in:
~/.vim/pack/plugins/start/vim-gpt/config/apikey
Also adds the following to ~/.bashrc (and .zshrc if needed):
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fiFor macOS users, brew is used to install required dependencies.
For Neovim users, the plugin works just like in Vim. It uses the same paths and logic.
If you prefer Vim-Plug, add this to your .vimrc or init.vim:
Plug 'rfilipo/Vim-GPT', { 'rtp': 'vim-gpt' }Then run :PlugInstall and run the install script manually for dependencies:
curl -s https://raw.githubusercontent.com/rfilipo/Vim-GPT/main/install.sh | bash- Build the
.debpackage:
./build_deb.sh- Install the package:
sudo dpkg -i vim-gpt_1.0.0_all.deb
- The plugin will be installed under:
/usr/share/vim-gpt/
- Link the plugin to Vim:
mkdir -p ~/.vim/pack/plugins/start/
ln -s /usr/share/vim-gpt ~/.vim/pack/plugins/start/vim-gpt
Once installed, launch Vim or Neovim and use the following commands in Normal or Visual mode:
Prompt GPT. If the result is a Vim command it asks to run it.
Show files in the current dir ans asks what to do.
Asks for a system command and what to do with the result.
Generate documentation for the selected code or current line.
Run with Control + Space in edit mode.
Get an explanation of the selected code snippet or current line.
Ask GPT to refactor or improve the selected code.
Set your OpenAI API key:
mkdir -p ~/.vim/pack/plugins/start/vim-gpt/config/
echo "sk-xxxxx..." > ~/.vim/pack/plugins/start/vim-gpt/config/apikeyYour API key must be placed at:
~/.vim/pack/plugins/start/vim-gpt/config/apikeyThe installer will prompt you to paste it the first time.
To generate an API key:
vim-gpt/
βββ autoload/
β βββ gpt.vim # Vim commands and logic
βββ python/
β βββ gpt_backend.py # Python script for OpenAI API requests
βββ config/
β βββ apikey # Your OpenAI API key (not committed)
βββ README.md
- Debian/Ubuntu Linux, macOS (for installer script)
- Python (via
pyenv) pipwithopenai- Vim (8.0+) or Neovim
PRs are welcome at: https://github.com/rfilipo/Vim-GPT
Crafted with π§ by @rfilipo and GPT β¨