I've been observing the big emacs vs. vi debate without having a dog in the fight.
I'm an old graybearded programmer, and have become set in my ways, which really didn't have much to do with either emacs or vi.
Contents |
Back in the old days, I was an IBM oriented guy instead of a DEC oriented guy, so I hadn't crossed paths much with either of the two predominant *nix editors which both start with character by character "full-duplex" terminal hardware such as the VT100. My experience had been with the IBM 327x family of terminals which did local editing in the terminal and only exchanged screen sized buffers with the computer. IBM had it's own editor wars but the editors in question were ISPF and xedit (not to be confused with xedit for x windows.
For the longest time I've been using graphical editors. I spent a long part of my career using, developing, and advocating GUI based IDE environments for object oriented languages such as Smalltalk and Java. So I've come to use the mouse as my main editing tool instead of the keyboard. As I grow older, my tendency to avoid things which make me remember arcane keystrokes has grown.
When I started playing around with Linux a few years ago, I found VI pretty much impenetrable since it provides very little "in your face" help. The first problem was having to remember how to get out of the editor. I've also come to regard modal user interfaces as evil. Although emacs wasn't much better, at least it gave me pull down menus and the like, so I went for the one with the training wheels.
But lately I've heard lots of triluggers singing out of the vi hymnal, so I decided to try it. I'm now in the middle of learning vi, and I've decided to share my learning experience here on the Trilug wiki.
At first, being the frugal sort I am, I tried to find on-line vi tutorials. Google turns up quite a few of these, mostly written by various university computer science programs to give new students and intro to the editor.
I found these pretty superficial. They mostly give just enough information to get you started with vi, without giving much of a rationale for how it works, or taking you very far.
I figured I needed a good book, so I went looking. It seems that the best book on vi is O'Reilly's "Learning the vi Editor," by Arnold Robbins and Lisa Lamb ISBN 1-56592-426-6. I finally found a copy locally at the Borders on Six Forks Road near Strickland. Finally I seem to have found a source which will serve MY needs. YMMV.
The key feature of vi is its modal nature. As I said, I'm not that fond of modal UIs since the user always needs to keep the state of the application in mind in order to predict how it will react. But the separation of command mode from insert mode is what gives vi its primary strength, which is the fact that you can do almost everything without taking your hands off of the keyboard.
The first thing you should learn, well after you learn how to get out (:wq, or ZZ to save and quit, :q! to quit without saving), is the basic cursor movement keys, which are h, j, k, and l, which move the cursor left, down, up, and right one character respectively. These are not very mnemonic. They are chosen because they form a compact row on the keyboard. I had a problem internalizing these however, because to my mind, left and up seemed to form a strong pair since they move backwards in the file. Also, since vi is really a fullscreen interface to the underlying ex line editor, h won't do anything at the start of a line, and l won't move the cursor beyond the end of the line.
After I played with this a bit I started to see the logic of keeping my hands on the keyboard and so I kept going.
I continued following the book. However I ran into something which mystified me for a while.
I would dutifully hit the i key to go into insert mode, and type several lines of text. When I was done I'd hit esc to get back to command mode, and use hjkl to move around. Then I'd decide to enter some more text and would often find that instead of going into insert mode, my last text would disappear and the status line would say something like "6 fewer lines." What the heck?!?.
I finally figured it out, the well chosen cursor movement keys were interfering with my typing skills. Over 35 years of using various terminals and keypunched I've managed to become a touch typist, despite having typing as the only course I'd flunked in high school.
In order to make use of the kinesthetic mnemonic of having left, down, up and right on those hjkl keys, I'd made a subtle shift of my right hand to the left so as to have one finger on each of these keys. The problem was when I wasn't moving the cursor, and went to hit the i key to go into insert mode, this shift put the u key where my hand expected to find i. As a result I was undoing my previous insert instead of starting a new one.
So now I have to retrain myself to KEEP that right hand in the home position with the index finger over the j and not the h key. This becomes more important as I expand my repetoire of vi keystrokes.
Despite these stumblings, there is something fascinating about the vi interface. As I start learning more powerful cursor movements, I find them to be a bit more mnemonic
Well it's a bit more subtle than this. The w key gets you either to the start of the next word if the current word is delimited with spaces, or to the punctuation at the end of the word if it isn't. W will always go to the start of the next word. Same thing for b and B, and e and E.
Cut, copy, and paste are familiar concepts, except that copy is called yank, which leads to the key mapping of c for copy, p for paste (although the official vi terminology is put), and y for copy (I mean yank). Now yank has a rich heritage from the DEC world, the first time I heard it used was when I was mentoring a new IBMer in learning PL/I and he decided to write a version of the TECO editor as his learning exercise. But I've gotten so used to the Macintosh/Windows mapping of x for cut, c for copy, and v for paste (another one of those key's in a row mappings) that I have to think about it a bit each time I use one of these functions.
So I've had some problems and interference with what's been ingrained from other tools, but vi is starting to make some sense to me. The way that commands get built up with a count, a command, and a cursor movement component seems to be quite powerful once I can wrap my mind, and fingers around it.
I'll try to keep y'all posted, if you are interested. I might even probe deeper into emacs later as well. Such mental exercises are supposed to help ward off Alzheimer's you know!