Lesson 4 of 26

Syntax Highlighting and Numbering in .vimrc file

Duration: 2:41 Watch on YouTube (external link, opens in new tab)

Markdown version

In this lesson

Working on a new index.html file, Roy turns on Vim's built-in syntax highlighting with syntax enable and line numbers with set number. Because these settings are lost when Vim is reopened, he creates a vimrc file in his home folder with both commands so that they load by default. He ends by pointing ahead to color schemes and the .vim directory.

Transcript

369 words

[00:07] (external link, opens in new tab) Okay, let's look at some basic configurations we can do to Vim so we can actually make it a bit more usable. Let me create a simple HTML file. And I'm going to say Vim index.html. Even though the file doesn't exist yet, it's going to get created once I save it. I'm just going to paste in some very boilerplate HTML stuff. Press escape and write. So, command write. And what you can see first of all is this.

[00:38] (external link, opens in new tab) This looks like crap because there's no syntax highlighting. So, we can enable syntax highlighting which is built into Vim for many file types already. I can say command syntax. I can press tab to see that there's a bunch of commands. tab syntax enable. If I type that, we can see that we have syntax outing. That's pretty cool. What about line numbers? Maybe I can set that. So, I can say set command set numbers

[01:12] (external link, opens in new tab) Number. Sorry, you can see that we have command line numbers in the command line. So I can move up and I can see the various line numbers that I have. And if I press right quick command right quit. So command wq. If I try to open the index html again, you see that we have an issue is that those settings were not saved. So how do we save those settings for later? The answer is that we can create a vimrc file.

[01:46] (external link, opens in new tab) And the way we do that is we can say vim home that's your home folder and create a vimrc file. So if it doesn't exist yet. So I'm going to create it and I'm going to save it. And we can put the commands we just put in inside the vimrc file. So for example syntax enable that's one command and set number. So that's the other escape command write quit.

[02:19] (external link, opens in new tab) And if I try to open my index html again, where is it? Vim index.html. We see that we have the default configuration. So that's a good start. Next we're going to see how we can set color schemes and the purpose of the .vim directory, how it relates to plugins and other cool things.