I recently got started using Emacs, and I was surprised to see just how bad most of the quick-start guides are. Most lacked the basic commands and definitions that beginners really need. This is my attempt to do better. I'm a n00b myself, so there won't be much explanation, just a basic overview, some useful starter commands, and links to proper tutorials.
NB: Emacs is not one thing. This post is abut GNU Emacs 23.
Most interaction with Emacs (besides normal typing of text) is via the issuance of commands. These commands almost exclusively involve modifiers like Control and Meta, which correspond to Ctrl and Alt on most keyboards. If you see the keyboard shortcut
M-x, you should type the [X] key while holding down [Alt]. Similarly,
C-h means [Control]-[h]. Some commands involve a sequence of keystrokes. You can remap all of these later if you wish. (You should also familiarize yourself with some other key and character conventions.)
Here are your first commands:
C-g will cancel just about anything (a command in progress, a selection, etc.) and
C-x C-c will quit the program. Note that C-x in most programs is "Cut to clipboard"—this is not what it is bound to in Emacs. In fact, none of the usual keyboard shortcuts apply. You'll learn about their replacements soon.
When you first launch Emacs, you will probably see a single window split into two panes, one above the other. (Emacs calls this a vertical split instead of a horizontal split, confusingly, but we'll stick with the convention.) These panes are called windows in the rest of this document. You have a cursor in each one, but only one will be blinking and active. This is the current window. Want to get rid of all windows except the current one? Use
C-x 1 to do that.
C-x 0 will close the current window.
The stuff you see inside each window is a buffer, which can be anything from a command line to a document to an interactive settings file. You can have a bunch of buffers open at any given time, and each window can be targeted to show any one of them. You will usually just have one window open and keep switching which buffer is being viewed in it.
C-x b will give you an interactive prompt that will let you swap out which buffer you are using, and
C-x C-b will give you the full list in the current window until you position your cursor over the one you want and hit [enter].
A buffer in Emacs is always in one major mode at any given time. Major modes generally change with your programming language, and affect syntax highlighting, autocompletion, compilation, etc. There are also minor modes, which can coexist peacefully. Most notably, modes change what certain commands mean. There's a command to move forward by one word, but the meaning of "word" changes between programming languages. (If you're using an s-expression language, for instance, you'll really want the Paredit mode, which lets you sling parens like a master.)
Undo mistakes with
C-/. If it really wasn't a mistake after all, you'll still be able to get it back later by undoing some more!
Now that you know the real basics, you're ready to look at all those other Emacs tutorials! Your next steps:
- Open and save files
- Keyboard navigation (and why the arrow keys can be trouble)
- Undo, and redoing by undoing
- Killing and yanking are not just different words for cutting and pasting
- Understanding, installing, and enabling modes
- How to use the amazing help system (
Oh yeah, and here's some common stuff that isn't mentioned in regular guides:
- Trying to save to a new filename that has a space in it, and Emacs isn't letting you?
C-q spacewill put in a literal space. (
C-qin general lets you enter a character you can't normally type in some contexts, such as newlines. Q is for Quote.)
- Want to put a newline character in a search or replace pattern?
C-q C-jinserts a ^J (line-feed character), which is usually what you want. In DOS mode you'll need to insert an ^M (carriage return) before the line feed, otherwise some programs might freak out.