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 see our video player troubleshooting guide to resolve the issue.

Easy Improvements: Syntax Highlighting & Line Numbers

00:00 Before, we’ve seen VIM in its bare-bones version, and in this video, I wanted to show you some very easy improvements that you can run on any installation of VIM and that already come with the editor. They’re going to make life much easier and more colorful.

00:14 We’ll look at syntax highlighting and line numbers, specifically. Back over here in our little script, you can see at the moment, again, I’m in INSERT mode, so now is the time when we want to switch to command mode because we actually want to execute a command, instead of typing something into the text here.

00:32 So I will press Escape, switch to command mode, and press the colon (:) that tells us, “Start a command,” and now I can say, for example, :syntax on.

00:46 Oops, I mistyped here, so let’s do that again. :syntax on—there you go. And we can see here that now syntax highlighting is switched on. This is already much easier to look at, especially when you’re in a big file.

00:59 Now we can easier read what’s going on. We see that here we have a function that we’re using, those are reserved keywords. You can see here, there’s a variable, and integers are highlighted in red.

01:10 And again, obviously you can change a lot of this stuff—it’s very editable—but this is the default syntax highlighting that VIM already comes with and that you can simply switch on using this :syntax on. Switching it off again also works as expected. You can say :syntax—gotta type it right—off.

01:27 And then we’re back to plain white on black, in this case, right? Okay, I’ll switch it back on.

01:37 And now we want to do a second improvement—we want to add the line numbers. Again, for our little script this is not as important, but imagine you have a bigger file.

01:46 It can be very difficult to know what’s going on without those line numbers. So if you say :set number,

01:55 then you see on the left side here, we have line numbers popping up, and that can be helpful because VIM gives you a lot of freedom for navigating. You can navigate to a specific line number very quickly.

02:05 We’ll look at it a bit later, but yeah, just so you know, there’s these two commands. If you remember these two commands—that is, :syntax on and :set numberyou can already have a much nicer experience with VIM.

02:18 And let’s actually take a look at that in a bigger file.

02:38 So here, I will open up a bigger file and just show you how much nicer it looks if we switch on those two features that we just talked about. This is just a Django settings file. You can see how it looks like right now—it’s a long, long file, and everything is just black and white, so it’s a bit difficult to know what’s going on. However, with these two improvements that we just talked about…

03:01 :syntax on, you can see it looks like that, easier to read. And the second one,

03:11 :set number, switches on the line numbers, and now we can see all of this going on here. Much easier to navigate. So yeah! Remember there’s two commands and you’ll have a better VIM experience already pretty easily.

gdwl on Feb. 27, 2020

Just thought I would point out that many installations of vim come with only the stripped down vim-tiny version. This does not support syntax highlighting, so users will have to install a full version. So if anyone finds it’s not working as expected that may well be the reason.

Martin Breuss RP Team on Feb. 28, 2020

Thanks for the tip @gdwl, that’s good to know! So in case anyone runs into that issue, you can download vim here.

fire9 on April 4, 2020

@gdwl You can use brew install vim if your computer is Mac OS system.

Become a Member to join the conversation.