Vim is better

Spankin' new text editors (looking at you, Atom); they make us feel fancy, they make us feel progressive. Sometimes we even fool ourselves into thinking they make us more productive, even as we port all of the configuration from our previous text editor to a new one. That's silly as shit. Pick a text editor and take it to your grave.

Choose an editor, know it thoroughly, and use it for all editing tasks. If you use a single editor (or set of keybindings) across all text editing activities, you don’t have to stop and think to accomplish text manipulation: the necessary keystrokes will be a reflex. The editor will be an extension of your hand; the keys will sing as they slice their way through text and thought. That’s our goal.

The Pragmatic Programmer

If you’re interested in picking right, pick Vim… What’s that? You’re not convinced? Well, let me count only a few of the ways in which Vim trounces many other text editors and IDEs:

Longevity + Ubiquity = Reliability

Vim (Vi IMproved) was released in 1991. It builds upon the Vi text editor, which itself is an improvement over its precursor, ed. This lineage is battle-tested and reliable, to such a degree that Vi is installed on every *nix system that I have ever used. If you’re comfortable with Vim, you’ll feel comfortable with Vi. Never feel like your hands are cut off when working in a remote environment.

You’d be forgiven for assuming that Vim’s long history is an indicator that it might be going stale. However, the opposite is true. Vim continues to be improved, with new plugins and extensions being written and released all the time. There are even projects like NeoVim, which is an attempt to further ensure Vim’s longevity.

The longevity and ubiquity of Vim translate to reliability other text editors don’t possess. You can feel reasonably certain learning Vim won’t be a skillset that goes out of fashion, and that feels pretty good.

Open Source

Picking open source tools isn’t just a matter of preference. They often work better, due to the collaborative nature of open source software development, where many people can audit and improve the code. As a bonus, open source tools are often free.

Mode based editing

Mode based editing is the killer Vim feature. It allows for complex manipulations of text, usually with a few contextually concise commands, all accessible from the keyboard. This creates a paradigm where one can “edit text at the speed of thought”. Now, don’t misunderstand me; As a Vim user, I’m not typing a billion words per minute. When I’m working with text, I’m thinking about what I want to do instead of how I can do it. Once you get the hang of mode based editing, Vim commands become second-nature. Many are easily remembered with a mnemonic, like “Change inner word (ciw)”.

Most Vim users work primarily in three different modes, each one suited to different kinds of text editing tasks.

  • Normal mode: use for navigating and manipulating text
  • Insert mode: use for inserting text
  • Visual mode: use for selecting text

Insert and Visual mode are pretty solidly represented in most text editors. Normal mode, however… Normal mode is where Vim slays other editors. Rather than treat this article as a tutorial, where I show you how to use Normal mode (there are tons of those, I’ll instead say check, ch-check ch-check it out.

Operators

In Vim, Operators are things you’d like to do to text. Examples:

  • delete a line or character
  • changing a line or character
  • yank a line or character into a register or buffer

Motions

Motions are “commands that move the cursor”. Motion examples:

  • move 2 words right
  • move to the last paragraph
  • go to the closing parentheses

Text Objects

Text objects are chunks or groups of characters. Text object examples:

  • a word, and the whitespace around it
  • a paragraph, without whitespace
  • the body of a function

So, big deal, right? Well, Vim excels at combining these stupid simple concepts in extremely powerful ways. Let’s say I want to change the body of a paragraph, and get dropped immediately into Insert mode. That’s a very simple task if I combine the change operator with the text object inner paragraph: cip

Howzabout I want to delete the next two words without having to hit the delete key over each character in each word. Again, easy peaze if I combine a count of 2 with the delete operator and the motion to start of next word: 2dw

The above examples should simply illustrate that Vim is all about combining small things into large things, about building relationships between different commands. You may recognize this as adherent to Unix philosophy. A good way to remember this pattern is: {count}{operator}{text object or motion}

Learning Vim

Using Vim is not as hard as you’ve been told. Its learning curve has been exaggerated. However, new Vim users often struggle with configuring Vim. You can get around this problem on easy-mode by using Janus, which is a distribution of plugins and configuration put together by Yehuda Katz. If you’re interested in my Vim setup, I keep it at GitHub. Additionally, there are many resources for learning Vim, a few of which are:

If you don’t get the swing of Vim right out of the gate, remember:

Originally published on the Aten blog