A Vim plugin for using Generative Pre-trained Transformer (GPT) from OpenAI API.
Plug 'kelvins/vim-gpt'
Plugin 'kelvins/vim-gpt'
curl
: to execute HTTP requests to the OpenAI API.jq
: to parse JSON responses.
To use the OpenAI API you will need an API key. To get an API key, go to OpenAI platform web site (here), create an account and generate the API key. Now, set the API key in the $OPENAI_API_KEY
environment variable, for example:
export OPENAI_API_KEY=s4jyM5kSMbw7MG6Uqv3bw3T3B4b4F6X9pLpz36vr8eaKzXPC
In Vim normal mode just type :GPT
and an input prompt will be displayed, just type the content you want to send and hit Enter
, for example:
Prompt: Write a Hello World function in Rust
It will open a popup window with a response preview so you can type q
to ignore and close the popup or w
to close the popup and copy the content to the current buffer.
You can map a shortcut like ctrl + g
, in your ~/.vimrc
file, to open the prompt, for example:
nnoremap <C-g> <ESC>:GPT<CR>
This plugin uses the OpenAI API, so be careful with sensitive information.
GPT doesn't always give correct answers, remember to double check any text or code generated by the AI.
All contributions are welcome! Please take a look at the contribution guidelines first.