Some reasons why I like vi

December 17, 2008

I will reluctantly admit it: I sort of like vi. It is a grudging like, for vi is not my favorite editor and it has its weaknesses, but still, there are things about vi that I keep finding cool and nice and attractive. One significant reason is vi's regularity and what I will call 'composability'.

(Let me note that by 'vi' I mean the entire vi family.)

To make up terminology, vi more or less has two sorts of commands: commands that change the text (call them 'action commands'), and commands that move the cursor (movement commands). Vi's regularity and composability is that pretty much every action command can be used with pretty much any movement command to specify what to operate on.

Once you learn this and it really sinks in (which took a while in my case), what you get is an immense amount of leverage for your vi knowledge. If you know a navigation trick, you can extend it to select text for action commands. When you master a new movement command, all of your action commands also get more powerful; when you master a new action command, all of your movement commands get more useful. When you learn something new, it doesn't just add to your abilities, it multiplies them in a virtuous feedback loop.

(I think that this is a great way of growing people's expertise and rewarding them for it. Unfortunately it is hard to copy in other contexts.)

This interacts nicely with another reason I like vi: its support for pipes, specifically piping text through commands. Pragmatically, this means that I can extend vi (in some ways) by writing shell scripts and hooking it to specialized superintelligent programs like par. Since piping is just another action command, it takes all of the usual movement commands for text selection.

As a side note, this composability also gives you little things to figure out and learn all the time. Even if you're not learning new movement and action commands, you can always see if you can come up with anything useful to do with a combination you haven't tried before.

(Since this experimentation gives you a stream of little rewards for playing around with vi, it is perhaps no wonder that people wind up loving it.)


Comments on this page:

From 87.79.236.202 at 2008-12-17 07:27:47:

Yes, exactly. (And vim takes this to the next level by introducing text objects (:help text-objects), which go beyond motions in that the operation need neither start nor end at the cursor location – the cursor may be located anywhere inside the area of interest. I use da< quite frequently when writing HTML, f.ex., or ci" and =i{ when programming.)

In fact vi extracts even more power from the concept: motion-action composites provide a useful unit for complex repeats. The . command routinely saves me huge amounts of effort. No other editor has anything really comparable. (Again, vim takes it to another level by providing a powerfully minimal macro facility – q records your keystrokes into a register (the vi equivalent of the kill ring, roughly) and @ replays the content of a register as if you were typing it, but stops at the first failed command.)

Basically, vi provides an abstraction facility for the low-level mechanics of editing, and vim even more so. I envy the high-level support provided by some Emacs modes, but I could never give up the incredible improvisatory power and precision of the vi model. It’s like a surgeon-grade 6-inch steel blade.

Aristotle Pagaltzis

From 66.243.153.70 at 2008-12-17 12:39:37:

As a followup to Aristotle Pagaltzis's comment, of course emacs has a feature like "." - it has everything!

The function is called "repeat", and is conventionally available with the "Control-x" followed by "z" key sequence. Once invoked by a multi-character sequence it can be repeated a second time by just repeating the final character, so where in vi you might type "..." in emacs you would type "Control-xzzz".

I think my favourite improvements for vim is the "*" (and matching "#") keys, which look for the word under the cursor, and the "gf" or "Control-wf" sequence which takes me to the file under the cursor.

Icarus Sparry (who also switches between emacs, vi, vim, sam and ed as needed)

From 87.79.236.202 at 2008-12-19 07:39:52:

But motion is a command as well in Emacs, so C-x z is not the same thing at all. The . in vi repeats the last command+motion unit, regardless of any command-less motions in the meantime, eg. you can type dwj.j.j. to delete the word in the current cursor horizontal location on the current and following three lines. This simply does not translate to emacs.

I stand by what I said: no other editor has something similar to vi’s . command.

Aristotle Pagaltzis

Written on 17 December 2008.
« Why XHTML is doomed, at least in its strict validation form
Why LVM snapshots should really have hooks into filesystems »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Dec 17 01:30:02 2008
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.