Master Vim - Learn how to go from Vim beginner to expert faster (11:27)
Videos can also be accessed from our Vim Reference Playlist on YouTube.
In the end, our goal is for the text editor to be an extension of our brain, meaning we want to get ideas out of our head and translated to code in a text file as fast as possible. So we want speed and Vim was designed for speed.
It's important to understand where we each are starting from so we can set realistic expectations and develop a plan to increase our speed.
Of course if you think about it, Vim can only do part of the work here. So let's address five limitations to fast editing and what Vim can and cannot do to help.
First is how quickly you interpret code with a programming language. So for example when creating web pages in HTML, what do the tags, labels, indentation, markup, CSS and all of those reserved characters mean? And how do we create a text file to make the web page look the way we want?
A quality text editor like Vim can help with syntax highlighting and colors to identify incomplete lines or errors. In other FactorPad videos and web pages we cover how to customize Vim to help with this. But at the same time Vim cannot help with how well you know the language itself.
Second, typing speed is a factor. The average person types around 200 characters per minute and the professional types maybe 400. But again, for the most part Vim cannot help you here. You either type fast or you don't. So that is something you can work on independently as part of your plan. An important point to keep in mind on this, keeping your hands on the home row and not looking at them will result in faster typing.
Third is navigation. How quickly can you move around in a text file?
Here is where Vim can help. Most beginning Vim users who are
comfortable in a GUI, or graphical user interface, struggle as
they shift from mouse and arrow key navigation to using Vim
navigation using the
Because the keys sit on the home row, your hands don't have to travel
as far. Later I will discuss several of our resources to help you here.
Fourth, common tasks are communicated to Vim using keystroke commands instead of time-wasting menus and dialog boxes common in other editors. So with only 1 to 4 keystrokes you can quickly perform tasks like searching files, selecting and replacing text or even combining files together. The exploration of these commands is a big part of what FactorPad's Vim Reference is all about, and why it is delivered in both video and web page formats.
Fifth, and beyond the scope for most beginners, is the concept of automation or macros or custom commands designed to automate commonly performed tasks. So not only is Vim fast while you are editing, it can do many things behind the scenes. We will further explore this conversation later.
Now that we have our expectations set and we have a feel for what we need to work on, let's talk about the basics.
To get started, we need to know enough to be dangerous, meaning, we need to understand how to do basic tasks so we can make Vim our primary editor. Tasks such as copying, pasting, navigating, searching and saving are essential. Because Vim is a modal editor it is different from what many beginners are used to. So learning the basics is often a difficult task. Difficult enough that many people try, struggle and quit.
It doesn't have to be difficult if you focus on nailing the basics first and waiting until later to add complexity. Vim has a long list of commands. If you combine the different modes and all of the possible keystroke combinations, you might easily have over 1,000 possible commands. However, all it takes is about 75 Vim commands and you will be able to do almost everything you need to get started.
The next challenge is how to learn these commands.
Many new programmers are baffled by how experienced coders memorize so many commands and keystrokes without using menus to jog their memory.
To be honest, most programmers do not have photographic memories and instead rely on notes, books and cheat sheets. Whether created themselves, purchased or found on the Internet, the key is to find one suited for your level. Many cheat sheets, especially those in pdf format with multiple colors and depictions of a keyboard are too complicated and frankly confuse and inundate beginners with too much information they have not seen yet.
I was not happy with the alternatives I saw, and frankly found them worthless, so I created a freely accessible Vim Cheat Sheet that is boiled down to 75 essential commands to get a beginner started. I also supplemented it with commentary, because it is important to know why things work as they do, especially at the beginner level when everything is so new.
Also, a helpful cheat sheet in Vim must address navigating and understanding modes, because it is through them that all future commands become easier to learn.
So whether it is this cheat sheet, another one you find, or one you create for yourself, bookmark it and use it frequently to jog your memory. Don't beat yourself up and think of it as cheating. All programmers do it because there is just too much to memorize.
Next, you need to start editing text files with Vim and commit to it. Over time your frustration level will drop and your productivity level will increase.
When I started with Vim, I forced myself to learn Vim by transitioning from a word processor to Vim. So every time I would normally reach for Microsoft Word, instead I opened Vim and created an HTML file that when viewed through a browser looked like the end product from a word processor. Of course this was not easy. I was much slower at first, but the exercise was very valuable because it forced me to both learn Vim commands and keystrokes plus reinforce HTML at the same time.
This multi-tasking resulted in a fairly vast factorpad.com website filled with free and helpful educational resources in not only Vim, but also Linux, Python and even financial modeling in Excel.
And with practice, ingraining these keystrokes into the involuntary part of your memory is what will lead to faster speed, and less frustration.
With the basics covered, you will need to practice and using a game to reinforce navigation keys is a good way to keep it light and fun.
A maze game is a perfect way to do that. You don't have to use ours,
but it is here if you would like a free playground to practice. It is
called the Vimazing
Race - hjkl Edition. Here you take 417 steps through a maze
from start to finish using just
k (up) and
and the penalty for an error is
returning to the starting line. Try that a few times, put yourself on
the clock and after some time you will have mastered the
hjkl keys and
will be ready for more advanced Vim navigation.
And finally, challenge yourself to improve. Vim experts are constantly on the lookout for new ways to do things in fewer and fewer keystrokes.
To help on this front, keep your eyes on our reference for Vim. As it grows we will continue to add new tips and insights.
So now you have a plan to master Vim by setting realistic expectations, nailing the basics, finding resources, committing to it and by challenging yourself to improve.
Best of luck and welcome to faster editing with Vim.
Q: What other resources are helpful?
A: If you are just starting out, the vimtutor program that comes with most distributions of Vim is helpful. In about 25 minutes you will get an introduction to many of the features of Vim.
Find more free resources for learning Vim at our YouTube Channel. Subscribe straight from here.