nvim-gpt Plugin is a powerful and intuitive plugin designed to enhance your coding experience. It provides code explanations and general chat with OpenAI's GPT-3.5-turbo within Neovim using the OpenAI API.
- Explain selected code snippets in simple terms using OpenAI API
- Chat directly with OpenAI GPT-3.5-turbo using the
:GPT
command - Maintain a continuous conversation with GPT, summarizing the conversation when necessary
- Automatically clean up conversation history when closing the split window
- Neovim 0.5 or later
- Python 3.6 or later
- pynvim 0.43 or later
- OpenAI API key
Add the following to your init.vim
or init.lua
file:
Plug 'lzhgus/neovim-gpt'
Then run :PlugInstall
.
Add the following to your init.vim
or `init.lua file:
Plugin 'lzhgus/nvim-gpt'
Then run :PluginInstall
.
local status, packer = pcall(require, "packer")
packer.startup(function(use)
use {
'lzhgus/nvim-gpt',
config = function() vim.g.nvim_gpt_openai_api_key = "YOUR OPENAI API KEY" end,
}
end)
Option1: Export OPENAI_API_KEY to your environment
export OPENAI_API_KEY= '<YOUR_API_KEY>'
Option2: Add the following line to your Neovim configuration (init.vim or init.lua) to configure your OpenAI API key:
vim.g.nvim_gpt_openai_api_key = '<YOUR_API_KEY>'
To set up the keybinding for the :ExplainCode command in Lua, add the following line to your init.lua:
vim.api.nvim_set_keymap('n', '<leader>ec', ':ExplainCode<CR>', {noremap = true, silent = true})
- Select a piece of code in Neovim.
- Run the
:ExplainCode
command or use the keybinding (<leader>ec
by default) to get an explanation of the selected code. The explanation will be displayed in a new split window below the current buffer.
- Run the
:GPT
command followed by your message (e.g.,:GPT How do I reverse a string in Python?
). The response from GPT will be displayed in the same split window as code explanations. - Continue chatting with GPT by running the
:GPT
command with new messages. The plugin will maintain a conversation history and summarize it when necessary. When you close the split window, the conversation history will be automatically cleaned up.