Learning Vim
Some shortcuts for your journey
This will mostly be useful for the programmers among you.
I recently got to the point where using Vim became actively useful instead of slowing down work.
Even though I was somewhat strategic about how I went about learning it, I think I could have done it faster.
This is a collection of the things I would tell myself if I started over.
Disclaimer: If you follow the steps below, you will spend some money to learn Vim. There is one software and one book recommended. I believe this is the fastest way and worth the investment. Judge for yourself.
Use the right keyboard layout
People often struggle with symbol-based shortcuts, because they use a keyboard layout that differs from the one the tools were created for.
If you are a programmer you absolutely should get a US keyboard layout.
This is a bit of an adjustment, but if you type symbols like[,{,;then your future self will thank you later.Remap
Caps LocktoEsc. You press a lot ofEscwhen using Vim. Vi — the predecessor of Vim — was created in 1976 for the Lear-Siegler ADM-3A terminal.
On this terminal, theEsckey was positioned where theTabkey is today.
No wonder people find usingEscfor Vim annoying!
Get familiar with the basic motions
This is what everyone tells you. They are right.
What people don’t tell you is how to master them fast.
I believe the fastest way is using Vim Adventures. It is a browser-based game that teaches you the basics. You can also go beyond the basics, but I found the game to have diminishing returns after about level 10.
Jump around faster
One of my main roadblocks was navigating in code quickly.
In the beginning, I mostly moved using h, j, k, l. These all move the cursor by one position in different directions. You get used to this rather quickly.
Other Vim motions (which you will learn using Vim Adventures) start becoming useful rather quickly. Therefore, learning them feels productive early on.
Navigation, however, took me surprisingly long to master.
Here is how you get there:
Use
{and}to jump up and down whole paragraphs, respectively → This alone got my navigation to the point where it felt productive. Remarkably, I have not seen it presented as one of the basics in any tutorials.In Normal Mode use the
:<line_number>command to go to a certain line. You can also use<line_number>G, but the first one translates much better into e.g. VSCode. This navigation method is particularly useful for debugging code. Error messages typically include the line of code that caused the error.Use Vim’s search functionality
/<your_search_query>liberally. Then jump to the next/prior search matches usingnandN, respectively.
That’s it. These three will be more than enough for the beginning.
Set up a basic .vimrc
Your .vimrc is the file that contains the “settings” for vim.
It can typically be found in ~/.vimrc.
Don’t copy your .vimrc from anybody else!
Later on in your journey, it can be interesting to browse other people’s configurations. Doing so from the start, however, makes your configuration really bloated. Copying your configuration also makes you hesitant to change it because you don’t fully understand what is going on.
Instead, use it to eliminate stuff that annoys you about using Vim. Do so bit by bit.
Most annoying stuff can be improved easily! By building it slowly over time you will learn Vim in a deeper way and truly own your setup.
Read “Practical Vim” by Drew Neil
This is the best Vim book I could find.
It starts with the basics, but includes all the advanced things you should know.
Don’t stress about remembering everything. Instead, pick the things for which you see immediate utility and use them as often as possible.
Here are some useful things I took away from it:
You should not duplicate code (the DRY principle). Similarly, you should not repeat motions/commands in Vim. Instead, perform an edit once and then press
.to repeat the edit. You should work in a way in which pressing.occurs often.Commands like
daw(delete a word),vi{(select everything within the curly braces), oryi[(copy all the content within the square brackets) all follow the same format.ameans “include the curly braces, square brackets, or whatever your block delimiter is” whereasimeans “don’t include the block delimiter”. Another useful command in this family isdaawhich translates to “delete this argument (and the comma that separates it from other arguments). It is used in a function signature.
There is much more. Reading it is worth it.
Wrapping Up
That’s it. Surprised? You probably expected a long and complicated post about the intricacies of Vim’s macros and the best secret configuration hacks.
There might be a post on configuration in the future, but not today.
Today, we keep it simple. There is little value in overloading you with complexity. I hope there is some in giving you a roadmap.
Vim is supposed to support you in your daily work. It should make your life easier, not harder. As with most powerful tools, this requires a little investment on your part. I believe the above represents the minimum effort required to reap the rewards.
Have fun on your journey!


