- Read Tutorial
- Watch Guide Video
So to review our last guide we talked about some basic navigation things. We talked about how we can go from right with the L character, left with the H. How we could go down lines with J and then back up lines with K. We also talked about how we can get to any line we want, with just typing colon, followed by the line number, just like I did right there, and how to navigate to the end of a file with shift + G.
So those are all great, but now let's start to get into some more advanced ways of navigating. The first thing that I wanna do is I'm gonna go up to line four because this kinda gives us one specific line that we can navigate to. So first and foremost, if I wanna get to the end of the line, it wouldn't be very efficient to just hit L and to keep going, this would be a horrible way of navigating.
And so what we can actually do is, let's say that I wanna get to the end of the line, I can hit just the dollar sign($
). So if I hit dollar sign that'll take me to the very last character in the line. Now if I want to get to the very front of the line, so right where the L character is there, I can type in the the number 0
, and that takes me to the front of the line.
Now there are also some nice shortcuts for switching into different modes. So say that I want to start adding to the end of line four here, I can type in the letter capital A, so shift + A
, and now notice on the bottom left hand side I'm now in the insert mode and I can add anything I want just like this.
Now if I want to start at the very beginning of the line, make sure you're in normal mode, so hit escape and then type in shift + I. And now I can start typing in anything I want here as well, just like that.
So that is how you can go from the beginning or the end of the line.
Now let's say that we don't want to go all the way to the beginning or all the way to the end, we can actually navigate using one word at a time kind of keys. So here if I wanna get to one word back, I can type in the letter B
, and that takes me back, that's what the B if for, one word at a time.
Now if I wanna to navigate forwards, I can type in one word at a time, I can type in the letter W
, and that takes me forwards one word at a time.
Now this is also really helpful, let me go actually into our paragraph here and let's say that for some reason I wanna navigate 4 words to the word complete up there, I can actually type in the letters F
and C
, and it takes me there. So what that stands for is F for forwards, and C is any letter that I wanna pass.
So if you think of it from a programing perspective, then you can treat C kinda like an argument. So if I wanna navigate to the S of system, then I can type in F + S and there I go, I'm right there. And now obviously while I'm in here I can navigate through this in the same way that I would just like our line four with W to go forward and B to go backwards one word. So that is how you can navigate each one of those.
Also we talked about how you can get to the bottom of the file with shift + G. Now if you wanna get to the very top of the file, then hit shift + H
and that takes you to the very top of the file. So G and H, that's nice 'cause they're right next to each other. So being able to have that kind of efficiency getting to the bottom and then to the top is quite easy.
So those are some more advanced ways that you can navigate in the file and just to remind you, whenever we get out of the file we're in normal mode and then if we wanna save our changes type in W then Q and we're out. So that is how you can use some more advanced navigation tools inside of Vim. Now in the next guide we're gonna talk about the various modes that Vim has.