Some Background
Our fall quarter ended a few weeks ago, and one of the courses I took was CS 32 (object-oriented programming in C++). This course and its prerequisite (data structures and algorithms) did not count towards my EE degree, but I took them nonetheless. I wanted to have a strong foundation in C++ since this helps greatly with embedded programming. Also, the professor, Kevin Burk, is one of my favorites.
The entirety of CS 32 was just two large projects, each lasting half the quarter. We had to work in groups – the goal was to learn to collaborate on large coding projects as one would do in a software job. As a result, I noticed the following:
- People are scared of Vim; they do everything they possibly can to avoid using it. When working on their own laptops, they can easily use VS Code. When forced to work on a school computer, they either use Vim entirely in insert mode – navigating with the arrow keys only – or they use the Debian equivalent of Notepad on Windows.
- People are slow at writing code. That is, their brains are thinking much faster than they are able to type. This should never be the case. The speed of your progress should not be bottlenecked by your text editor.
Why Vim?
The greatest slowdowns while writing code in a standard text editor come from moving your hands back and forth between the keyboard and the mouse/trackpad. Suppose you switch back and forth twice a minute, and each motion takes half a second (four total motions per minute). Now say you are working on a large project and have spent ten hours coding. You would’ve spent 20 minutes moving your hands back and forth!
Vim eliminates this, pretty much entirely. If you utilize its features effectively, you will essentially never need to take your hands off the keyboard.
There are alternatives to Vim, but over the years, Vim has held up the best and remains widely available. There are also modern text editors with primarily visual features that do indeed speed things up, but the speed improvements don’t compare to what Vim can offer.
I am not suggesting that you do everything in the terminal. Editors like VS Code make compiling and debugging much easier than using command-line tools. But when it comes to literally typing your code, nothing beats Vim. (By the way, there is a Vim VS Code extension that I use extensively.)
How to Learn Vim
Learning Vim is not easy. The learning curve is very steep, and it takes a lot of time and patience until you can truly reap the speed benefits of using Vim. Persistence is absolutely the key.
Begin by running vimtutor
in the terminal; it should come with your installation of Vim. Do not go through the entire thing all at once! Work through a few sections per day, then stop and work on a real project in Vim. Try to apply what you learned. This will help ingrain the commands into your mind such that they become second nature. As you learn more, you will find yourself recognizing the fastest ways to do the actions you need to do most often.
Continue this until you are familiar with everything vimtutor
has to teach you. Keep in mind that there can be multiple ways to do the same thing; in such cases, I recommend choosing your favorite way and ignoring the others.
Finally, check out my list of useful Vim commands. It’s based on this list, but I removed what I feel is redundant or not particularly useful. I also added some commands I use often.
Final Notes
Frankly, learning Vim won’t be fun. You will probably want to give up several times throughout the process. That’s what it was like for me, but with some encouragement, I stuck with it. I am very glad I did. Persist through the steep learning curve, and over the years you will be rewarded with hundreds of hours of saved time.