Vim Help System
The course is part of this learning path
This brief course shows you around the Vim Help System with a view to helping you become self-sufficient when learning Vim, and so that you know where to go when you need help. We will also walk you through a guided demo to give you some practice and experience using the built-in Vim help system.
This course is ideal for anyone who uses Vim and wants to understand how to use the help system.
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.
Up until this point I've been teaching you about how Vim works, I've been showing you various commands, and you've been practicing what you've learned along the way. And there's a lot more of that to come. Again I'll teach and demonstrate and you'll do in practice. It's really a great and fun way to learn. Now, we're even going to continue that method in this lesson even though it's about documentation in the Vim help system. I know reading technical documentation can be totally boring and even slightly confusing at times. I wouldn't recommend that you learn how to use Vim by reading Vim's documentation alone. It's not a good strategy. However, I want to teach you how to use Vim's built-in help system so that you can be self-sufficient even beyond the end of this course. Also, I want you to know where to look when you have a question about a specific command. For example, if I introduce you to a command in the course but you wanna learn even more about it, then I want you to be able to go deeper on your own. Finally, even if you have an amazing memory, it's almost impossible to memorize absolutely positively everything. I want you to be able to quickly refer to the documentation to refresh your memory quickly. This lesson will show you how to do that while you're editing a file. This way you don't even have to stop what you're doing to get the help you need. Let's start this lesson out by opening up a terminal on your system and navigating to where you extracted the contents of the course download archive. For me, that's in my downloads folder and I'm going to start there. cd downloads cd vimclass, and now I'm going to open the file with Vim help.txt. As always, you can follow along with me now or wait for the practice exercise that's gonna follow, or you can even do both. Whatever suits your learning style best. Now let's get started with a Vim's help system. And to do that you just type colon and the word help and press enter. You'll see that your screen is divided into two windows. The top window contains the help documentation and your original file is in the bottom window. Vim's documentation is simply a series of text files. You can even see that the name of this file is help.txt. If you type control G, which I'll do now, you'll actually see where this file is located on your local system. You can navigate through this help file like you would any other file. For example, you can use J to go down a line, K to go up a line, et cetera. One of the first things this help file tells you, is how to quit out of help. It's as simple as closing a file so type colon q, press enter and the help window is closed, and you're right back to your file. What makes the help system really handy is that you can get help with a specific command by typing colon help followed by the command that you want information about. For example, if you want to learn more about the dd command we could type colon help dd and press enter. The help for the dd command says delete count lines into register x line wise. When you come across information enclosed in brackets in Vim documentation, know that it's optional. If we strip out the optional parts, we're left with delete lines linewise. And if you proceeded with a number which Vim calls a count, it will delete that many lines. For example, three dd will delete three lines. You haven't been introduced to registers yet, but you will learn all about them in an upcoming lesson, even though you've been using line-wise commands and character-wise commands, we haven't explicitly talked about that yet either, but we'll get to that in just a minute. In addition, to getting help with specific commands, you can ask for help on various subjects. For example, count, isn't a command in and of itself but if you wanted help on it, you would type colon, help count and press enter. Here in the documentation, you see that count is an optional number that may proceed a command to multiply or iterate that command. By the way, if you wanna go back to the previous section you are at use control-o. It's very similar to hitting the back button in a web browser. If you wanna jump forward, use control-i. I is right next to O on the keyboard. So pressing control-i brings us to the count documentation. Okay, so let's use control-o to jump back to the dd documentation. Let's say you want to know what is meant by linewise. Again, we could use colon help linewise and press enter. Here you'll see that if a command operates on an entire line it is considered to be a linewise command. If it operates on a character, it is considered to be a characterwise command. Simple enough but an important distinction for sure. So if you're looking at the documentation for a specific command and in its description it says that it's linewise, then you can know that command operates on an entire line. Again, let's go back with control-o. There is another way to navigate through the help file instead of typing colon help linewise enter, you can place your cursor under the word linewise and type control close bracket. So let's do that. I'll just do J to go down a line. I'll just hit W a couple of times here to put us at the word linewise and I'll hold down the control key and hit the closing bracket. Now, as you can see you've jumped a place right to the linewise documentation. Let's say you want some help on the q command. So we'll type colon, help, colon q and press enter. One thing I'd like to point out here is that colon q is the shorthand version of the quit command or colon quit. You'll notice that u, i, and t are surrounded in brackets, which as you already know, means that they are optional characters in the command. So if you want to be explicit, or if it's easier for you to remember, you can use colon quit. If you wanna be a little quicker, use colon q, they are the exact same commands. Again, anything in brackets in the Vim documentation is optional. Now get meta here and get some help on the help command itself. So we can type colon help, and press enter. Here you can see that even though we've been typing colon help, we can just as easily type colon h as the characters elp are optional and the help command as well. So let's try it out with colon h count press enter. And sure enough we are placed right at the count documentation. So colon h is a shortcut that works just as well. Now let's return to our previous position with control-o. The first sentence about the help command is open a window and display the help file in read-only mode. As I mentioned at the beginning of the lesson, when you start the help system, Vim opens up a new window. If you wanna keep the help window open while editing or navigating through your file, type control-w control-w. That's simply holding down the control key and pressing w twice. So I'll do that. Control key is down, w, w, and now you can see the cursor jumped to the window at the bottom of your screen, which is the file that you opened at the beginning of this lesson. Now that the cursor is back in your file, you can do whatever you want while referring to the above documentation. And if you wanna get back to the help window just use control-ww, it just flips back and forth. Again, hold down, control ww, back to the bottom window. Control ww, back to the help window. I wanna leave you with one more quick tip before we wrap up this short lesson about the Vim help system. Let's say you want to look at the documentation for a command but you're not quite sure what the entire command is. In this situation, you can use command line completion. And to do that, we'll type colon h, followed by the start of the command you're looking for, and then type control d. So if you were to type colon h space colon q, and then type control d, Vim will list all the commands that start with colon q. Here you can see colon q, colon qa, colon quit, colon qall, et cetera. What control d does is list the commands that match the pattern in front of the cursor. So if we were to add u to this, so it's colon h space colon qu and now type control d, it just lists the commands that start with qu like colon quit, colon quita, colon quote. Now, at this point, you see the list of commands here on your screen, and you could just simply type out the commands you're looking for and press enter and you're done. But there's another way you can do the same thing. You can actually press the tab key and it will cycle through all the available options. So if we hit tab q once, we'll see that it completes colon quit. If you hit tab again, it moves to the next matching command, and auto completes that. That command in this example is quita. We'll press tab again, it's colon quote, is the next one that matches. You know, tab again, is quitall, et cetera. Now, all you have to do is press enter to get help on that particular topic. And if you just keep pressing tab, it will wrap through all of your options. So I'll just go back to quit, press enter, and it brings up the documentation on the quit command. By the way with my configuration I have an option on called wild menu. When I press tab, the possible matches are shown just above the command line with the first match being highlighted. So let's look at this a little bit closer. So let's type colon h, wildm and press tab. You can see that the wild menu option is highlighted. Now, if we hit tab again, we'll see that wild mode is highlighted. Let's hit shift tab, which reverses the order and takes us back to the first match which is wild menu. I'll hit enter to bring up the documentation. Let's disable wild menu to show you what it looks like without this option on. And to do that, we'll just use colon set, no wild menu, and press enter. It doesn't look like anything happened, but let's try tab completion again. So we'll do colon h wildm, and press tab. Now it just performs the auto-complete on the command line but there is no menu above it. So we'll press tab again, and it moves to the next match. We can press shift tab to go back. So it works in the exact same way, but there's just no extra status bar above the matches highlighting them as you go. We'll get into how to save your options in a future lesson, but I wanted to quickly mention wild menu here because I didn't want you to get confused if you saw something different when I was demonstrating tab completion. So if you have that extra menu, just know wild menu is turned on in your environment, and if you don't, it's turned off and again, we'll get into how to save this permanently later. Now to get out of help, we can just type colon q and hit enter, and now we're back to our file, and we can edit here if we want, and if we're done, we'll just hit colon queue here as well. So colon queue to quit here as well. Well that my friend is a quick introduction to using the help system in Vim. Again, the goal here is to make you self-sufficient even after you complete this course, and by the we're nowhere near done. I want you to know exactly how to find the information you need, and how to use the help system as a quick reference when you need help or you need to look something up in the future.
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.