Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Awesome plugin: ChatGPT with NeoVim
uuta
uuta

Posted on • Edited on

     

Awesome plugin: ChatGPT with NeoVim

Today, OpenAI GPT-3 chatbot has enormous potential. Lately, there’s been a new AI bot in town: ChatGPT.

https://chat.openai.com

Releasing ChatGPT, it seems that many ambitious software engineers work on advancing its API via Slack, Line bot, and so on. I was finding luckily a NeoVim plugin that interacts with OpenAI’s GPT-3 chatbot:ChatGPT.nvim.

I’m a heavy user who’s enthusiastic to try a new feature of NeoVim, so this time I also began introducing this fascinating plugin. I will share with you how we use it andChatGPT.nvim works.

Input the touch command to make.openai_key.zsh file.

$touch$HOME/.openai_key.zsh$vi$HOME/.openai_key.zsh
Enter fullscreen modeExit fullscreen mode

Modify$HOME/.openai_key.zsh to set OPEN_API_KEY that is obtainable onthis page.

exportOPENAI_API_KEY=<value>
Enter fullscreen modeExit fullscreen mode

Add the following code into~/.zshrc file.

# ChatGPTsource"$HOME/.openai_key.zsh"
Enter fullscreen modeExit fullscreen mode

The reason why sets up an environment variable via.zsh is that the ChatGPT NeoVim plugin reads it withos.getenv() which is the method in python to extract an environment variable.

https://github.com/jackMort/ChatGPT.nvim/blob/6f602143d64b506fa8fcfa349df54ddb289360f2/lua/chatgpt/api.lua#L9-L13

Execute the following command to load configurations.

$source ~/.zshrc
Enter fullscreen modeExit fullscreen mode

Let’s move on to the next subject which configures NeoVim. It depends on developers about how the NeoVim configuration is, so the next description might not be suitable for everybody. I would be glad to consider what your configuration is. My NeoVim environment is there.

If you’ve already handled packer.nvim, installingChatGPT.nvim is really effortless. Copy and paste the next code in therequire(’packer’).

require('packer').startup(function(use)...-- ChatGPT-- https://github.com/jackMort/ChatGPT.nvimuse({"jackMort/ChatGPT.nvim",config=function()require("chatgpt").setup({})end,requires={"MunifTanjim/nui.nvim","nvim-lua/plenary.nvim","nvim-telescope/telescope.nvim"}})...)
Enter fullscreen modeExit fullscreen mode

Then, install it.

:PackerInstall
Enter fullscreen modeExit fullscreen mode

Currently, three commands are available inChatGPT.nvim. So I registered those ininit.lua as my key bindings.

-- ChatGPT-- https://github.com/jackMort/ChatGPT.nvimvim.keymap.set('n','<Leader>tk','<cmd>:ChatGPT<cr>')vim.keymap.set('n','<Leader>tj','<cmd>:ChatGPTActAs<cr>')vim.keymap.set('n','<Leader>tt','<cmd>:ChatGPTEditWithInstructions<cr>')
Enter fullscreen modeExit fullscreen mode

Let’s take a look at the screen after pushing the command<Leader>tt or:ChatGPTEditWithInstructions: opens an interactive window to edit selected text or the whole window.

Super cool!OpenAI GPT-3 chatbot returned a response that fixed a bug. Of course, the response fromOpenAI GPT-3 chatbot might be not always correct and proper, but it will give you great insight and improve your velocity of development.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromuuta

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp