VIM Fundamentals

Insert Mode



VIM Fundamentals

Check out a free preview of the full VIM Fundamentals course

The "Insert Mode" 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 go into insert mode, insert to the left and right of the cursor, and inserting new lines. There is a brief overview of all motions covered so far at the end of the segment.


Transcript from the "Insert Mode" Lesson

>> So let's go to insert, now you're probably thinking insert, it's just I right, [LAUGH] no, there's a lot of ways to go into insert mode. And it's quite fantastic, in fact, this is actually one of my favorite things about vim is how many different ways you can go into insert mode.

I know this just a sounding ridic, as I say it out loud, I'm like, am I really saying this, out loud, yes, I am, I am saying this out loud, insert mode, I know. Like I said, it's gonna be shocking how many available ways you can go into insert mode.

And I'm only gonna give you a few of them here, because if I give too many now, you're gonna lose, there's some really good ones later. All right, so let's curl it in and let's go, so now we're going to do insert mode, so this is where it gets real exciting, right?

So let's use j to go all the way down j to the I, all right, so I, and then use w to kind of go into it so you kind of can see where we're at. So now know notice that my cursor is thick, right?, it's a thick cursor, I actually prefer it this way.

So when I go into visual when I go into insert mode actually maintain the thickness of the cursor, just an old habit, it's hard to make a die. I don't want it to die, but you can make it however you want, so when I press I, notice that my cursor goes to the left.

Up to the left, so I got a mirror myself to the left of my cursor, right, that's unusual. And when I press escape, notice that my cursor moved back one, so if I were to go, I escape, I would slowly walk myself back. So that is how insert effectively works, now notice what happens when I press a instead, a opens the cursor to the right.

Now this is a small distinction, but it's actually pretty darn useful in a lot of situations. Often you'll be off by one and probably in your current editor, which I'm just going to assume is Nano. You probably have to press like an arrow key to go over, and then you have to start typing and that just is kind of annoying, right?

You don't want to have to be in that position, it is really nice just to press a and e go over. Now, a and I are very important because they're used in other commands as well, and we'll get to them and they mean effectively the same thing. Means on the inside a means on the outside, all right, so let's go down, and here's the first example of it.

I want to go into insert mode, but I want to go at the first non whitespace character in this line. Well, I can use shift I, there we go, I just walked right into the first non whitespace character at the beginning of this line. That's pretty cool, right, so I'm going to, escape, insert mode, and we're gonna go down but before we go down, I'm gonna go back so I'm at the beginning.

We're gonna go down now and now shift a, I am assuming most people can guess what's going to happen here, which is you're going to now go to the end of the line. So when I hit shift a I'll go to the end of the line, but not just the end of the line, if there's any additional trailing whitespace then it will also go on the end of that.

So unlike I which only goes to the first and non whitespace character a goes always to the end of the line. So you got to kind of keep that in your head a little bit, but that is how capital I and capital a works, and trust me capital a is actually incredibly useful.

I don't use capital I that often, but capital A, you will always find yourself needing to go to the end of the line. And this is just something you're gonna have to either use today with your mouse just to simply move it over or use the arrow keys to try to get it right.

And that's often annoying, I'm sure there's some sort of sweet VS code shortcut that I don't know about because I don't use VS code anyways, so let's escape insert mode and go down one more line. So now we're gonna get into the o's now o was just mentioned o is fantastic, o is a glorious way to go into insert mode.

In fact, it's one of my favorite, okay, when you press o, It makes a new line respects the indenting of the language that you're in and puts you into insert mode. So if you have a function that's defined by two scoreless and then you press o it will properly indent you into that line, that is very.

That is when I learned about I think I might have taken the day off Just patting myself on the back. I was so excited, it was like the best it was just so great, I know this is fairly ridiculous to be that excited about going into insert mode but it really does just, I love these type of shortcuts that just make small things faster.

All right, you just don't have to do as many little things, alright, let's leave insert mode. Let's go down and let's try capital O, if capital P does what it does, I'm assuming you can guess what capital O does. Yes, it takes your current line, shifts it down, respects indenting and puts you into insert mode.

That is also glorious, all right, I use it all the time, and probably are my most frequently used ways to go into insert mode and then maybe capital A and then eventually I, but I don't use I all that often in comparison to the rest. All right, so play around for a second kind of feel it make sure you kind of understand, at least have the mental model that i goes on this side of the cursor, a goes on this side of the cursor.

I capitalize goes on this side of the line, A capitalize goes on this side of the line. Awesome, so that's insert mode, I didn't give you an exhaustive list cause I don't wanna do too much. This is effectively the basic commands, at this point you could be equivalent in editing text as you are today.

You might be pretty slow because you don't know all the commands, they don't feel normal. They don't feel natural, but this is kind of like the minimum bar, and this is why them gets that super steep an initial curve is because when you're doing it. You have to kind of know so much Just even basically at a text, and that can be extremely daunting for a lot of people.

I know it's overwhelming for those that are brand new, this is probably a lot of information, but let's just keep going. All right, we're gonna keep going, we're gonna just keep on shoving in information until we feel like we're gonna explode. It's kind of like college, just not as fun, all right, awesome, let's get out of this and let's go down.

All right, we've already kind of recap we've done most of this, I did sneak ZZ in there. I wasn't actually going to shows easy at all because I don't use it ever and there's a reason why you don't have to use it, but I thought it would be a lot of fun to just kind of make it happen.

That's 16 total motions that I showed you, there's a lot of motions, there's a lot of things to keep in your head. Today, you will likely have to remind yourself, I want to move down, what do I press? I press J, hopefully we can conquer J and K, number one, and then hopefully you can conquer some other things.

And also looking at my list I realized I forgot to put in U for Undo, which means I actually showed you 17 commands. I just didn't even remember it myself, I know fun times for everybody.

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