back to notes

Why Vim?

From the original on Reddit


TL;DR: If you don't use Vim, do not read this post. Or if you read it, do not believe it. Keep using what you enjoy using now. Do not go down the Vim rabbit hole.

Vim is a disease. I know this, for I suffer from it. It is a mind-altering ailment that permanently rewrites your concept of text editing, preventing you from ever thinking in the way you used to. When you're infected with Vim, all other modes of editing text become deeply unsatisfactory to you. Other editors will look like tricycles to you. Even worse, you will find endless frustration in being unable to explain Vim to someone that isn't already infected themselves.

I'm a dev team leader, and I do not push Vim on my junior members, for that should be criminalized. Two things can happen when you try to learn Vim: either you fail to master it, in which case it was wasted time, or you succeed, in which case you can never go back, even if you want to.

So, what is so great infectious about Vim?

1. Modal editing

Most editors are in a perpetual if you start typing now, what you type will appear on the screen mode. This is insert mode in Vim, and it is not the default mode. Vim users will switch in and out of this mode to type. But the rest of the time, they are in other modes, usually one called normal mode.

What is normal mode? When in normal mode, letters you type will not be text entered on the screen, but rather they are commands. It's like your entire keyboard has become a command panel for manipulating the text in many complex ways, rather than editing the text character-by-character.

Lest you think normal mode is something that just gets used here and there: Vim users will spend most of their time in normal mode. They will enter insert mode to type text, and then immediately exit insert mode. It's that fundamental to the Vim experience.

Visual and Visual Block mode also exist for selecting areas of text in order to perform actions upon them.

2. Text objects and editing commands

Normal mode wouldn't make much sense on its own, if the act of editing text was a character-by-character action like it usually is. One of the core things about Vim is that the single character ceases to be the only fundamental object in text editing. Vim elevates words, sentences, lines and paragraphs into first-class objects.

Text objects are important because the facilitate actions being performed upon them.

Part of why Vim is hard to explain is that any single editing command is usually not all that impressive upon its own. If I have the text:

"something in quotes"

... and I want to replace what's inside quotes, I can use the editing command ci" (mnemonic: "change inside quote"), which will wipe out the text inside that quote, and put me into Insert mode to type new text.

By itself, that's not very impressive. Sure, it's faster than using the mouse to highlight the text and hit the Delete key, but it's not that much faster. What you have to understand is:

  1. Everything becomes a fast, streamlined text edit command like this. This is a tiny example, and here's some more small examples but every common edit action you'd take can be boiled down into a snappy command like this, and...
  2. The edit actions can become very complex. An individual command, like the one I demonstrated, is a tiny thing. But these commands are meant to be composed together into much bigger operations. Much like how programming itself can take complicated manual tasks and turn them into simple repeatable routines, complicated manual editing tasks can be turned into simple repeatable Vim actions.

Why this is useful is hard to explain. It's kind of one of those "nobody can be told what the Matrix is" sorts of things. You don't really get it until you fully experience it yourself. Vim users often describe the act of editing text in Vim as feeling like you're programming text, rather than just editing it.

3. UNIX is your IDE

If you are using Vim in a GUI window, I would argue that you're only half using Vim. Vim is really the editor part of an IDE, and that IDE is the UNIX base system. It is a tool you use in conjunction with UNIX utilities in order to manipulate text. You can pipe a buffer of text into a UNIX tool, and have the transformed text returned to your buffer. This isn't just possible, it is idiomatic. Likewise, your "project browser" is your UNIX shell itself. Particularly when paired with a terminal multiplexer like tmux, Vim and UNIX make for a complete, portable, language-agnostic development environment.

4. Vim springs eternal

As I said in another comment: Vim was here before your IDE. Vim will be here after your IDE is long gone. Vim will outlast your job, your career, your marriage, your life.

Learning Vim means you learn an environment that you can (and, once the disease sets in, will) use for the rest of your career. Long after everything else you know has gone to dust, Vim will be there. Some version of Vim will be running on whatever computer triggers armageddon.

5. Vim is composable

Vim is far from the only editor with plugins. But while most editors have a larger "out of the box" footprint and a smaller amount to which they can be configured and overridden, core Vim is a very small, tight package, upon which you build the editing environment you want with a very deep and powerful level of customization. Vim is a core around which you build your personal editor.

6. Vim operates at the speed of thought

People talk about Vim saving keystrokes and mockingly comment on how that will add up to entire seconds of time saved. It is correct that the value of efficient editing is not best measured in time saved. But what should be familiar to programmers is reducing the interruption of thought. We programmers have plenty of rants and comics about the pain of even brief interruptions of our thought processes. Well, what you don't realize until fully down the Vim rabbit hole is how you are putting up with thought-interrupting manual editing actions that become streamlined into oblivion in a Vim environment (and thus, those tasks you didn't think twice about before are completely intolerable to you now).

7. Even more crazy stuff than I know

I'm still falling down the hole. Years into my fall, I am still finding Vim features which are entirely new to me, which further impact my ability to manipulate a text buffer in new and efficient ways. If it's conceivable, someone has probably already thought of it and made it possible in Vim. Much like Zombo.com, the limit is your own imagination.

TL;DR #2: Look, I said to stay away. It's a bit like Operation: Mindcrime. Don't ever trust the Vim needle, it lies.

Coda: Some of this post uses a bit of exaggeration for humorous effect. This is /r/ProgrammerHumor after all. So don't pick any of the hyperbole apart in comments, please.



last updated october 2018