VIM Fundamentals

Customizing vim View



VIM Fundamentals

Check out a free preview of the full VIM Fundamentals course

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

ThePrimeagen demonstrates how to execute commands including setting auto scrolling, deleting multiple lines, setting line numbers. Setting relative line numbers will display line numbers that are relative to where the cursor is currently located.


Transcript from the "Customizing vim View" Lesson

>> All right, so, as I was saying earlier, just right now that before this, we were in the intro section. So I was taking it very slow, I was intentionally telling you every move I was making. From here on out, we're gonna start speeding up cuz there's a lot of stuff we want to cover.

A lot of cool things and I wanna make sure you have that opportunity, okay, so let's start making vim my way, not the vim way, but my way. Yes, exactly, thank you. For those that can't see the zoom call is just beautiful, everything was fine for a second.

So remember when we are in this file, let's see, let it so just recall your previous file down. Whatever what I believe is insert mode, remember how I had to keep on using ZZ to center myself, that was kind of annoying, right? You didn't wanna have to do that all the time, so we're gonna execute our first vim command together.

It's gonna be a magical moment and remember, so I'm gonna go into command mode, call to go into command mode when you're in normal mode. There we go and I'm going to do this set, scrolloff= 8, just scroll off, right? I don't know it feels like an insult almost, I'm gonna hit enter.

Now what this means is that when I'm eight lines away, it will automatically start scrolling for me. So that way it is nicer until you get to the bottom of the file. So here, let me zoom out a little bit, if I zoom out a little bit, you'll notice it's not quite there.

If I too zoomed in, this file is a little too small to show it, but you can kinda see it, right? Things stay more centered or they'll at least be like bottom centered. So this is very, very nice little feature to have, I love it, I didn't have it for a long time, cuz I just didn't even know it existed.

So just remember that that's a command you can execute in vim and it'll be awesome. So let's quit this, now give you the next thing to do this. It feels good though, right, yes, all right, so let's quit vim, and we're gonna download this upcoming file, okay? So now we're gonna start moving a little bit faster, doing some pretty fun things.

So I'm gonna copy this file, I will throw it into chat, curl these unknown files, let's edit them together okay? How many times did I make that joke before it gets old, I don't even know, but we're gonna keep doing it. All right, so we're gonna press enter and now we have a lot more.

So once again, notice that if I scroll all the way down, do you see scroll off didn't stay. Why in a weird, so I'm gonna do it again set, scrolloff=8. Wow that's inconvenient to do but as I scroll hey, that's really nice, I like to be able to move around and actually move the screen with me.

So now let's all together go down to the delete that description, so how you learn how to delete is using dd. So let's just do that dd that together dddddddddddddddd. There we go, we did it. We just ran through that pretty quickly, let's undo that. Okay, let's undo our changes, we just got done doing and we're gonna do it differently now.

All right, we're gonna use 7dd, what I just did there is I said, hey, delete these lines, but do it 7 times. That was pretty awesome, right, you just did a bunch of deleting In very little effort but why was that hard? Think about that for a moment, what made that kind of hard to do?

Well, one of the reasons why it made it hard to do, is you have no line numbers. How in the world are you supposed to do, what am I supposed to do, sorry, wrong direction. What am I supposed to do, there's no lines, right here and that's problematic, right?

You want to be able to know where you're at, so what we're gonna do is we do another set command, set number. What this will do is that will set the numbers into your editor. My goodness you probably are ready start, you're starting the feel like, hey wait a second.

This feels more familiar I'm starting to not feel as lost as I once was. And so now we can retry 7dd again, okay, 9 minus15 is 6. All right, so with dd and the numbers I have to do one plus the math, and I have to do the math in my head.

My goodness this is like not easy, well, guess what, there's an answer for you. Set, relative number, now relative and number is a lot of things to type. If you don't wanna quite type it all do rela and then hit tab and it will complete for you relative number and if you really don't even wanna type that, you can just do rnu for short, right?

Relative number, I know great way to remember, hit Enter and look what it's done. We have kept our line number on our current cursor, but then everything else is a relative offset from your cursor. Now this may seem a little strange and I totally get it, it is a little strange.

It's not like other editors, you wouldn't do this in other editors because you use a mouse and you move around. But for vim, it makes a lot of sense, now I was a relative number hater, okay, I was all about like no way I was just not gonna happen right?

I was throwing my little danglers all around, very upset about it but instead I've learned to love it because I got good at the commands that use relative numbers. So now it's at least easier, I can go okay, I wanna delete up to the function 7dd. Awesome, right, you know what you can also do, you can also go like this d6J.

I want to delete six downwards, now that might feel a little bit better to you, right? Or you can do something like shift V, six J, now you know what you're about to delete let's hit Delete. Now notice that we're starting to take all these commands that we've kind of used and we're starting to kinda build them up into a composed item.

It's feeling a lot better, right, now you can start seeing there is actual speed benefits.

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