 We're going to be doing some advanced applied laziness in VIM today. And this is one of the things you can do nearly automatically in VIM with just the teensy bit of setup. But it would be a huge annoyance to do anywhere, you know, doing it manually, okay? Here's what I'm doing. I am actually taking some papal encyclicals and I am compiling them into a LaTeX document. So I'm taking this HTML document, I'm putting it into a tech file, I'm going to format the tech file and then that compiles to a nice printable document and of course I'm going through, you know, correcting changes and stuff like this. There are a lot of, you know, missing spaces and stuff like that. But here's one thing that, you know, I can do automatically in VIM but would be a big pain otherwise. If you look at the bottom, there are actually 41 footnotes to this document. Now footnotes in LaTeX are done in a very particular way. Let me actually do one of them manually. What I would have to do is go down to the bottom here, okay, and I would have to find a footnote. Let's say I want to take footnote number one here and I'm going to copy that and I'm going to go to the first place that footnote is evoked, you can see here. This is supposed to be the superscript and you have to put it in LaTeX syntax which looks something like this, okay, so I have, let me actually make this a little bigger for you, okay. So you'll see I have this command here slash footnote and all the footnote is put in pearly brackets and I'm actually going to get rid of the numbered footnote. And that's how footnotes are done in LaTeX. They're numbered automatically when you compile them. Let me actually show you what it looks like. So I need to do this chapter. That's what I'm going to do in this video. I'm going to do it with, you know, a very simple VIM macro. But this is what they'll end up looking like. I've already done this chapter here. You have, of course, the number and it automatically puts that footnote in the bottom and it automatically numbers it, okay, based on, you know, which one it is in the document. So let's go ahead, now I'm not talking about LaTeX or anything fancy here. I just want to talk about how do I automatically get all of these footnotes and put them where they belong in the document further up. How do I actually do that? That's sort of a big pain. Well, I'm going to talk it through using VIM. Okay, first off, I'm going to turn on screen key so you can see what I'm typing. Now, in this document, if I search for open parenthesis and then any number of any length with a closed parenthesis, that will actually lead me to all of these footnotes here. So I can keep pressing in and you'll see each time I am going to a footnote, okay? Now I'm actually going to, I think I want to make this a little easy for me. Well, I won't do that first. Here's what I'm going to do. I want my macro to, I want to be able to run it like in sequence. So what I want it to do is I want to give it a command that will automatically go down to the bottom, get the text for the corresponding number here and put that there and then go to the next footnote. So let's go ahead and start doing this. Okay, so here's what I'm going to do. Next thing I'm going to do, let's think about this. I am going to say delete, well, actually I got to actually record the macro. To record a macro, press Q and then you have to give it some kind of label. I'm going to say F for footnote. So now you see at the bottom it's saying recording at F, okay? So what I'm going to do here is I'm going to assume that I'm already at the beginning of a footnote and I'm going to say delete in parenthesis, okay? So I've deleted that too. Importantly, I've actually copied it to my clipboard. So now what I can do is I can, let's say, search for the beginning of a line and then I'm going to press Ctrl R and then Quotation. And what that does is it actually inputs what you have copied into your register. And then I think I want closing parenthesis and that is actually going to lead me to the corresponding footnote down here. So I'm going to press Enter, all right? And I'm going to say, I want to get rid of this little number thing here. So I'm going to say delete around word. Now I just have the text of the footnote here. Now I'm going to say capital D to delete to the end of the line. Now I have copied that footnote where I want it. Now I'm going to say quotation mark, quotation mark. And that is going to return me to the last line I was at, okay? Now at this point, I think I'm going to do, I think this is going to work better if we have multiple footnotes in one place. Actually I probably wouldn't even have to do the quotation mark, quotation mark thing. But I'm just going to say, search for open and close parenthesis. And that's going to lead me to the place where I just deleted that number. Now I am going to, let's say, I'm going to go over to the other side. I'm going to press A to insert text. And I'm going to say footnote, okay? Open and close. And then escape. And then I'm going to press P, I'm going to go back and press P. And that's going to insert that footnote that I just put in. Last, I'm going to delete the little parentheses at the beginning. So I'm going to go, let's say capital F to find. And then let's close, or yeah, close parenthesis. And then I say delete around parenthesis. Okay, that's basically, now that seems very complicated. You might say, oh, you did all this complicated stuff when you could have done this manually. But once we do this, we won't have to do it again. But I'm going to add one extra thing to it. I'm going to go ahead and search for the next footnote out here. Which again is going to be open parenthesis. And then search for any number, any number of times. And then close parenthesis. Now I'm done recording my macro. So I am going to press Q, okay? So remember we started by pressing Q and then F. And then we hit all the keys we wanted to hit. Then we press Q and now that macro is recorded. We have recorded all of those operations in a macro that we can now run whenever. So if we want to run that F macro, we just press at and then F, okay? Now you saw my screen move around a little bit, but look what just happened. This used to be, actually let's press undo to undo it. This used to be three, let me redo it. And it went down to where the third footnote is, grab that text and put it back where we wanted. And it actually originally, it originally put me at this fourth footnote as well. So I can say at F and then it just got the fourth footnote, put it where it belongs here, okay? And now we're at the fifth one. And now of course we can run this multiple times. Let's say I want to run it, you know, ten times. So one, zero, at F, okay? So that's running it for the next ten footnotes, okay? It's going through and manually finding all of the stuff to put in for us. It's actually taking a while. It's probably taking a while because I'm recording a video. But I can actually just say, you know, 100 F and that's going to do it for the rest of the document because, I mean, we have less than 100 footnotes. And when it gets to the end, when it finds it, it can no longer find the next sequence of a parenthesis and, you know, numbers, it's just going to say, oh, I can't find a match. And it's going to stop calling the macros even though it hasn't reached 100. So now look, it's actually over now. And we can look down in our references here. And it looks like there's one that somehow escaped. We'll figure out what's going on with that. But all of the other footnotes have been properly formatted. It might be, let's see. Yeah, it looks like the people who originally put this text in forgot to, you know, actually put the reference point where this footnote is actually supposed to be. But for everything else, it did it automatically. So I'm going to have to read this document and find where exactly this goes. But now, you know, that's just the minor example of the kind of things you can do with Vim. I only did this with, you know, 40 or so footnotes. But now that I've recorded that macro, if I, you know, let's say I take another papal encyclical that has a similar formatting to this. Actually, I think I copied it from this one because they're using parenthesis for footnotes or whatever. But any other document that has the same format, I can still use that same macro. So macros are a very nice way of just getting so much done very quickly. It's a little hard when you first start out. But when you start to think and Vim in abstractions, in terms of regular expressions and commands, it makes things, you know, way more effective. So anyway, yeah, that's it. Just wanted to show you that I use this all the time. See you guys next time. Oh, and I suppose I should show you that, of course, once I compile the LaTeX document, all the footnotes are working as expected. Here is the little, the one that we just did. So we see them all, of course, appearing as proper footnotes, properly ordered and stuff like that. So yeah, I mean, everything pretty much works as you expect. So that's about it.