Vim is unlike any other editor. It gives users almost unlimited power over their text editor, but to the beginner all the powerful features can be intimidating. Many people joke about how it can be difficult to do simple things like just saving a file or exiting the program, and to an extent this is true. However, with a little patience and tenacity, anyone can learn Vim in about 30 minutes. After those 30 minutes, you should at least be able to get your text editing work done entirely in Vim, though it may take a couple weeks for you to feel completely comfortable.
It helps to approach Vim the same way you approach a new programming language. Don’t expect to be an expert right away, but it won’t take you long to start doing some amazing things even if you don’t fully understand how everything works. Even those who have been using Vim for 5+ years are still learning, and it is this depth of features that makes Vim so powerful. Even when you couldn’t imagine being more productive in another editor, you can still find ways to get more out of Vim.
One of my favorite aspects of Vim is the concept of motions. The concept of a motion is simple, it’s just the ways that you can move your cursor. While you can use your mouse with Vim, it is designed to work well without one. With only simple motions like up, down, left, and right, moving your cursor from one point in a file to another is tedious, but with more advanced motions, you can jump around a file with only a few keystrokes. Some of these include moving to the next word, sentence, paragraph, or to a matching punctuation.
Vim also has search motions so you can move your cursor to the next character or series of characters. This is extremely useful when you realize that you can apply motions to just about any action. Like if you want to delete a parameter, you can press ‘dt,’ (Delete everything up To the next comma). If you want to capitalize a word,you press ‘gUw’ (the action gU to capitalize and the word motion w).
Another great feature is that Vim commands are repeatable. So if you just used gUw to capitalize a word, you can then move to another word and just press period. This feature is a huge time saver when you need to do the same action over and over. The period is limited to a single action, but the concept scales to other features. If you want to create a more complicated repeatable command you can use macros to record a series of keystrokes and play them back again later. If this is something you want to be able to repeat tomorrow you can save it as a permanent key binding in your Vim configuration file.
Once you understand how Vim works and how to customize it, you can replace just about any feature that you like from another IDE. For instance, I write a lot of unit tests, and I find it very convenient to be able to run them directly from my editor without having to change context. I was able to do this by pulling in two external plugins, Vim-dispatch and current-func-info. I run my tests through Vim-dispatch because I find it very convenient to run my tests asynchronously, so that I can continue editing while the tests run in the background. I also like to run a single test at a time since running all the tests in a file can take a very long time. In order to run a single test, I needed to be able to easily pass the function name, and current-func-info makes it very easy to get the name of the function where my cursor is sitting. I find this extremely powerful because without ever moving my hands from the keyboard, I can make a change to the test and with only three keystrokes, I can kick off the test and see if it’s working.
Vim is designed to be programmable, so this sort of customization is actually quite simple. Vim makes it possible to customize every aspect to make every task as easy as possible. All the tedious text editing tasks can be simplified — saving you time so you can spend less time repeating tedious actions and more time writing code.