Wednesday, August 05, 2009

Quicksilver Solves Emacs vs vi

This will get geeky. First some background. Way before word processors, computers had text editors and two in particular came to prominence. Both vi and Emacs were written in 1976 and I think vi vs. Emacs really was the first Internet flamewar and it's still going on.

This was long before menus and mice so both text and editing commands had to be entered via the keyboard and it was even before arrow keys. But since you need to be able to type all the letters, numbers and punctuation, where do you put the commands like uppercase word and move forward a sentence? This was even before arrow keys so there wasn't that solution either. And both of these editors have a lot of commands (though I think it's fair to say Emacs has many more and vi users see that as a detriment).

In Emacs, commands have names like forward-word which moves the cursor forward a word. You can execute it by typing M-x which stands for hit the meta key and then x and typing forward-word. (Keyboards used to have a meta key, now usually the alt key stands in its stead or you can hit esc and then x.) Or for the more common commands (and even many uncommon ones) they are bound to a keystroke, in this case M-f. Emacs is famous for binding commands to crazy keystrokes like C-M-s (search forward for a regular expression pattern) or C-x C-s for save (type x while holding down control then type s while holding down control). You really do get used to it, and you can learn commands at your own rate but it's easier if you turn your caps lock into a control key.

vi is different, it has two modes: a command mode and an edit (aka insert) mode. In edit mode you type and the letters go into the document. In command mode, the various letters stand for commands. Famously (as many games still use this), the h, j, k, and l keys stand in for the arrow keys as left, down, up and right. $ is the end of the line and ^ is the beginning of a line. Type these and the cursor moves as commanded. w moves to the beginning of the next word, e to the end of it. 4w moves to the beginning of the 4th word following the cursor. etc. /string searches for "string" in the file. vi users are really good at switching between modes.

So real programmers use either vi or emacs. I've been using emacs since 1983. My friend Sean uses vi. I long ago got over the flamewars. An editor is only as good as you know it. If you're proficient at emacs you can be just as efficient as someone proficient at vi. But the flamewars continue.

When I switched to the mac I discovered the program Quicksilver. It quickly became my favorite program of all time, even more so than emacs. It's easy to use but not obvious and it's unfortunately very difficult to describe just how powerful it is. And I've tried, I wrote a 120 page manual for it and a one page quick reference sheet. This tutorial is a good intro, but basically it's a launcher. No matter what you're doing on the mac, type a configurable keystroke like command-space and it brings up the Quicksilver command window. Then you type to bring up the thing you want. It can be a program, the name of a file, or a song in iTunes or a person in the address book, or a bookmark in your browser, or an album in iPhoto or just about anything. Most launchers stop there, you bring up the thing, hit return and it opens (Spotlight works like that). Quicksilver's power comes from the second pane in the command window where you can enter a verb. Sure the most common one is open, but you might use Copy, Move To..., Email to..., Add to Playlist, Hide, etc. If I bring up a contact from the address book in the first pane I can choose actions like Compose Email to start an email or Email Item to then choose a file to send (it will just do it I don't even have to open Mail) or IM... or Video Chat... or Edit Contact, etc.
Picture 2 1.png
The intangible part of Quicksilver is that after you get used to it, you start all your actions on the computer with it. It almost becomes the interface to your mac, and it's very difficult to use someone else's machine that doesn't have it.

There's a lot more to it but one more thing to mention is triggers. You can bind commands to keystrokes to make them even faster to run. E.g., if I type option-command-f (I said I was an emacs user) Quicksilver appears and prompts me for text to search in imdb for. I look up movie titles and actors all the time using this. I don't have to first go to the browser and then visit imdb or choose a search engine from the search box drop down. One keystroke, type and see the results in my browser. If I add shift to the keystroke then I can first highlight text and hit and it searches for the text. So if I'm reading an article about a director, I can find his or her imdb page without ever having to type or even copy and paste the name, just highlight and type a keystroke. I used a trigger (control-shift-command-i) to resize the above screenshot to be 400 pixels wide to post on the blog. I use that trigger all the time.

Sean started using Quicksilver recently and is adding new commands and uses to his repertoire over time. I was describing a trigger I used all the time (hide the current application by moving the mouse to the top right corner of the screen) and he said "i don't use many key-combo triggers", he mostly just uses the Quicksilver command window and types in nouns and verbs. I replied that it "must be my emacs background" that I use lots of triggers. He said "vi has command mode which may be why I'm so comfortable in QS's noun-verb mode and rely less on combos, QS is like command mode for my OS" I thought that was a really nice description and added "and triggers are like emacs key bindings". The nice thing is that you can choose to use it either way. Quicksilver is really flexible in how it lets you use it and in its own way, it solved the emacs-vi war.

After we had this epiphany in chat he said "TO TWITTER!" and we both laughed and realized this wasn't going to fit in 140 characters. We both ended up blogging it. Here's Sean's writeup of this. He takes the analogy further and introduces perl.

2 comments:

The Dad said...

The next time I'm in Boston you are forcing me to sit down and learn QS.

Howard said...

What you don't have time now?!? Watch the tutorial, it's video. http://bit.ly/kGNY