Check out a free preview of the full VIM Fundamentals course

The "Registers" Lesson is part of the full, VIM Fundamentals course featured in this preview video. Here's what you'd learn in this lesson:

ThePrimeagen discusses registers as a key value store and answers a student's question regarding what Lua and neovim are. Registers can be selected using double quotes and yanked to edit the original macro.


Transcript from the "Registers" Lesson

>> Lua is the plugin and customizing Lang or Neo vim. Lua is a language I think invented 20 years ago, 30 years ago. It's an exceptionally simple, highly embeddable language that has all c like interfaces effectively, and with Neo vim. They have it as just a first class citizen.

All the vim API's are exposed into Lua and so you can write your plugins in vinil. Which vim or you can write in Lua? I at least feel like Lua has multiple purposes, meaning that I am able to both use Lua in the oven. But I could also have a chance to use Lua at some other point right?

Like even at Netflix we experimented for a moment using Lua inside of our television app to be able to have like an easy to use really lightweight, dynamic language. And so Lua does have a lot of uses it's used a lot in the game industry for you eyes.

It so it's a pretty cool little language at least have some familiarity with it and because it's so tiny, you literally could learn the entire language if you're already familiar with the basic concepts of programming. Probably a day, there's nothing to it. Honestly, there is nothing to it, it's an exceptionally tiny language.

You can do basically o o or functional style stuff, so it's pretty straightforward. Alright, so I think we're gonna start back up. So I did leave it here on the cliff hanger. Look at that, we have this highlighted text from r macro very exciting, but we're gonna leave we're gonna quit, quit bang.

And now, let's go on. Let's go on to the next thing which is registers. So I have mentioned this thing over and over again. I've said the word registers that honestly when I first heard the term registers I definitely thought that they're definitely hard to imagine them not being hard, right?

They just feel hard. This idea of registers they're always flipping and flopping and why what are they for. Apparently they store macros in them. What the heck is a register? A register is as simple as a key value store a single character to a string. That is all it is.

Some registers are dynamically filled for you, such as the yanking register along with your delete history register, the implicit registers automatically filled for you. Your alternate file, your current file is automatically filled for you. There's a couple other, but then there's just a whole bunch of open empty registers that you can put anything into them and then you can do stuff with them.

So let's jump over here. Let's download this I honestly have no idea what's in this file. So this is exceptionally exciting at this point. So let's curl this down. And let's see what happens. So we've already talked a lot about this. We've already done a lot with this foo thing, pasting all that.

I actually explained this way earlier, right? So let's go right into how to interact with registers. So you'll notice something, whenever you do register, you'll notice that they all start with a double quote. The nice part about that is it's actually a really big hint to you if you press double quotes, then a register, you now have selected a register, which means then you can do a motion with that, right?

So, let's see here. So if I were to go like this, let's highlight this line. Now I'm gonna press quotes b yank right? So now theoretically, if I've done this correctly, I just yanked into the b register what I was highlighting. So let's go read again. You'll notice a the implicit register shows it right here what you also see is that the zeroeth register the gang history register, doesn't have that yank.

Instead, what you'll see is right here, inside the b register, it's actually right there, I'm able to yank into a register. Now hopefully, you're sitting there thinking well wait a second, if macros record to a register, and I can yank to a register, can I edit my macro?

Right? Why not? Why couldn't you? Of course you can. Silly pants. Let's do that. So let's go like this. Let's go quotes ap. I just pasted that macro that we executed earlier. Now I can start doing something with it right? I could go into insert mode and say hello world.

I can then take this escape key right here, highlight it, yank it, paste it right here. Take this highlight the whole thing, right? Or actually, you can highlight with using v dollar all the way to the end. Go back so that way, don't get that bonus new line.

Then I can go double quotes. Let's put it into C just so we don't clobber our original one c yank. Awesome. So now if we look at our registers again, what do we see? We see our original macro that we had, right? And we also see this Hello World one.

There's a Hello World one now. We just edited our macro live on the spot. So if you get macro pressure and you miss one small thing you can just hand edit it, as opposed to having to rego through the whole process, and execute it, and then go, okay I messed these ones but, I messed these ones.but you can start single out.

I can just put underscore here to go back to the beginning, I can do this to edit it this way. It also makes it really easy to work with any of these macros. So let's actually go back to the macro run. Let's go five down and I'm gonna go @c.

Look at that, case hello world, right it just did the same thing that we did before. But we added that little extra hello world went back into normal mode. Did all the text editing and did all the case statements and everything. So to act just like how we expected to and notice that the capital I that we used for the case statement, reg.

Notice that right here that capital I allowed us to actually go before the hello world and type in the case statement. And so it's still acted really like the way we expected it to act, which is actually pretty cool that this all just simply worked out we added we edited and we're able to replay them again.

So this is one thing that will help make macro pressure go away by the way, is the fact that you know if you don't get it right on the first try. You can just edit it, I forgot to press d d here. Okay, just do that boom, got it, threw them in there, we're good to go.

The only thing that's hard about them is getting the correct Escape key. So I always use Ctrl C, and I copy and paste that Ctrl C character and put it where it's supposed to be. I always I haven't really found a great way to get around that alright.

Awesome. So I mean, that's really all the stuff that has to do. I already showed you this one with the register one, right? There's like this already exists, like I showed you kinda everything there is really with registers. There's some ones that are auto generated. You can edit them, you can add them, you can yank them, you can paste back into them, you can change them and that's just how they work.

They're actually really simple. So the slogan of definitely hard to imagine them not being hard is actually incorrect. They're exceptionally simple, they're just simply single character to string value, and that is all they are. And then you can replay them either as key strokes or paste them places replace them with yank.

You got it. Awesome. So I feel like we've gone somewhere we've kind of we've done this we're able to see registers. And now we've had a pretty good like survey of a lot of features and Vim that make Vim pretty excellent. And we barely customized anything using plugins, right?

We only have a couple plugins. We have a color scheme and fozy finder. At this point vim is actually a fairly usable system. Sure we don't have autocomplete, very easy to get autocomplete. Sure, we don't have a range of color schemes or sweet things. We can get that sure our file tree is not that great.

Well, guess what? There's dervish, there's Ranger. There's all these other file plugins that you can use for other quick ideas into using vim or using cooler operating systems. We even have RG already integrated into vim. It was that simple. So yeah, I really liked it. I hope that you guys like all this.

We are gonna be moving forward a little bit and kinda doing a little step to the side. So this whole time we've been doing just then stuff, right? We haven't talked about any new motions in a while, right? We've been using only the ones we've already learned. We have learned how to kind of add them together and make them into composed commands such as like pen j, moves down 10 times.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now