Pareto meets Vim

2 minute read Published:

It was at the JSDayES conference at Madrid where substack (James Halliday) coded on the stage of the big auditorium. The lines and words were changing quicker than I was used to. He wasn’t editing code character-by-character. Whole statements, lines, and blocks were moving around. Editing code like that looked magical to me. We weren’t watching a recording. It was Vim that was the secret sauce. How does one become a Vim wizard without being intimidated by the superpowers?

Firstly, we’ll define our objective. What do we need to learn? Having Vim documentation stare at us can be overwhelming. Pareto noticed roughly 80% of consequences come from 20% of causes. We don’t need to remember everything. We merely need to learn a tiny fraction of Vim to edit code faster. There is no downside to not knowing a shortcut. We can always fall back to editing text by individual characters.

Which 20% are important? Understanding navigation between normal, insert, visual, and command modes is not optional. Insert mode is the one that most closely resembles an ordinary text editor. Familiarity with command mode to save a file and exit is helpful too. On top of this, we can start learning more shortcuts for productivity. Get familiar with Vim by watching Vim Tutorial by Ben Awad - YouTube to get an idea of how modes and shortcuts work.

Memorizing everything Ben did in the video is a bit much for most people. Place a a cheatsheet in front of your keyboard. Consult the cheatsheet while you code. You can either write your own or download one from the internet.

The last but not least is practice. You can either use vim directly or enable Vim shortcuts in the editor or IDE you’re already used to. Visual Studio Code users can install Vim extension. Many tutorials will go deep into settings you can customize. For now, you can ignore all of that. Users of JetBrains IDEs, including PhpStorm, IntelliJ, and PyCharm can install IdeaVim.

These are my 20%:

  • change (ci") or delete (di") text within a pair of quotes
  • select multiple lines in visual mode (V + arrows up/down)
  • change text until the end of the current line (C)
  • Undo (u)
  • Cut (x)
  • Paste before/after (P or p)
  • Copy (y)

Resources: