A Vim puff piece
Because code is a largely unseen feature of modern times, it's easy to forget that software engineers are quite literally building the digital world by hand. It's lost on most of us programmers when we log into our computers each morning that the task we undertake is not far removed from the tool and die makers of last century or the carpenters of many centuries before. The Romans built with stone; we build with code.
While most code is bug-prone and rapidly obsolete, well-built programs stand the test of time. The code that ran the Apollo Guidance Computer is the Great Pyramid of the digital age, along with programs such as 1K ZX81 chess, GNU Screen, and Emacs which surely compose some list of modern wonders of the world.
Much has changed since these programs were first written. The pioneering days of computing are over and computers have even started trying to write code themselves. Nonetheless, computers still rely on humans for instruction. The most basic work of the software engineer is writing these instructions. Whether punched on a card, configured with switches, or typed into a text editor, programmers must always end up writing some code. The world of tomorrow is built with text.
If we must build the world with text, we must use a proper text-making tool. In 2020, many programmers rightly make use of excellent, modern tools like VS Code and IntelliJ, which make previously error-laden tasks like global renames and refactors a breeze. These tools are here to stay, and for good reason. Every writer of software should consider them when selecting a tool for the job. However, one would be remiss to overlook a prestigious member of the old guard, one which each of these other editors pays homage to in the form of an optional editing mode. In all the Earth, there is hardly a more fit-for-purpose tool for creating text than Vim.
If you're already a proficient Vim user, rest assured that this post isn't a beginner's tutorial. I'll reserve that for the proper tutorial: vimtutor. To run vimtutor on a Mac or Linux system, simply open your terminal, enter "
vimtutor" in the prompt, and execute the command. Beginners will find Vim difficult at first,1 but persistence will repay a hundredfold to they who exert it.
This post is also not a history lesson on Vim. Much can be said about the origins of the program, and much already has been. Two-Bit History has an excellent article in that vein, if you care to read it.
A text-maker's tool
If you've heard of Vim before, you likely know that it's a modal editor. That is, it divides the task of creating text into parts: broad strokes and fine-tuning. Vim acknowledges something that most text editors ignore: the majority of text creation is editing, not writing.2 Text must be navigated, organized, re-organized, duplicated, and deleted far more often than purely written. Therefore, the first mode a Vim user finds themselves in is Normal mode.
That Vim begins in Normal mode is a microcosm of its aptness. To sum up the quality of Vim in a pithy Buzzfeed-esque listicle3 of benefits feels like an insult to the fundamental quality of the tool. It's a tool for making text, much in the same way that a felling axe is a tool for cutting down trees. An excellent felling axe does no disservice to a chainsaw, and, though a chainsaw makes faster work of large trees, many woodsmen still select an axe for its reliability, simplicity, maintainability, and relative ease of carry. Chainsaws haven't rendered axes irrelevant or useless, and neither have modern text editors rendered Vim a relic of history. The sheer benefits provided by Vim transcend any list I could write because the tool is simply appropriate for text editing. This is universally acknowledged. Even Emacs, Vim's older arch-rival, pays tribute to Vim, as many of its distributions ship with default Vim keybindings. This is high praise from an excellent program in its own right; Emacs is a better piece of software than Vim. But that's beside the point: Vim is the code-maker's felling axe.
Though Emacs is objectively better software than Vim4 (largely due to Emacs Lisp), Emacs isn't the same type of tool as Vim. A famous joke calls Emacs an excellent operating system but a lousy text editor. It's the kitchen-sink and a whole universe on top. It plays the perfect foil for Vim in the sense that Emacs is capable of myriad things while Vim excels at just one. Emacs lacks focus; Vim is purpose-built. I love Emacs; I write text in Vim.
Humor me for a moment. Open a terminal window, navigate to your home directory, create an empty text file called "vim-demo.txt", and execute "
vim ./vim-demo.txt" to open the file in Vim. Vim likely comes pre-installed if you're using MacOS or Linux. Windows users are on their own to figure things out. Once Vim is running, follow these steps:
- Press "
i" to enter Insert mode, the mode for writing text
- Type "
The Cubs are World Series champs"
- Press the
ESCkey to return to Normal mode
- Now, remaining in "normal" mode, press the following keys:
- Observe that "
The Cubs are World Series champs" has now become "
THE CUBS ARE WORLD SERIES CHAMPS"
Now, even if you're an experienced Vim user, you might only understand part of what we just did. Here's a breakdown:
gU --> make uppercase i --> inside s --> sentence
Make uppercase, inside, sentence. Uppercase, inside, sentence. Make uppercase from inside the sentence.
Why "inside", you ask? Because your cursor was inside the sentence. This means that Vim understands what a sentence is and how you want to edit it, which is more than most text editors can claim.
Hopefully you didn't close Vim yet, because I've got one more for you. No need to delete what we've written, and if you already did, just press "
u" until you're back in business.
- Ensure you're in Normal mode and then press "
yy" to "yank" (like copy, but better) the entire current line
- Press "
p" to paste the line you just yanked below the first one
- For fun, let's press "
b" a few times to go to the beginning of the previous word, and then "
w" to jump to the next word again until you're back where you started
- Now, press "
/" to enter a forward search (you can do a backward search with "
- In your forward search, type "
CH" followed by
Enterto send the cursor to the next instance of the word "CHAMPS"
- Press "
n" a few times to cycle forwards (next) through the matches from our search, and press "
N" to cycle backwards
- Press "
*", which searches for the entire word currently under the cursor, which should be one of our instances of "
- Press "
cgn", which tells Vim you want to change the match under the cursor (you're now in Insert mode) and then type "
CHAMPIONS", followed by the
- Press "
." to automatically repeat the previous step and marvel in amazement as Vim turns
yy --> yank line p --> paste it bbb --> beginning, beginning, beginning www --> word, word word / --> forward search n --> next match * --> search the word currently under the cursor cgn --> change search match . --> repeat previous command
Quick tidbit: exiting Vim
Exiting Vim is famously confusing for first-timers. Just press "
:q!" to quit without saving your Vim demo, or "
:wq" to write quit.
Comprehension and composability
You're probably gathering by now that Vim is incredibly mnemonic. That is, editing in Vim is much like speaking a language. This allows editing in Vim to quickly become second-nature once you grow somewhat accustomed to even just a few basic commands.
Further, Vim contains powerful concepts that are well suited to the task of composing text, not the least of which being the "." command (or "dot" command), which is entirely unique to Vim. The "
." command plays into the composability of Vim, which is a fancy way of saying that Vim allows you to use its commands as building blocks and inputs for other commands, macros, and scripts, which ultimately make the Vim editing lexicon exponentially powerful unto itself.
This power is real and you will experience it if you use Vim for any length of time. Though, however powerful Vim may be, it doesn't take itself too seriously for some lighthearted novelty. Indeed, VimGolf is an ode to the powerful composability of Vim: a clever Vim user, so inclined, can make vast edits in precious few keystrokes.
Here's a few links
I won't cover everything there is to cover because there's too much, I don't know everything, and everyone else has done it better. In view of the latter, here's some links to keep you going:
- Getting Started with Vim: An Interactive Guide
- How vim Makes my Daily Life Easier, by Luke Smith
- Why I love Vim: It’s the lesser-known features that make it so amazing
- Vim Tips Wiki: Best Vim Tips
- awesome-vim: A collaborative list of awesome vim resources
And some personal advice
I couldn't let you leave without inserting my humble opinion on a few matters, so here goes:
- Vim will serve you best if you grok vi, ed, and ex. They are the basis for Vim's greatness and the foundation of its philosophy.
- Avoid your mouse, not to mention your arrow keys. Challenging yourself in this will pay off.
- Persist in learning better ways to do what you're already doing. There's always a more efficient method.
- Keep a minimal Vim configuration, and don't just copy someone else's. Have a reason for what you include.
- Along the same lines, avoid using too many plugins. There's a reason I didn't mention them in this post: you probably don't need them.
- Don't hesitate to use an IDE if you need one. If you're writing Java, you probably shouldn't use Vim. Use the right tool for the job. If you want more IDE features in Vim (via plugins), take a look at NeoVim.
- Don't use Vim because it's severe or seems hardcore; it's not a fashion statement. Use Vim because it helps you to write text effectively.
- Swiftly disregard people who write lists. This is a hard and fast rule. People who write lists don't know what they're talking about.
That last item is questionable. Imagine how easy it would be to delete it in Vim! On a serious note, there are many opinions on the internet. It's increasingly important in the year 2020 that you have the bravery to develop your very own understanding of things. So, freely take or break my advice. Vim is cool; you won't be disappointed.
If you didn't watch the video at the top of this post, you should. It's inspiring to see skilled workers making something beautiful by hand, using tools and techniques that perfectly suit their undertaking. Vim is a similar tool to the draw knife or the hand plane used by the master woodworker. It's an old tool, but it will never be outdated. It will always find itself at home in the hands of a skilled maker. It's a multiplying force that acts as an extension of the body and mind. The right tool for the job will always be relevant.