Tuesday, December 06, 2005

Editor Choice

If you prefer vi to emacs, do this: set -o vi (If you're just experimenting, set -o emacs gets you back to emacs mode.)

Me, I use vi-mode in the shell. I've been using vi for so long, it's in my firmware. I don't have to think about how to edit files with vi, it just comes out of my fingers. Editing command lines comes just as naturally.

Do remember that vi is a modal editor. When you begin to type, you're in insert mode. To get to command mode, type Esc. Once you're in command mode, the familiar vi commands just work. End of line? $ Beginning of line? ^. Back two words? 2b. Change the word under the cursor? cw.

As soon as you type Enter, the current line, as you see it, is handed to the shell and executed. You're put back in insert-mode with a new, empty line.

If you prefer TECO or WordStar or some other editor, you're out of luck. emacs and vi come standard, but nothing else. Sorry.

On the other hand, if you want to learn vi or emacs (because, say, you're coming from another operating system), then the shell is an excellent teaching tool. Each history-editing command you learn will work in the editor, and each text-editing command you learn will work on the command-line.

As one last trivium, the old line editor, ex, feels just like vi-mode history editing. Some day, you'll be stuck using a line editor to recover a system. Instead of being nervous, you'll find yourself completely comfortable. It'll feel just like editing your history.

After you're comfortable with vi-mode history editing, go try ex; you'll see what I mean.

0 Comments:

Post a Comment

<< Home