Bill Powell Is Alive
{ Man Found Alive With Two Legs }

A personal blog about Linux and literature, distributism and Catholicism, adventures in permaculture, and being alive.

A Hymn to Vim

by Bill Powell | updated: 2005 Apr 23 Sat | published: 2005 Apr 23, 00:00 Sat
tags: linux, nonfiction, and vim

I’ve traveled far in my Linux adventure since the immortal early newscast, Man Found Dead Trying To Install Linux. Not only did I get Linux to work, it’s all I work with. I wouldn’t start Windoze if I could.

I could (and eventually will) go on for hours about life in the Free Realm, but let’s keep this blog to one little program: Vim. Vim is a text editor, and if you’ve never edited text with anything but Micro$oft Word, please, think of your children and read this blog.

I write too much, so I’ve spent a sizable chunk of my life wrestling with editing programs. I’m old enough to remember console versions of WordPerfect and KEdit on my Dad’s company laptop. But when my parents came home with our first PC, it didn’t have the longed-for WordPerfect. No, the salesman had convinced them to choose something better: Word. How was it better? Mom wasn’t sure. So we fired it up.

Awe. Stupefaction. It didn’t look like letters on a computer screen. It was a piece of paper. When you typed, the letters looked real, just like they’d look when it printed! And there were so many buttons. At an agonizing parental crawl, we discovered each wondrous new power. Bold! Italic! Point sizes! Fonts! All at a mouse’s click! Sheer glory!

I’m not exaggerating that much. What was I, twelve? For the next several years, I would spend more time with M$ Word than any other program. But why dwell on unpleasantries? Over the years, here were my main gripes:

  • The program took awhile to start up.
  • File corruption was a way of life. Eventually, I started saving a separate copy every twenty minutes or so.
  • It didn’t like other file formats. Especially other M$ Word formats! Whenever I worked on a file at school, my home dinosaur was invariably still running some version that was at least two weeks out of date. Oops, my file was “not recognized.” M$ Word wouldn’t even see what it could salvage. Nope. Not recognized. We do not negotiate with rogue formats.

In short, everything I wrote was locked into a proprietary, binary file that I could only read with the approved version of an expensive, unstable product.

Not until college did I hear know that rebels had disturbed the pax micro$ofta. I tinkered with other WYSIWYG processers like Lotus, but they didn’t feel that different. When I started to get serious about claiming my computer, my first free word processor was Atlantis. It was pretty much M$ Word Lite, but it did start a lot faster. And it only saved in Rich Text format (”rtf”), which can (sort of) be read by any word processor.

Then I discovered text editors.

When you type into a word processor, the program doesn’t just save what you type, it saves tons of nifty, invisible codes. They mean things like, “Make this word three inches high” and “Email a copy of this document to Redmond, and that other Washington.” Unfortunately, these codes are in a certain “language.” If another program (like the version from last week) tries to read the file, it might not speak that language. Diplomatic relations break down.

But a text editor only saves what you type. If you’re still by the rivers of Babylon, the nearest text editor is probably Notepad. Try it. Notice how you can’t make something bold or italic? If there were any codes to make words bold, you’d see those codes, not bold words. You’re looking at the real file. (An ASCII representation, anyhow.)

Notepad is basically an electronic typewriter, no offense to the typewriter. When I tried cooler programs like Crimson Editor, I was hooked. I wrote stories in plain text; I left a blank line between paragraphs and marked underlines like _this_.

For the outside world, I still needed to make a final version pretty in a word processor. But for my day-to-day work, it was plain text. No more rogue formats for me; even M$ Word, any version, would grudgingly talk to a text file.

I still saved too many backup versions, but I rarely needed them. Text editors didn’t crash. I mean, yeah, I could cause trouble if I opened an entire web site’s worth of files at once. But for M$ Word, “trouble” was defined as “running me.” Unfortunately, I still needed it once in awhile.

Then came Linux.

In the Linux world, your text editor is your tribe. Even more than your distro, your choice of text editor initiates you into a worldwide brotherhood. And a warrior’s call to fight and die in the endless War for the One True Editor.

Sort of. Actually, there’s been such Editor Proliferation that I think it’s getting hard to carry on the Ancient Feud. But feelings still run high over the old choice: Emacs or vi, the two venerable editors of eld.

There was a time when, as far as I can tell, most UNIX people either used Emacs or vi. With the coming of Linux, these empires quickly established large colonies in the new world, and a truce has not yet been called.

Nor is this an idle dispute. Emacs and vi have many fundamental differences, and if you spend hours a day working with text, your tool matters.

However, if you’re reading this, both editors, as well as their myriads of children, have powers you probably haven’t imagined. Off the top of my head:

  • You can navigate through your file with astounding speed. You can jump by word, sentence, and paragraph. Or to 35% of the file. Or line 1432. Or jump precisely 6 words or 10 sentences.
  • You can combine this navigation with selecting. Press a few keys, and you can delete, say, exactly 4 sentences without a single click and drag.
  • Instead only one Clipboard (or a lumbering Clipboard Manager), you have many registers that you can cut and paste to with a few keys. Don’t like that paragraph? Save it for later in a place it won’t get copied over.

This is a laughably inadequate list, but it’s a hint of the power of these text editors. They’re not designed to look good, but to work well—and fast.

Although you can use a mouse, you can do anything you want on the keyboard. No menus needed. Yes, M$ Word has keyboard shortcuts and even lets you map new ones, but these editors treat the keyboard as the rule, not the exception.

After all, which takes longer, to hit three or four keys or to reach for the mouse and click through three dialogue boxes? How about if you have to do one or the other hundreds of times per day?

This is a glimpse of the strengths of any decent text editor. Now we come to Vim.

Vim is for “vi improved,” so you can tell which side I’m on. Actually, I tried Emacs first, and it does have its good points. I forget what didn’t work right, but I figured I’d try the resident child of vi, namely, Vim. I haven’t run Emacs since.

Why Vim? What I like best is precisely what drives Emacs folks nuts: modes. Vim, like its father before it, has several modes. (Actually, Emacs does too, but not they’re not as dramatic.)

In insert mode, the keyboard does what you expect. I’m using it now. I hit “d”, and a “d” goes into my file. No sweat.

In command mode, the letters I press show up as planned, but not in my file. Instead, they appear on the command line, which is for, well, typing commands. If I want to write (save) the file, I simply type “w” and hit ENTER, and the file is written. (Vim also has a menu for this kind of thing, but why bother?)

You may ask, “Wait, how can you tell which mode you’re in?” To invoke command mode, you first have to be in normal mode. Here’s where Vim becomes either nightmare or fairyland. Every key is a command.

Say I’m typing, and I want to delete the next 3 sentences after the cursor. I press ESC, and I am In Normal Mode. My benign keyboard is now a blessed minefield of commands. Instantly I type:

d3)

And the sentences vanish.

Scary? It’s a lovely logic. The d means “delete”. The 3 just means “do what comes next 3 times.” And the ) means “move one sentence up.” Thus, “delete 3 sentences.” You could easily delete 30 or 300.

With a mere ESC, you turn your whole keyboard into a control pad. Vim, like all Linux, is insanely customizable, so you can even be like me and switch the ESC and CAPS LOCK keys. (CAPS LOCK is about 251 times faster to press then ESC.) When you’ve done all the deleting or rearranging or whatever, you hit “i” and you’re back in insert mode. Or hit “:” and you’re in command mode.

Curious? Guess what, you don’t even need Linux to try Vim. There’s a Windoze version that’s almost as cool.

Course, there’s a Windoze version for Emacs too. Emacs (probably) has most of the same tools as Vim, but you need to hold down various permutations of Ctrl and Alt to do anything. If you get used to the lightning keystrokes of Vim, that starts to feel slow. On the other hand, you can stay in Emacs and use it to check your email, download files, and even play a text game. So it’s worth trying too.

But you’ll like Vim better.

And we haven’t even talked about add-ons. As usual, the crazy community of Open Source has inspired tons of free add-ons. When I started using LaTeX (a program for making plain text into pretty printables), I worried I might have to use a separate, specialized text editor. Nonsense. Someone had already written Vim-LaTeX.

My favorite add-on is VimOutliner. It’s what it sounds like, an outliner, but it’s the fastest, easiest way to arrange thoughts you’re likely to meet. I use it to take notes, plan stories, whatever.

So try it. Using any decent text editor is like moving from a couple blunt rocks to a full toolset. Come on, you have to write all the time. Go try Vim.


This page last generated: Sun Jul 18 14:11:02 -0400 2010