Transcript from the "Plugins" Lesson
>> All right, let's move on. Let's install some plugins, okay? So let's start making it better. So you have to have a plug in manager, right? That's how VS code really works underneath the hood is that, likely a lot of the plugins you're installing are just GitHub projects in which are shaped a certain way.
[00:00:18] Such that VS Code knows how to download them, put them in a special spot, and then run some sort of source on it that will make run really quickly and smoothly, right? So that's kind of how plugins work. That's same thing here with Vim, it's just the best way to do that.
[00:00:35] And the nice part is that, the demo that we've been kind of lightly writing is also the same code that is used to make plugins. If you're using Neovim you can use Lua, which Lua is that sweet Brazilian language which means moon. But it has one based indexing that kind of hurts a little bit, and it does have a type script to Lua converter.
[00:00:56] So you can have types and still have a sweet native plugin for Neovim. I haven't played with it yet, I'm gonna be playing with it here shortly, very excited about it. I want to see how it goes. So, before we can do anything, we have to get the plugin manager, right?
[00:01:12] So let's follow this link right here, that says plug if you don't have that link right in front of you. Go to your, that's so bright sorry everybody, go to your search bar just type in Vim plug and there you go top one it's by June gunn. Very cool name I might be saying his name wrong but I just love the idea of condom June gunn, and there you go.
[00:01:32] So you're gonna go through here you can see all the different installing here. Let me make it a lot bigger so we can see it, it'll be a nice plugin manager that can download all sorts of plugins. The best part about plugins is that you will just end up using GitHub for it.
[00:01:46] You'll just simply put the two words in GitHub my name plus whatever plugin or whoever. So this one's June gunn Vin plugin, if this was something to install, we will just simply use that and put that in there, it's very nice. So let's start first with the process of getting the plug in manager.
[00:02:01] We have to first download plug.vim, now it has a bunch of options for you to follow you can follow any of them. And if you're in Neovim you can still use the Vim1 here, I'm gonna use the Vim 1 myself right now. I'm gonna take this random script and I'm gonna go save it and Vim is gonna execute it for me.
[00:02:16] Fantastic, that's like the fifth time I made the joke, it's not gonna get onto me, anyway I'm gonna take it, I'm gonna copy and paste it, I'm gonna press Enter, it's gonna go, it's gonna download it. And now the next time I start Vim because it's in a special spot, it's going to source it and have it ready for us to be able to run.
[00:02:37] We'll kind of go over what the special spot means, but until then, just keep that in mind. There's a certain set of spots you can have and a certain shape of your directories, it'll start auto sourcing all of your stuff. All right, so we have that downloaded, let's find a plugin to install.
[00:02:56] So we'll go down a little bit further first, and we're gonna make sure we have this ready for us to cut and paste, okay? We can actually do this right now in fact, so let's go here and we have to do this first line. And so this first line will be dependent on where you install the script.
[00:03:10] I did mine, right, I'm gonna use the dot vim plugin folder, I'm gonna copy that, I'm gonna go back over to my terminal. I'm gonna edit my vim RC, I prefer to put it right after the sets is generally where I have everything, I'm gonna paste it in.
[00:03:27] And then I'm gonna do the end part, which means I will go over to N or begin typing end and then delete everything inside of there, so there we go. We have plug begin where it will save all the plugins at, and plug end to say okay, the plugin manager is done, go do the thing you're supposed to go do, and there we go.
[00:03:47] So now we're ready for plugins. Hopefully everyone was able to get the June gunn plugin for vim plug, I showed you how to do it. Awesome, I'm gonna assume everyone's ready. So this is the part with Windows where I wasn't sure how smooth it was gonna go, cuz I know that Windows is not Ubuntu, and I don't Know how it works.
[00:04:06] I know that the slashes are different, at that point you've confused me, I don't really know what's happening. So let's find a plugin, I wanna fuzzy find out that's gonna work for everybody here. So let's use fzf, if you haven't heard of fzf, also so bright sorry. It is a fuzzy finder plugin, so I'm gonna type in fzf vim_plugin, I'm gonna hit Enter, and look at that.
[00:04:29] My goodness, my cursors already ready to click it, and it's June gunn again, my goodness. It's like this person makes a bunch of plugins. So I'm gonna click this, we're gonna go to the GitHub page. I'm gonna scroll down, I'm gonna check the installation instructions just in case it's something I don't expect.
[00:04:45] Okay, look at that, it's actually is something I didn't expect. It requires two plugins, junegunn/fzf and junegunn/fzf.vim. So obviously, fzf/vim must be the simple wrapper around fzf. If you don't know what fzf is, it's pretty fantastic, it allows you to pipe any list into it, and then do a fuzzy find over it.
[00:05:03] It's pretty darn fast, it's pretty nice. So what I'm gonna do is, I'm gonna highlight these two items. I'm going to copy it and jump back in here, I'm gonna use that Shift+O to go right into where I want it to be. I'm gonna use Ctrl+Shift+V, cuz I'm pasting in a terminal.
[00:05:19] Paste those two in I'm going to save it, and then I'm gonna use space Enter. I've now sourced my vim RC, so at this point, we're already to do something with it, but what do we do? You can't do anything yet, cuz you actually haven't got the plugins yet.
[00:05:38] So what I'm gonna do is, I'm gonna go down here and I'm gonna type in PL, and I'm going to hit Ctrl+D. Now notice we have a set of new commands in here, we have Plug, PlugClean, PlugDiff, PlugInstall. PlugInstall sounds about right, let's give it a shot. I'm gonna type in PlugInstall, hit tab to auto complete the rest of the characters hit Enter, and there it is, fzf and fzf.vim.
[00:06:00] If I were to take these two URLs right here, or these two words right here effectively and paste into GitHub, these would each be repos. They're just repos set up in a specific way to work with Vim. Fantastic, we now have it, we are ready. So we can use Ctrl+Wl to jump over to go into that one or we could have stayed in this and use :q and quit that window.
[00:06:25] Now we have this we're ready to go, this is fantastic, so we should be able to do some fuzzy finding. But what do we do? Well, as they always say to me read the friendly manual. So we're gonna go over to the friendly manual and notice right here, awesome.
[00:06:40] So if I do colon files, it will return all the files. If I do Gfiles, it will return all the Git files, it has a bunch of different other options which we can go over, but right now let's try g files. So if you're inside a project that has source control, it should work.
[00:06:57] Now remember, when I opened vim, I opened vim from the vim nav playground, but I directed it somewhere else. So that means when I do Gfiles, it'll actually use my vim nav playground because that is where it was opened up. That is the folder that it was as my project.
[00:07:14] So, now I can fuzzy find and find something. So if I wanted to open up twitch, I can see there's twitch.c twitch.h let's do twitch.c, my goodness, we're right back to where we started. Look at how beautiful that is, we are now fuzzy finding. This is like 10 times better but hey, like my Ctrl+P doesn't work.
[00:07:35] Why doesn't it work? Come on, you're paying attention, you know better than that, you've got to set up a remap. So let's go in here, let's open up our config, let's go down to the bottom, let's highlight, which one do we want to do? Let's highlight this one, why not?
[00:07:50] It's confusing, you can delete the rest of the line, I'm gonna show you a super cool shortcut, are you ready for this? Shift+D, look at that it deletes everything from your cursor all the way to the end of that line. It's fantastic, D is one of my favorite disc.
[00:08:06] So then I'm going to hit Shift+A, it's gonna go right into place and I'm gonna go Ctrl+P, remember you do the (C) your C look like this. And then of course p for Ctrl+P there we go, and then do a space I'm gonna go Gfiles. And don't forget this one trick that makes doctors very angry CR, carriage return.
[00:08:32] You can't forget that because if you don't do that what happens, it just typed the command but does not press enter for you. So there we go, Ctrl+P, will now execute get files. That's awesome, but if you're not in a Git repo, this command won't work. So you may wanna have a backup command that will work in this situation.
[00:08:51] And so what I actually have as a backup command, is I'll jump into here and I'll have project files and I'll just have something like this. So that way I have both Git files and project files, so just in case I'm not in a repo, I can still fuzzy search over the folder, make sense, right?
[00:09:06] I think that that is a fairly good practice to do, so there we go. So now, I just got to source it, what do we do to source it? No, no, no, don't you say source percent sign space Enter, right? Awesome, we've now just sourced it, we're using our shortcuts vim is our way we're doing things the way we like it.
[00:09:23] Maybe your shortcuts different than mine, perfectly fine, awesome. And now when I press Ctrl+ P, beautiful. If I had a bunch of files that weren't source controlled, I could do space PF. Yes look at that I am fuzzy finding like a madman at this point. I can kkk, I can also do, there we go, you can type in any letters you want bbbbb, it just works Ctrl+P will go backwards in the list control and we'll go forth in the list.
[00:09:48] Remember I told you Ctrl+P as an important habit to get into cuz by default, it works in every list. It's just beautiful, it doesn't work in quick fix list if I remember correctly, but we're gonna pretend like it does. All right, so you can use Ctrl+C to just close it down escape, you got it, it just works, this is beautiful.
[00:10:09] Hopefully everyone was able to get the vim plugin to be installed, it's not too hard. One you need a plugin manager I choose vim plug, there are other plugin managers vim even has its own default plugin manager. I just simply use vim plug cuz it's the easiest for me to either find the plugins you want, they're almost always on GitHub.
[00:10:28] You provide the GitHub address minus github.com, it just automatically downloads them for you, it sources them when you call plug end. This is a special function, all special functions with the hashtag human are special functions are called autoload functions. You don't even have to worry about what they mean or why they are like that.
[00:10:47] But you just know that these are two special functions you have to call. I wanna begin, I wanna end, and that's what it's gonna do, so awesome.