ChatGPT in Neovim - Copilot Killer?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to show you how to integrate chat GPT with neovim in a way that is even more powerful than copilot and removes the need to leave neovim to ask chat GPT a question first you are going to need a chat GPT API key from open AI if you don't already have an open AI account create an account first then click the link in the show notes to get to the API key page click create new secret key and give your key a name that indicates where it will be used I called mine neovim click the button to copy your new API key and put it somewhere safe for now we'll need this later next we are going to install a neovim plugin called chat gp. NVM see the show notes for a link to install the plugin scroll to the installation section and copy the snippet for whichever plug-in manager you use paste this into your plugins. Lua file your file name and location may be different than mine save the file to install your plugin we also need to configure the plugin so let's create a new configuration file in our plugins directory be sure to reference the new file in your init.lua copy the setup and default configuration from the plugins GitHub page and paste it into your configuration file if you just want to use the defaults then you only need the API key command setting but I like to copy the entire config so that I can easily change values later the most important setting is the API key command which you will set to a shell command that retrieves your API key I'm using lib secret to store my passwords and keys so I'll be installing secret tool which is a command line interface to the lib secret Library there are instructions on the chat gp. envm page for using other secret managers first I'll install secret tool with the following command next I will use the store command to store the API I key we created earlier into lib secret this command needs a label followed by an attribute value pair that the secret will be associated with you will then be prompted for the password which is just your API key to test if the key is stored correctly run the lookup command with the same attribute value pair when you have that working copy the full lookup command and paste it in the API key command setting of our configuration let's restart neovim and try out the chat GPT command shoot it appears I don't have any credits in my account if you are starting a brand new account you may already have some complimentary credits but my account was a bit older so I'll head back to the open AI page and click the billing tab click the add payment method button and fill in the appropriate details next you can set how much you will fund the account with credits and if you want it to automatically recur I'm just trying things out so I'm going to set it to the minimum amount and not an enable recurring payments let's try the chat GPT command again in neovim hm looks like it still isn't recognizing our credits let me try restarting neovim again hey look at that we are able to use the chat prompt just like chat GPT in our browser this means we never have to leave neovim to ask chat GPT a question again awesome okay now we are going to step it up a notch and edit some codee first let's use visual line mode shift V to highlight a block of code then run the chat GPT edit with instructions command on the left side you will see the code you just highlighted the existing code reads account information from the database I'm going to try to get chat GPT to update the code to read a new database column a few seconds later and look at that to accept the updated code press control y it worked but now it is complaining because the corresponding class doesn't have that parameter this is easy enough to fix by hand but let's give chat GPT a crack at it it has no problem updating this class and if we go back to the original buffer you can see the error is no longer there next let's try the chat GPT complete code command I'll start out by typing out a comment of what I want the function to do this should provide some context for chat GPT to complete the code hm I'm getting an error that the 4K token limit has been exceeded this command seems to want to send the entire buffer to chat GPT and my files are rather large so this could be quite costly I'll try it in a separate file just to test it out it seems to work but in my opinion it's a bit clunky fortunately there is a much better option the chat GPT run command takes a parameter indicating the action you want to run there is a good set of options built in but you can extend these with your own options as well let's try the complete code example again but this time using the chat GPT run command first we highlight the lines we want to use for context then we type the command chat GPT run space complete underscore code that's much better while the code that gets generated is not always perfect this workflow was much nicer than the chat GPT complete code command and it only sends the selected text as context let's try a few other chat GPT run actions the fix bugs action will analyze the selected code and attempt to fix any bugs that it finds in this case there weren't really any obvious bugs but it did notice that the code didn't handle exceptions so it added an appropriate TR catch block pretty neat to accept the updated code press contrl y the next chat GPT run action I want to show is the explain code action this will analyze the selected code and provide a detailed explanation of what the code does this is handy when you reading a co-worker's code or even your own code from a year ago it looks like it did a pretty good job next up is the dock string action this action will automatically generate a documentation block for the selected function not only does it provide a reasonable explanation for what the function does but it also has the appropriate arguments and return types if you have trouble coming up with professional sounding messages the grammar correction action will help it does a pretty good job with this poorly worded error message but I still wanted something a little more professional so I used the edit with instructions command we saw earlier to polish it up next let's look at the ad Test action this action will automatically create unit tests for the selected function the generated unit tests looked decent enough but there were references to a Constructor that didn't exist so I decided to use our old friend the edit with instructions command that looks much better the last command that we are going to look at today is the chat GPT act as command this powerful command tells chat GPT to act like a specific Persona in order to better answer your question for instance we can tell it to act as a SQL terminal now we provideed a SQL query and it will respond appropriately feel free to explore the different personas to see what is useful for your workflow for this video I use the default GPT 3.5 turbo model but you can also use another model such as GPT 4 by changing your configuration we've used this plug-in quite a bit today so before you go let's see how much we've spent only 4 cents that's not bad make sure to subscribe to see more great neovim videos like this in the future
Info
Channel: Nerd Signals
Views: 4,648
Rating: undefined out of 5
Keywords: neovim, vim, chatgpt, chat gpt, open ai, copilot, copilot x
Id: jrFjtwm-R94
Channel Id: undefined
Length: 8min 3sec (483 seconds)
Published: Sat Nov 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.