Those who know me won’t be surprised that I’m a big Vim fan. Unfortunately there’re still people out there who either think Vim is hard to use or say that Vim is for geeks only. Let me try to clarify a bit and tell you why that’s not the case.
Vim is not hard to use
Let’s begin by claiming “Vim is not hard to use”. At first we need to think about why someone declares something being difficult. In my opinion the reason is that someone is
- just not used to it or
- it’s incredible difficult to learn (lack of documentation, bad user interface, you name it).
The first argument might be the more important one: The average user started his computer career either with DOS or Windows, so using editors like edit.exe and notepad.exe was the usual business. You had (or have) the cursor and just type in characters. Easy!
The second argument, especially lack of documentation, comes to the table when you’re at least trying to learn a new program. When you’ve got a problem, you normally look it up in the docs, find your problem and answer and go on.
Back to Vim: Indeed you’re probably not used to it (hence you would already use it and would have never stopped doing so) and you think it’s difficult to learn. But that’s not true: Every single bit in Vim is well documented. You have several commands and tools that are just there to get you to the right point in the help pages. And not being used to something is really no argument to declare something as being hard to use.
Your editor is hard to use!
I’ve been using Vim for about 3 years now — and not just for programming, but whenever I’m about to write or edit text. And from that point of view, I tell you: Your editor is hard to use (except it’s vim, of course). Let’s talk about the why:
Computer programs are there to assist you in doing things, that means making your life easier and more comfortable. But in God’s name, how does an editor that has nearly zero features enhance your editing experience? I’m not (only) talking about notepad.exe here, that counts for editors like Scite, Notepad++, UltraEdit, Visual Studio etc. too.
You may argue that your editor has syntax highlighting. Good, but it doesn’t assist you with editing. You have folding. Doesn’t assist. You have tabs. Don’t assist. You have refactoring tools. Do assist, but may only work for specific programming languages. You have IDEs with SCM integration, database connections, debuggers and tons of other tools and add-ons: They do not assist you with editing, plus there’re the native tools that already do those jobs fine.
I admit that I’m flaming a lot up to here, but let’s make things clear for now: Your average editor is just bad (focus on editing!). And please be honest: What else than moving your cursor around a lot combined with Ctrl+arrow keys do you do in your editor?
What makes Vim different — and better
The most important thing with Vim is what also confuses the most people: Vim does not only wait for your keystrokes and write the proper characters down. Instead, and this is important, it waits for your commands. You tell Vim what to do, and it will be done. Of course this implies that you know what you’re doing.
Basically vim is divided into 3 major modes:
- Command mode (or ex mode): Nearly all keys on your keyboard are bound to an action that Vim executes. In addition you can perform : commands.
- Visual mode: For selecting text, with the power of Vim selectors.
- Insert mode: This is what you mostly have in all other editors: You type, Vim writes it down.
We could say that if you don’t care of Vim’s features, just enter insert mode by hitting the i key and start typing. But of course you don’t want to do that, because you want to learn how Vim works, and not how you can continue using other editor’s habits.
As this article is not a Vim tutorial, let’s get back to the principles: I told you in the headline what makes Vim better, and the separation into several modes is the basic and powerful idea. Isn’t it just more logical to tell the editor “Hey, delete the next 3 words!” or “That line I wrote is stupid, delete it and let me type a new one!”? Why should hitting backspace for 70 times be more intuitive (yeah, you can also do Shift+Home, then Delete)?
Some other examples to get you an idea: “Delete the next whole code block”, “Increment the number under the cursor”, “Insert some text at the same place in 10 rows”, “Delete the line under the cursor and paste it below the next one, thus swapping them”, “Find the next occurence of the word under the cursor”, …
Hopefully you’ve recognized the difference: You’re invoking commands, you tell the editor what to do. You are not just moving the cursor around and delete here, insert there, catch the mouse and click everywhere.
How do I get used to all those keystrokes?
Seriously that’s the most heard excuse of users who stop to use Vim after trying it for 2 minutes. Again, you need to get used to it, which implies learning how Vim works. Luckily you only need a few keystrokes to get you started in a good way.
The first thing you should do is the so called vimtutor, a tutorial-like Vim introduction that shows you the bare basics. Just run vimtutor (.exe) and read(!) the instructions. After that my personal suggestion is: Use Vim! Just don’t stop, else you’re not getting used to it.
Once you’ve conquered the magic boundary of frustration, you’ll get enlightened by the pure power. Sidenote: I needed 3-4 approaches until I’ve continued using Vim for all my editing tasks, just be patient.
Whenever you feel like “That must be easier to do!” open up the help and specify your keyword (by issuing :help in command mode), or use the mighty :helpgrep command which searches the help pages for a regular expression (e.g. :helpgrep *delete*).
Another very good source are the Vim tips. Several Vim users demonstrate quite useful commands and keystrokes that make life a lot easier. However, do not (I repeat, do not!) try to learn all possible keystrokes at once. It’s a common mistake Vim newbies do. Just learn/lookup what you need or what you think might be done in an easier way. Following this approach makes your Vim experience a step-by-step learning curve.
Throw away your old habits and try out Vim. From someone using it for several years just believe the fact that it’s worth it. Be patient and you will edit your texts and codes much more effective in the future.
But please do not say “Vim is hard to use” anymore. If you do it nevertheless, then you got frustrated because of your old habits. It’s okay, just wait 1-2 days and try it again.
And before you can say knife, you’ll start to use Vim’s keystrokes and commands intuitively. As soon as that happens, you’ll feel pure fun when editing text and you’ll recognize that you’re so much more productive. Promises!
Last, but not least: Do not use emacs. Great operating system, but lacks a good editor. Try out Debian GNU/Linux instead and use Vim. Have fun!