 Today, we're going to quickly learn a whole bunch of VIM bindings you probably don't know about. Now, every key in VIM is a shortcut to something. It makes everything much easier. It's much easier to have a delete button, or change button, or find button. But we're going to talk about one key on the keyboard that is unique in VIM, and that is G, okay? Now, when you learn VIM Tutor, you will probably learn that, you know, G, G means go to the top of a document, capital G means go to the bottom. And, you know, I think VIM Tutor teaches you other things, like G, you know, Control G gives you file information down here at the bottom. But in reality, G has a bunch of other features, other, I don't know, a bunch of other things that go with it. So let's learn some of them. So firstly, here's one of the big problems if you're a new VIM user, you think it's a problem, it's not actually a problem. Let's say you have big text like this. One, and you're going up and down with H, or excuse me, with J and K. One thing you might find weird is the fact that all of this text here is treated as one line. So if I'm up, you know, if I'm up here, I go, I press G to go down, J to go down, and I press J to go down again, I'm now totally past all that text. That is often a little weird for people. They don't think of that. Now, there's a reason that works that way in VIM. I will say that. So you should use it this way. However, that might be, you might want to scroll through this text as if it is multiple different lines. And you do that with GJ and GK. So for example, if I press GJ, it actually goes through the text as if it is, you know, different lines. Or GK, same thing, right? So you can go up and down, no problem. I've actually seen some people remap J and K to GJ and GK. You can do that. You can put in your VIM RC, you can probably say something like this. It might have to be a remap or something like that. But you can specify that you want to move through lines individually. You can do that. I don't recommend that. What I really recommend is formatting your lines properly so they're not like this. Okay, so another, let me actually write these down. So there's GJ and GK. And additionally, there are other things. Of course, in VIM, you know that there is dollar sign to go to the end of a line and zero to go to the beginning of a line. Well, these also work prefixed by G. For example, so, you know, dollar sign goes way back here to the end of the paragraph. But if I press G dollar sign, it actually goes to the end of the visual line. Same thing, if I'm here and I press zero, it'll go back to, you know, this word here. But if I press G zero, it will go to the beginning of the line. So you can actually have a constellation of different G shortcuts that will only acknowledge lines, visual lines, rather than actual VIM lines. Now, the most important of all these is actually GQ, though, okay? And that's because when you are dealing with long text, you frankly just, especially if it's like prose text in a markdown, like some kind of markup file, you really should not format it like this. You should really format it so the lines aren't too long and, you know, they wrap and stuff like that. And of course, when you compile it, it doesn't make a difference. It's just more visible, not just it's more usable in VIM, it's also more usable in other computer tools. So GQ, that is actually a command that you can put a text object off after. So let's say GQ, I don't know, well, I'll just say GQQ to operate on this whole line. And you'll see what did this do? Well, it took all this text and it's made it, it's basically returned a bunch so that it is now one big paragraph that's actually multiple lines that are treated as multiple lines in VIM, right? So to undo that, notice that, you know, we have just one big line, GQQ, that has formatted it all as one thing, okay? Now, of course, GQ is just a command that you can give any text object. So let's say I give GQ5 down, okay? It's going to go five lines down and it's going to take these other two paragraphs and it's going to format them in the same way. And of course, you can use it with, I don't know, select a round of paragraph and then press GQ, same thing as any other kind of VIM command. Okay, so that's that and that's very useful. I actually have in my VMRC, I have norm QGQ, okay? No, capital Q is, you know, I basically never use capital Q, someone's going to tell me I should. But a lot of people press capital Q accidentally and then they're like, oh my goodness, how do I get out of this mode? Either way, I just actually remap it to GQ. So I just like press in capital Q, capital Q to use that, you know, to format text, okay? All right, so next thing with G commands, capitalization, okay? One thing that I think a lot of people want to do a lot in a text file is to change the capitalistic, like capitalize something, uncapitalize something. So here's an example. Let's say for whatever reason, well, I'll go ahead and give you the commands, okay? GU means uncapitalize something. G of big U means capitalize something and these can be followed by any kind of text objects. So let's say, you know, let's say I'm here, I want to uncapitalize everything from here to the end of the line. Well, I can say GU to uncapitalize and then I can just give a text object, let's say the end of the line. Now GNU Linux is no longer capitalized, okay? Or I could actually do, see how I is still capitalized here. Well, I could do GUU that acts on the whole line, right? Or let's say G capital U, three words, that will capitalize the first three words, okay? Normal, just use, they use normal text objects, it works pretty much how you expect, okay? Or let's say GUU to capitalize the whole thing. Or we'll lowercase the whole thing. Another capitalization, you may know about this, there's another binding, not related to G, but there's a tilde. And what tilde does is it switches the capitalization of a particular letter. So let's say we just want to capitalize I, we can press tilde, okay? Or, well, let's go over here, we'll capitalize, we'll find the next L, so GNU Linux is capitalized. Now additionally, I mentioned tilde, there's also G tilde, and so tilde will change the capitalization of one letter. G tilde is actually, you know, you can use it as a command that runs on a text object. So I can say G tilde tilde to act on the whole line, or I could do something like G tilde, you know, big word, and it will, now instead of GNU Linux, it will be, you know, uncapital GNU, uncapital L, and then the rest is capital, because we're just switching capitalization. So again, GU to uncapitalize, G capital U to capitalize, and then G tilde if you just sadistically want to change capitalization. Okay, so here's some other stuff, just random G commands that might be useful. Here's one I use all the time. One interesting thing is that if you have a file name in a VIM document, and some people will know this, some people don't, but I have created a file called another underscore file, if I press GF while I have this highlighted, this will go and open that file. So here's my other file, yeah, this is another file, press the little carrot thing to return to the previous file. So I'm going to do that. So that's a way of moving from file to file, and you can also, I mean, you can even do things like, let's say it doesn't have to be a relative link, it could be, you know, a full file name or something like that. So let's say Etsy hostname, I can go to there, and look, that pops up, all right? So here's my actual hostname file. So, you know, that's just a nice thing to do, and it's very easy when you're, I mean, it's easy when you're doing some kind of, I don't know, actual work, frankly, it's very useful. All right, so reselecting, here's some other things. You can, I don't know, other random G commands. When you have, let's say you select some text, okay, and you unselect it, and maybe you do some other work somewhere else. Well, you can actually, at any time, press GV, and you will automatically jump back to that text that you just selected, and it will reselect it. And then you can do some more stuff over here, you know, and you can press GV again, and it's gonna be selected once again, all right? So GV, that's another nice thing, reselect text that can be usable. Now, one more thing is conjoining lines, all right? Now, one great, fantastic tool, actually the opposite of the thing we were doing up here. We were doing GQ to put everything on different lines. You also might know that there's capital J, and that means join lines. So this will automatically format a bunch of lines, however many you say, into one big thing. Okay, let's actually do that the right way. Now, the thing with J, capital J, though, is that let's say we have all the letters in the alphabet right here. Well, if I press capital J, you'll see that it's joining these lines, but you can't put a space in between, okay? That's sort of annoying. And to be clear, you can also use, let's say we highlight all this and press J, there's spaces in between, we don't like that. Well, there's a analog of capital J, which is G capital J, as you may be able to guess. And what this does is you can highlight it all and press G capital J, and that will join all the lines, but it will not put a space in between, okay? Now, normally you do want that space in between other times you are formatting text like this, like that's prose, or other things where you want some kind of space, but sometimes you don't. Let's say our alphabet example, that's a good one. And that's pretty much all, yeah, that's just a useful thing to keep in mind. Otherwise you'd have to do like J, X, J, X, J, X, which you could do if you really want to. It was just like one or two lines. Now, lastly, one thing that you do a lot in a file is substituting, like substituting a function name or a variable name that you're changing. You just want to change it throughout a document, but a lot of the times you want to check to see if your substitution is actually working first. So I'm going to do something here. Let's say we have, I'm going to delete all this stuff besides the Latin text up here, because we're going to use that. So I'm on this line, and I have the word nebulae. The substitution command, let's say I don't want that AE at the end. I want it to be the ligature that's like AE together. So I can substitute the sequence of AE for the ligature of AE. I have an international keyboard, and then we'll do that globally for this line. Now, the substitute command by itself only works on the line that you're on. Otherwise you have to go back into the command, change it, a little percent sign at the beginning or whatever to make it work on the whole document. But one nice little command out there is g ampersand. And what that does is it takes the previous substitute command that you ran, and instead of running it on one line, it runs it throughout the document. So I'm just going to run g ampersand, and you'll see some changes in the top, but what actually happened is that all of our AE's were replaced by AE with the ligature. So that is a good way, like g ampersand, it's a good way you can test out a replacement command, a substitute command on one line. If that works, then you can just press g ampersand and it runs throughout the document. So that's a fantastic thing. All right, so this has been a whole bunch of Vim commands in one sitting. Now you know a whole lot more than what you knew before. And you know what, there's even more because in Vim you can of course type, you can actually just type, I think, help g bring up a list of all the other commands that start with g, most of which I have not talked about. Some of them are very rarefied, but you can learn anymore. These are the ones that I use pretty often. But anyway, that's it and I'll see you guys next time.