Emacs, also a way of life

If you’ve programmed or been a sysadmin on UNIX or Linux, you’ve undoubtedly already taken sides in emacs versus vi. You won’t be convinced to switch to the other text editor. It’s like trying to persuade someone to flip allegiance between the Red Sox and the Yankees.

If you haven’t, be aware that GNU Emacs is a very powerful text editor that probably runs on any computer you’ve ever edited a file on or ever will. Although calling it a text editor is a profound understatement. It could as easily be considered a software development environment (IDE), an office suite, or a personal information manager (PIM).

Learning GNU Emacs, 3rd Edition is an excellent way to get started. Yes, the book was last revised in 2004. But even the 1991 first edition is still useful—one of the strengths of Emacs is that the basics are stable.

For that matter, the commands I learned ten years before that still work. I have been using some form of Emacs for over thirty years. As a tool, it’s an old reliable. With a handle worn down to comfortably fit my hand perfectly. I’ll bring it up here when I think of something to share that’s especially useful or satisfying.

One problem is terminology. Emacs has different terms and notation than you may be used to. Although, like Time Lords, we were there first. I’ll elaborate as we go. But a few essentials first.

Every one of the thousands of commands available has a name. The command to move to the previous line is called previous-line. As such, you can run it by <Esc> x previous-line <Enter>. Since it’s frequently used, and you’d never get any work done if you had to type all that, it comes bound to the key-combination <Ctrl>+p. And if your keyboard has arrow keys, it’s also bound to ↑.

If you don’t like that, you can change it. Switch the key-combination to something easier for you to remember. Or take a command you use often that doesn’t have a key-combination and assign it to one.

When discussing Emacs, though, refer to the standard key assignments. And remember, a command’s real name is the text version, not the key assignment.

Also, the way key assignments are written are different. C-p is what PC users know as <Ctrl>+p. S-p is <Shift>+p. M-p is <Alt>+p. (The M is for ‘meta.’)

And they can be combined: C-S-p, C-M-p, M-S-p, or C-M-p, or even C-M-S-p.

If you’re ever confused, the command M-x apropos helps you find commands whose name includes your search term, e.g. searching on capitalize reports capitalize, capitalize-region, capitalize-word, capitalized-words-mode, and cua-capitalize-rectangle. You can even search by regular expression if you feel like showing off.

The command M-x describe-key (bound by default to C-h k) tells you what, if anything, a key or key/mouse combination will do. After entering the command, you’ll be prompted to use the key or mouse/key combination you’re curious about. But be aware that describe-key distinguishes between the different keys that have the same labels.

For example, the * above the 8 in the main keyboard is considered a different key from the * that’s on a numeric keypad (where its Emacs name is kp-multiply). I’ve chosen to use the keypad keys for different purposes, e.g., in my setup the keypad’s * inserts a • instead of an asterisk.

So what do you think?