This Vim plugin brings the power of OpenAI's ChatGPT API into your Vim editor, enabling you to request code explanations or improvements directly within Vim. With this plugin, you can effortlessly highlight code snippets and ask ChatGPT to explain, review, or rewrite them, with the option to include additional context for better results.
- Vim with Python3 support.
- A ChatGPT API key from OpenAI.
Add your ChatGPT API key to your environment:
export CHAT_GPT_KEY='your-api-key-here'
Copy the chatgpt.vim file into your Vim plugin directory (usually ~/.vim/plugin/ or $HOME/vimfiles/plugin/ on Windows). Alternatively, use vim-pathogen
Install the openai Python module using pip:
pip install openaiThe plugin offers the following commands for interacting with ChatGPT:
:Ask '<prompt>'Sends your raw prompt to the ChatGPT API.
To use this command, type :Ask followed by your prompt.
:<>ReviewSends the highlighted code to ChatGPT and requests a review.
To use these commands (:Explain, :Review, or :Rewrite), visually select the lines of code you want to interact with, then type the desired command and press Enter.
-
:GenerateCommitSends entire buffer to ChatGPT and requests a commit messages be generated, then pastes it at the top of the buffer To use this command typegit commit -vthen:GenerateCommit -
:<>Explain '<context>'Sends the highlighted code to ChatGPT and requests an explanation, with the option to include additional context. -
:<>Rewrite '<context>'Sends the highlighted code to ChatGPT and requests a rewritten version, with the option to include additional context.
To use this command, visually select the lines of code you want to extend, then type :Extend 'context', where context is any additional information you want to provide.
The ChatGPT response will be displayed in a new buffer.
- Enter visual mode by pressing V.
- Select the lines of code you want to explain, review, or rewrite.
- Type
:Explain,:Review, or:Rewriteand press Enter.
This plugin is not affiliated with or endorsed by OpenAI. You are responsible for managing your API usage and any associated costs when using this plugin.