Neovim and Git: SOLVED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm going to show you how to get some amazing features of git within neovim using just two plugins seriously check this out in my git configuration now I can see these beautiful lines on the Le hand side of my line numbers showing the changes between git and my local copy of this file using just a couple of colors that give me a good indication of what's different between my local copy of this file and git I can also toggle line blaming so that when I hover over a line it'll show me the latest change who changed it and on what date I can also preview hunks in line inside of vim and I can get blame my files so I can see who changed things most recently wow this developer is terrible these are exciting and Powerful features that you can use with Git within neov using just these two plugins I'm going to show you what they are and how to install them let's get into [Music] it recently we released a whole entire course on neovim configuration called neovim for noobs and everyone else really and so far that feedback has been amazing but over and over again I saw people asking questions about the same thing missing in our config we were missing G integration now in our last video I went over lazy git which personally I think is a game Cher for using git really it's amazing but we're still missing some really big pieces of functionality within neovim forgit so in this video I want to go over two plugins that think bring all of the functionality you would need for git in neovim those two plugins are git signs and fugitive so let's go over git signs first the main reason I love using git signs is basically for the lines that it gives you to the left of your line numbers you can see them in a couple places throughout the documentation but there's also some interesting things you can preview hunks in line and you can also hunk things in line which is kind of interesting and you can also toggle line blame which feels very VSS Codi so we'll get into that in this video I'll show you in a little bit how to do it but to start let's install it so we want to copy the short URL forg go to our configuration and let's make a new file in our plugins directory called git signs Lua we want to return a Lua table that contains the short URL for the git repo URL and then we want to set up our configuration and the config is a function and all it does is we require get signs and call setup and that's all we need so let's quit neovim reopen it and there you go g signs is now installed so now let's see if G signs is even working I'm sure it is and there you go look now we can see we have a line right here in our configuration this line is yellow that means that there was a change so now if we want to see what this change is we can call get signs preview hunk in line and that'll that'll show us the change in line now if we say get signs preview honk that'll open it in a little extra window there I I like that a little bit better so let's go back to our get signs file and set a new keymap vm. ke map. set in normal mode leader and I want to call it GP for preview get preview this is where we want to call get signs preview hunk with a carriage return and an empty options table okay so now if we quit neovim and reopen it if we go to That honk again that we want to preview and we type space GP there we go we get our a nice little previewed hunk that's really cool I like that a lot now on top of that of course you also get these lines this line shows up to the left of your numbers and what it tells you using the colors green or yellow if there's something new in your file versus what's existing currently in git or something that's changed on that line yellow means that something's changed on the line green means that you've added something completely new to the file that's really great just for kind of spot checking the differences in your file and just getting a feel for what's changed between your local copy of the file and what's in the git repository I think that's really helpful and the other thing with Git signs that I find really interesting is the ability to toggle the current line blame this feels like vs code in a way but what it allows you to do is while you scroll through your file if you stop on a line for a second on the right hand side of that line You'll see the git blame for that line so I'll tell you really quickly like who changed the file on what date and what the commit message was so now I don't find this quite as useful because the second plugin I think is a little bit better than this but I think this is really fun so let's put another keymap for this functionality in our file so we can do Vim keymap doet leader GT for git signs toggle current line blame great so now if we reopen neovim if I type space GT I have toggled the current line blame and now I can see line blames for every line if I stop on that line pretty cool but this isn't the only plugin I wanted to show you there's another one kind of an OG plugin that's really powerful and always has been powerful it's amazing that plugin is vim fugitive Vim fugitive was written by the man the myth the legend himself Tim Pope and it's an unbelievable git rapper for neovim essentially what it does is it just wraps git commands and allows you to view those commands in neovim either in quick fix Windows or neoen paines things like that it's pretty straightforward the way it works but it's very powerful because you're not going to have to leave neovim in order to use some of these git commands it's really cool I'll show you all we have to do is copy the short URL of this repository and we can go back to our configuration file and you know what now I want to rename this file because it's not just about get signs we're going to do get integration stuff so let's just rename it to something a little more straightforward like get stuff. Lua I like that now since we're adding another plug into this we want to add another table so let's make this previous configuration into its own Lua table and let's make a new a table that contains just the short URL of the Tim Pop's Vim fugitive repository let's write this file first let's format it a little bit write and quit and then we can reopen neovim and we can see that lazy is installing Vim fugitive great so now if we can go back to our files we can check out Vim fugitive a little bit and see what we got going on here it basically uses the git command down in the bottom left of my screen here and after this get command you can run any command you can think of and it'll show it in Vim show you really quick if I want to find the changes to this file using get blame I just type get Space blame and then it'll show up in a pane right next to this file the whole entire blame history for this file this is super powerful I use this on a day-to-day basis if I want to just make sure I know who made a change to a file a lot of times I'm not sure what the context is so many times throughout my day I'll have to reach out to people asking them the reason behind certain changes this helps me get there really quickly now I know I can just just reach out to Christopher power and say why did you change the color scheme to katuin mocha instead of katuin for example and of course you can use all these other get commands like get commit that'll show you the commit status you can type get add to add a file and that'll add all the changes um in this repo now and we can see that they're all staged so now we can type get commit oops if I could Spell correctly get commit and now this allows us to commit all the changes that we just staged pretty cool and there's honestly a million other things you can do in v fugitive I suggest you look at the documentation it's pretty thorough and it's uh pretty well understood it's been around forever and now with just these two plugins you have all of the git functionality you could want within neovim and then some in my personal opinion and if you liked how this Vim setup looked check out our playlist for neovim for noobs where we go over this setup line by line file by file it's really great and I think you'll like it and hey thanks nerds [Music]
Info
Channel: typecraft
Views: 39,160
Rating: undefined out of 5
Keywords: git, git tutorial, git and neovim, neovim tutorial, neovim, vim, git cli, software engineering, git for beginners, git basics, gitsigns, vim fugitive, fugitive, vim plugins, software developer, developer productivity, neovim git
Id: zOQMwWqdp9w
Channel Id: undefined
Length: 8min 2sec (482 seconds)
Published: Tue Jan 30 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.