Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Useful Vim Commands

00:00 Welcome to the fifth video here in the section about VIM. And here, I want to show you some useful VIM commands. Now keep in mind, I’m not a VIM professional myself, and this video is not meant to take you to be VIM professional.

00:12 That’s actually quite a learning curve, and some people who go down that path, they become very quick and very functional using VIM, but I here just want to give you a little peek of what’s possible and show you some useful commands for navigating, as well as basic interactions with your code. So, heading over to this Django settings file, I’m going to stick with this one here because it makes a bit more sense to see it in a bigger file.

00:38 We have the syntax highlighting switched on from before, as well as we have the line numbers here. So now, I can show you some ways of navigating quickly in this file.

00:47 You can use the arrows to move around just as you would expect, but there’s quicker ways to get to where you want to be. So, for example, to get to the end of the file, you can just press Shift + G, the big G. It takes you all the way to the bottom of the file, wherever that is.

01:03 And pressing two small g’s—gg—jumps back up to the beginning of the file. So that’s, for example, two very quick ways of moving around. Or you can jump to the end of the line by pressing the dollar sign ($), that just brings you all the way to the end, or you can press the zero (0) to go to the beginning of the file.

01:21 I’m just quickly going over to them to show you that there’s all these quick ways of navigating if you know all the keyboard commands. Another way would be, for example, pressing g and the big A takes me all the way to the end of the file plus enters insert mode, so now I can start typing here right away.

01:39 Back in command mode. Another thing that we want to do frequently, for example, is to delete a line. That’s very easy in VIM, you press two times the small d, dd. It just deletes the line.

01:50 I can undo this, pressing the u character, and here it is again. Let’s jump back to the beginning. Okay. And up here, I can copy this line, for example. In VIM that’s called yanking, so it’s a double y.

02:05 Now I’ve copied it and using p I can just paste it down below. There’s this file again. Again, I will undo this,

02:13 just pressing a simple single key. So, you can see here that that’s where the power of VIM comes in and where people who took the time to actually learn all of these many, many commands that exist—they can excel at this, because you don’t have to move your hands off your keyboard at all and you can do lots and lots of stuff very quickly.

02:33 Let me show you two more things. We’ve switched on these line numbers before, on the side. One thing that’s useful for this is that in command mode I can, for example, go to a specific line by just typing the line number, and it takes me there.

02:45 And now I could go to the end of the line and go into insert mode and I could start typing there. Even better if you know a certain place where you want to go to—let’s say I want to go to DATABASES here, right? But I’m somewhere else in the document. I can search for it in VIM using the / key.

03:05 So I can say /DATA—oops.

03:10 And it takes me to a where it finds DATABASES. This searches through the whole file. Let’s go to /templates,

03:17 and it takes me to the first time where it finds templates. Okay, so enough about those commands. I’m sure you’re not going to remember all of these commands that I typed here, and I’m going to tell you that there’s tons and tons more of them that I don’t use very often, and that I probably don’t even know about. So with this, I just want to give you a quick peek into what’s possible with VIM if you become a power user. So if you really want to go into that, it’s all about the keyboard shortcuts.

03:42 So if you enjoy that and you’re good at remembering, then go ahead and make VIM your own, and I promise you people are going to be impressed, ha. All right, that’s it for this video. In the next video, we’re going to talk a little bit more about stuff you can do to get more professional using VIM. See you there!

Become a Member to join the conversation.