VIM Fundamentals Opening vim & Editing Basics
Transcript from the "Opening vim & Editing Basics" Lesson
>> Awesome. All right, so there's gonna be a bunch of curled files that we'll need to get from time to time. So just be prepared. I will be linking them in the chat. Hopefully if, you're following along, you can just copy and paste from here. It's how we will go into them and do the same thing together.
[00:00:16] As I've said it before we're gonna start when Adam and Eve were going from like the very, very, very beginning and we gonna slowly build a foundation that makes sense. We gonna edit the files together. We gonna walk through them together and we gonna hopefully get to the end.
[00:00:29] And as I've said earlier, motions where my chief most important when I learned how to do it because I was using a plugin inside of intelligent. Today, those will be kind of the same level of importance as other features of VIM such as file navigation, being able to do certain sets of actions, macros, registers, quick fix lists, you name it, we're gonna kind of go through the whole gamut here today.
[00:00:50] So let's open vim, go to your terminal and just type in v i m and hit enter. Alright, so now what are you supposed to do? For a lot of people the first time you open this, you're just like, well, that's fun. Lots of WTF, lots of, well, that's fun, but I have no idea what I'm actually doing here.
[00:01:14] I don't even know how to use this. I don't even know how to do anything. It's telling me to type all these things to be able to go find stuff, and I'm like, okay, check health. Can i do push ups? My goodness, i have all these like, warnings and stuff.
[00:01:25] How am i going to errors and just feels like i don't even know what I'm doing now everything's gone all of a sudden. It just feels weird, right? Like, this is why when people open up vim for the first time they generate Sha 256 codes. It's because you just start jamming the keyboard until something happens, so let's quit.
[00:01:43] By the way, I didn't show you how to quit, press. Okay. Hey, Chuck. Hey, don't tell anyone. Okay, this is kind of a secret. Don't tell anyone. It's going to be this :q. Hit enter. When you do that you will leave in. If that doesn't work for you try the bathtub.
[00:02:01] Just get it out, right. It's, this is such a meme. I came and believe it's such a meme, but every single day you'll see someone not being able to exit vim. And it's like hilarious. There was recently a guy with a Mac book pro with the touch bar and his escape key quit working.
[00:02:17] And then he goes like permanently stuck in vim. He had no idea what to do. And this was just a couple of weeks ago. It was fantastic. He wasn't technically stuck in vim, he just didn't know how to escape. Anyways, so if we could get a quick crowd participation moment I know everyone just left but I can always jump over to the chat.
[00:02:33] What were you expecting to see when you open up vim? Does anyone have anything? Anyone from the zoom class? What were you expecting to see, when you typed in v-i-m?
>> An empty document.
>> An empty document? Okay. I bet a lot of people wanted to see a file tree, right?
[00:02:51] Was it weird not seeing that? When you open up VS code, you see a file tree you feel a little bit safer. You see something on the side that kind of orient you to where you're at. You got nothing right? And it felt confusing. Someone's had an empty screen from chat line numbers.
[00:03:08] Yeah, maybe line numbers, maybe something, just anything but it feels super disorienting when you see nothing you're familiar with. That's gonna be a pretty regular occurrence for a while. Okay? We'll try to make it better, but in the end, it's gonna be pretty regular. Al right, so let's move on.
[00:03:27] Let's actually use vim this time. All right, I hope everyone's ready. So remember, we're going to do the basic movements and all that here in a little bit. But I'm going to just kind of walk you through just doing your first edits. So let's all open up vim together and do vim test.js being an empty directory, it doesn't really matter.
[00:04:03] down here in the bottom. You do see test.js. Okay, at least we feel a little bit more oriented, but I see no line numbers, I see nothing else, it feels confusing. So let's just, write a for loop together. So I'm gonna start typing, f o r. Okay, why is that not working?
[00:04:20] What? We all just type f o r but now everything's confusing. Okay, open squirrely brace. My goodness, nothing's working. What's happening? That's because you were in the wrong mode. So when I type in f o r, you'll notice that like, it just nothing happens, right? Okay, we got something yay.
[00:04:39] Yeah, what just happened there? Here let me exit for a quick second. You need to go into insert mode. So everyone, press i. Now when you press I, what you'll see down here is insert mode. This is letting you know where you're at. So now, you know, you're in test.js, and you're insert mode, insert mode will for the most part act just like anything else.
[00:05:01] And by the way, I do use the Vortec. If you can't tell there's no ASDFs right here. It's all AOEUs. And so that might be a little bit different. So if you see me typing something weird, that's probably what's happening. So when you're in insert mode, you can freely type.
[00:05:17] One thing that won't work. So if I start typing, for, there's not usually that many semi-colons, I don't think. When I'm doing this and I press enter, it will obviously give me a big indent, now that's a tab. You don't want a tab as you were typing it you probably got a tab, I don't know if you want an eight space tab if you do I'm power to you, but I don't use that.
[00:05:41] I like four spaces. This feels odd. The colorings all wrong. But hey, at least an auto invented for me, right? So what happened if I use shift key and like move around with my arrows? It's not, okay. I don't man that feels funny, right? Like you can't highlight text.
[00:05:58] So what is this insert mode that just feels wrong, right? So let's jump back here and let's first talk a little bit about modes honestly for a second. So normal mode is where you edit text, you modify it with delete, and yanking and pasting in and putting it all over the place.
[00:06:18] Insert mode is where you type new text. So those are two different ones. And then there's another mode called visual mode. There actually should be another mode here, but for whatever reason, my GitHub Pages did not update I'll just mention it. So there probably is a couple missing items here.
[00:06:32] But there's visual mode. Visual mode is equivalent to you using your mouse and highlighting a section of text or using Ctrl and Shift and the arrow keys to highlight the text. And then you're able to yank it, delete it or perform operations on top of that highlighted region.
[00:06:49] So it's a lot like using your mouse. And so there's one more mode called command mode. When you're in normal mode and you press colon, you can execute a command. That's called command mode. We'll use that from time to time. But those are your basic modes. There's some other ones.
[00:07:04] Just don't worry about it. If thing if you get into a goofy mode and you don't really know what's happening, press escape. If that doesn't work, start doing colon q until you're out of them and then just jump right back in. You will learn how to get out of things a little bit better as time goes on.
[00:07:17] So, there we get we're in insert mode. So how do you get out of insert mode? You can press Escape, Escape will make your cursor go from that thin cursor if you're using Neo Vim. If you're using regular vim, I believe you'll have a thick cursor. You'll now notice that down here at the bottom, there's no more Insert right, that went away.
[00:07:35] You're now back into normal mode. This may not feel normal. But trust me, it's very normal. It's just really normal. Just accept it. So anyways, so now there's other ways you could actually get out of insert mode you can use control C you'll see me using that a bunch.
[00:07:51] Control C does have a small implication in a very specific use case that doesn't make it the same as escape, but we're not gonna probably even run into that today. There is also Ctrl+(, which will also leave insert mode. But for the most part either use escape Ctrl+C Ctrl+(, whichever one you want for today, whatever one feels the most comfortable, because we can change it and we'll change it to the way you want it to be here soon, just not at this moment.