The Emacs Bunny Slope

This is a guide to the Emacs text editor. Specifically, it's for using Emacs inside a terminal window, using the keyboard only, as you might use Pico or Vi. I hope that this will help people who spend a lot of time working with text files to get their feet wet with Emacs and maybe even use it to be more productive.

Emacs is a very large, sophisticated text editor. Nevertheless, you can learn to use it without worrying about all of that stuff. In this guide, you will learn a small number of commands, and that'll get you started. You can get along just fine with just those commands, but hopefully you'll choose to learn more later. A secondary benefit of learning the Emacs keys is that the Bash command line shell uses most of them too. So, if you get good at Emacs, you'll also be able to use command lines more efficiently.

What Emacs looks like:

The Emacs UI is pretty sparse.

Ignore the top line (that says "File Edit..." in white text on a black background). That's for mouse users.

The majority of the screen shows the contents of your text file.

The white-on-black line near the bottom is called the "modeline" and tells you some stuff about that file: it's called sample.txt; Emacs thinks it's a plain text file; the cursor (the black rectangle) is at line 2, column 21.

The bottom line is called the Minibuffer. It shows status messages, and is where you enter commands. It's used sort of like a dialog box in a GUI, except that it's stacked on the bottom instead of being in the way.

How not to screw up

The first three commands you should learn are the ones that get you out of trouble:

Moving around

You can use the arrow keys. You can't use Page Up and Page Down because those belong to the terminal program that Emacs is running inside of. You use Control-V for page down, and Meta-V for page up. You use Meta-F and Meta-B to go forward and backward a word. You use Meta-< and Meta-> to go to the top and bottom of a document. You use Control-A and Control-E to go to the beginning and end of a line.

What's Meta?

It's an imaginary modifier key (kind of like Control or Shift) that your terminal program knows about. It's probably the same thing as your Alt or Option or Command key on your real keyboard. Check the documentation for your terminal program to figure out how to configure this (there may be a checkbox for "Use Alt key as Meta", which should be checked).

Search and Replace

Hit Control-S and then the text you want to search for. The cursor will move to the first match. Hit Control-S again to search for the next match. Use Control-R instead of Control-S to search backwards.

Hit Meta-% to do a search and replace. (It's pretty self-explanatory once you get it started.)

Saving

Control-X Control-S to save, or Control-X Control-W for Save As.

Common problems

When you hit the delete key, Emacs thinks you typed Control-H: check your terminal program documentation. There should be an option like "Delete key sends backspace" or "Exchange backspace and delete" that you can enable that makes this go away.

My terminal program doesn't know about Meta. Use the Escape key before the other key that would have gone with Meta. So instead of Meta-X, press Escape, then let go, then press X. It's up to you to decide if this is more annoying than finding and using a terminal program that knows about Meta.

Getting more ambitious

There's an online manual.

Features to explore next (the stuff that makes Emacs worth using): buffers, the "info" command, help, split windows, keyboard macros, syntax highlighting (which Emacs calls font lock mode, and the ~/.emacs file.