Emacs Powertools and Opinions
November 5th, 2008 at 3:53 pm (Computers, Writing)
I recently came across Steve Yegge’s emacs tips. He’s a man after my own heart:
“Using the mouse is almost always the worst possible violation of economy of motion, because you have to pick your hand up and fumble around with it. The mouse is a clumsy instrument, and Emacs gurus consider it a cache miss when they have to resort to using it.”
Cache miss! I love it.
His article is long, detailed, opinionated, and a goldmine of useful emacs nuggets. It will only be interesting to you if you are at least an intermediate emacs user and, say, you agree with the philosophy noted above. Here I include some of my own tips and commentary on his post.
Steve suggests mapping the CapsLock key to be Control, which is sensible in an emacs world, since you use Control orders of magnitude more often than Caps Lock, and ergonomically CapsLock has the more desirable position. But I’ve always been reluctant to do this, because it’s non-standard, and once you’ve adapted to the unusual layout, you render yourself frustrated and mistake-ridden when using anyone else’s keyboard.
Navigation: I already use Ctrl-s (search forward) and Ctrl-r (search backward) liberally to move around in documents (I agree that this is very handy!) and I do use temp buffers for notes — or rather, only one temp buffer. I only use *scratch* for this, because I like being forcibly reminded that there is no auto-save going on and anything I put there won’t be saved unless I explicitly do so (otherwise my compulsively periodic saving goes on as a background processes, in addition to emacs’s autosave, and I generally assume that anything in an emacs buffer has a good dose of permanence). However, I’ve rarely used the regexp search commands, because it was so tedious to type Meta-x-isearch-forward-regexp. Happily, in this article I learned that there are bindings to be had: Ctrl-Alt-s and Ctrl-Alt-r, respectively. (Actually, on my Mac they are Ctrl-Apple-s and Ctrl-Apple-r.) I agree that this is a spectacularly awkward binding to type, but I don’t use it that often (yet) so I’m willing to try it out before remapping it.
The other super-useful navigation bindings that I regularly use (not mentioned in his article) are Ctrl-[ and Ctrl-] to jump to the top and bottom of the file, respectively.
Buffers and windows: I already use most of the buffer and window management commands he listed (splitting, swapping, closing, and listing buffers) but did learn a new one: Ctrl-x + to balance window sizes. Cool!
GUI stuff: I don’t use the menu bar in emacs (sometimes it’s there, sometimes not; I generally ignore it either way). I do, however, like having a scroll bar. I don’t use it much (again, I dislike using the mouse), but it gives a nice visual indication of where I am in a file and how big it is. Yes, the status bar will tell me that I’m 61% through the file, but the visual is much more intuitive, especially because it shows me how much of the file, proportionally, is currently shown in the buffer window. Steve backs off from his initial recommendation to get rid of the scroll bar with an interesting analog/digital argument.
Steve cites “region selection” as a case where the mouse is actually helpful in emacs. I’ll agree, in the case of rectangular region selection (I don’t even know how to do that with the keyboard, much less efficiently), but I do normal region selection all the time with the keyboard. I set the mark (Ctrl-space), move to the end, and then do whatever I needed to do with the region: copy (Meta-w) or cut (Ctrl-w), usually. He seems to view the “move to the end” as the slow bit, but with Ctrl-s (search forward), as noted above, generally this is speedy as well.
Help: I agree that Meta-x-describe-bindings can be a fascinating (and revealing) exploration of the current mode and the powers available to you. I’ve used this in bibtex mode to good effect.
Query-replace: This is one of my favorite bits of emacs power. I love that I can so easily specify text to find and replace, and do it interactively, skipping from instance to instance and individually saying yes or no, or opting to just say yes to all such occurrences (with a !).
Other tidbits I gleaned from this article are
- Meta-b to skip back a whole word. I can’t believe I never knew this one. I imagine then that Meta-f goes forward a whole word. Hey, it does! I also use Ctrl-t regularly to swap two characters (usually when I typed them in the wrong order), and sure enough… Meta-t swaps two words. Whee!
- M-x list-matching-lines: this one blew my mind. It takes in a regexp and shows you every line in the buffer that matches it (like grep -n -e on the command line, but hey, you’re still in emacs, and if you go to one of those entries and hit return, your cursor jumps to that position in the buffer).
Any additional tips are welcome!