This course covers vimrc files, which allow you to define various presets so that your favorite settings and options are already set up in Vim when you start using it. You'll also learn how to configure vimrc files with customization such as color schemes. A guided exercise will give you a hands-on tutorial of using vimrc files and you can follow along to put your skills into practice.
This course is ideal for anyone who needs to edit text files in a command-line environment.
If you want to follow along with the exercises in this course, you should have the Vim text editor installed on your computer.
If you want to follow along with the exercise(s) in this course, you can find the necessary resources here.
The goal of this exercise is to create your own vimrc file with your own desired customizations. First start a command line session on your local machine. Next, use Vim to open the vimrc-samplefile that came in the course downloads. To do that and navigate to the location of the file. And remember that this could be different for you depending on where you extracted the contents of that file. This example assumes the course download was saved into your downloads folder and extracted from there. So I'm going to go to the Downloads folder, then vimclass, finally opened the vimrc-samplefile. The first thing I'd like for you to do is just look through the file and read the comments for each option along the way. For example, you can look at the ruler option in the comment above it says, "Show the line in column number of the cursor position." If the option sounds like something you might use or want in your configuration settings then read the related help documentation for the command. When getting help, remember to use single quotes around the option name so you're taken directly to the option documentation and not some other related help documentation. For example, to get more information about the ruler option you would type :h 'ruler' and hit Enter. If after reading the detailed description of the option and you wanna try it, then make sure to enable it with a set ruler command and I'll press Enter here and then you can see what that does. And I've already actually already had it set. And you can see in the bottom right hand corner my cursor position, which is at one comma one, the first line in the first column. To disable the option use set, no followed by the option name. So to turn off the ruler, we can use set noruler and press Enter. I'm just gonna type controlww.switchback to the lower window here and I'm going to go to the ruler option here. Let's say you decided you do not want to use this option. Well, in that case just comment it out. So I'm gonna do Shift I to start insert mode at the beginning of the line, type a double quote and a space and hit Escape. Now that option is in a comment, so it's not going to get executed. Every time I make a change like this it's pretty much a habit for me, I'm going to save my change with W to write the change to the file. I'm gonna leave it up to you to explore the other options on your own and then you can just use this same process. For example, you can get help on the 'showcmd' option and if you want to use it, you can. Or if you don't, you can comment it out. So I'm gonna close out the help with a Q here. Now, once you have this sample of vimrc file the way you want it, make sure to write your changes first and then next, what we're going to do is copy the contents of this file into a register so that we can later paste it into our own vimrc file. Now, I didn't wanna get into the specifics of each different operating system how you could copy a file for windows versus Linux, et cetera so we're just gonna do this all in Vim so it's gonna work for everybody. The first thing I wanna do here is just position my cursor at the very beginning of the line with gg, now I'm just going to use the V register. I like to think that it stands for vimrc and then I'm gonna yank the entire contents of the file. So I'm gonna do double quote V Y and I'm gonna yank the capital G motion. So you can see that 86 lines were yanked. Now, what we wanna do is open our vimrc file and we're gonna do that with a colon E or colon edit command. Now, if you're working on Mac, Linux or Unix the name of your vimrc file is actually .vimrc or periodvimrc. If you're working on a window system then it's _vimrc. So here I'm on a Linux system so I'm gonna use colon E to edit. Tilda which represents my home directory or the current user's home directory a forward slash which is a directory separator .vimrc again, because I'm on Linux, but if you were on windows, you would use _vimrc I'm gonna back that up here and do .vimrc and hit Enter. Now we're editing our own vimrc file. So what I'm gonna do is paste the contents of the V register into this file. So I'm gonna do double quote V Shift P to put that above my cursor position. You could also use double quote V lowercase P but then you'll just have a blank line at the top of the file, no big deal either way. So now, since I have this baseline configuration I'm gonna hit colon W2 write changes to my vimrc file. I'm gonna go to the end of the file here with Shift G and you see a line down at the bottom of the file that says, "For more options see" "help option list" and the "options" command. So you can use those commands. I'll just do this here, "option lists", and you can go through all of these options if you'd like and customize Vim to however you want it to be. I'm gonna close out this window with Q. You can also use the "options" command. At the top of the screen here, I'll give you instructions on how to use this option command. When you're done you can just hit Q to close out of that window, when you're done customizing your vimrc file just write and quit your changes. WQ exclamation mark and Enter.
Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.