Introduction to ChatGPT.nvim
ChatGPT.nvim is an innovative Neovim plugin designed to harness the power of the OpenAI ChatGPT API, allowing users to generate natural language responses directly within their text editor. With this plugin, users can engage with ChatGPT for insightful discussions and coding assistance right from their Neovim environment.
Key Features
Interactive Question & Answer
ChatGPT.nvim offers an interactive Q&A session using OpenAI's ChatGPT, providing users with a smooth and intuitive interface to query and receive detailed answers.
Persona-Based Conversations
Users can choose from a variety of conversation styles by interacting with different personas, utilizing prompts from Awesome ChatGPT Prompts to enrich their dialogue experiences.
Assisting Code Editing
The plugin enhances the coding workflow by integrating an interactive editing window that uses ChatGPT to provide specialized guidance tailored to various coding tasks.
Code Completion
Similar to platforms like GitHub Copilot, ChatGPT.nvim aids in code completion by suggesting snippets and completions by understanding the coding context and patterns.
Customizable Actions
ChatGPT.nvim allows users to execute a wide range of actions such as grammar checking, translation, keyword generation, and more. Users can even define personalized actions with a JSON file.
For a deeper understanding, a comprehensive plugin showcase video is available here.
Installation Guide
To get started with ChatGPT.nvim:
- Ensure that
curl
is installed on your system. - Obtain an API key from OpenAI. This can be acquired from their official API keys page. Note that a ChatGPT Plus subscription does not cover API credits; these must be purchased separately.
The OpenAI API key can be configured by:
- Setting it within the
api_key_cmd
as an executable returning the API key through stdout. - Defining it as an environment variable named
$OPENAI_API_KEY
.
For those unable to access OpenAI directly, a custom API host can be configured via api_host_cmd
or the $OPENAI_API_HOST
environment variable. Additional curl parameters can also be specified if needed.
Example Configuration
An example setup using the chat model with specific parameters looks as follows:
{
"jackMort/ChatGPT.nvim",
event = "VeryLazy",
config = function()
require("chatgpt").setup({
openai_params = {
model = "gpt-4-1106-preview",
max_tokens = 4095,
temperature = 0.2
}
})
end,
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"folke/trouble.nvim",
"nvim-telescope/telescope.nvim"
}
}
Security Considerations
While configuring the API key via the environment variable $OPENAI_API_KEY
is straightforward, it exposes the key to potential risks. Instead, it's advisable to use the api_key_cmd
option, which executes a command at startup to securely fetch the API key.
How to Use
Once set up, ChatGPT.nvim provides several commands accessible through your Neovim interface:
ChatGPT
: Opens an interactive chat window utilizing thegpt-3.5-turbo
model.ChatGPTActAs
: Selects prompts for use with thegpt-3.5-turbo
model.ChatGPTEditWithInstructions
: Facilitates text editing using thecode-davinci-edit-001
model, specifically fine-tuned for coding.
For detailed actions, users can reference the actions.json
file to explore predefined or custom actions for enhanced productivity.
Interactive Popup Features
Keybindings in interactive mode include:
<C-Enter>
to submit.<C-y>
to copy/yank the last answer.<C-o>
to toggle settings.- And more for efficient navigation and operation.
Conclusion
ChatGPT.nvim represents a seamless integration of advanced AI capabilities into the Neovim environment, substantially improving the coding experience and interactive engagements. With features tailored to making coding more intuitive and conversations more engaging, it stands as a valuable tool for developers looking to maximize efficiency in a text editor.