A Guided Tour of Emacs - The many faces of Emacs
The GNU Emacs Manual calls Emacs the extensible, customizable, self-documenting real-time display editor, but this description tells beginners little about what Emacs is capable of. To give you an idea, here is a sampling of some of the things you can do with Emacs:
Like you would expect of any text editor, Emacs can be used to edit text files, such as one's grocery list.
Emacs includes special facilities for editing code in many different programming languages (as well as compiling, running, testing, and debugging them):
Emacs can view and edit files in their hex representation (M-x hexl-find-file):
Emacs can compare two buffers and highlight the differences between them (M-x ediff-buffers):
Emacs is a file manager (M-x dired):
Emacs is a terminal emulator (M-x shell):
Emacs is a mail and news reader (M-x gnus):
You can even play tetris in Emacs (M-x tetris):
You might see now why some people characterize Emacs as being an entire operating system. Many Emacs users find that they can do almost all of their work from within Emacs, and there are many advantages to doing so.
Why Emacs?
Emacs helps you be productive by providing an integrated environment for everything you need to do:
- All of the basic editing commands (and there are lots of them) are available no matter what you're trying to do: write code, read a manual, use a shell, or compose an email.
- All the tools Emacs provides for opening, saving, searching, and processing text (and more) are available to you in any context.
- Emacs makes it easy to move text around between the different applications you use in Emacs.
The combination of consistency and flexibility means that you can do a variety of different tasks efficiently from within Emacs. There's no need to switch between dozens of different programs (all of which will generally have subtly different keyboard commands for text editing...).
If Emacs doesn't work the way you'd like, you can use the Emacs Lisp (Elisp) language to customize it, automate common tasks, or add new features. Elisp is very easy to get started with. And yet it's is incredibly powerful when it comes to customizing, automating, or extending the editor— far more powerful than the extension facilities in Eclipse or Microsoft Visual Studio. You can make Emacs whatever you want it to be by extending it with Elisp; one testament to this is the fact that all of the features pictured above (and many more I'll mention later) are in fact written in Elisp.
Before we get started...
First, complete the Emacs tutorial (to do this, start Emacs and type C-h t, that is, Ctrl-h followed by t). The Emacs tutorial is an interactive hands-on which will familiarize you with many things, including:
- Starting and exiting Emacs
- Basic text movement and editing commands
- Opening and saving files
- Emacs concepts: windows, frames, files, and buffers
- Invoking commands with keybindings and with M-x
All the features, commands, and keybindings I'll mention work in GNU Emacs, version 22. Behavior and keybindings may be slightly different in other versions of Emacs. Some features included with GNU Emacs 22 weren't bundled with previous versions of Emacs but can be installed separately.
Occasionally I'll say something like "See (info "(emacs)Intro") for more information." This refers to a page in the Emacs manual (in this case, "Intro") which you can read with the built-in documentation reader, called Info. To view that page in Emacs, type M-: (info "(emacs)Intro") RET.
The power of text manipulation
Emacs gives you a large collection of tools for manipulating text, which turns out to be a Swiss army knife of sorts because Emacs also has a way of presenting all kinds of information in text. Here's one example:
M-x dired invokes Dired, the file manager mode, on a directory of your choice. Then M-x wdired-change-to-wdired-mode switches to Editable Dired mode, which looks like this:

In this mode, changing the filename text (in the right-hand column) and then typing C-x C-s ("save") renames the indicated files. Suppose I want to change all the emacs-slides-*.odp filenames to just slides-*.odp. Emacs makes that as easy as doing a search and replace (M-x query-replace or M-%)! There's no need to learn to use a batch renaming tool when Emacs lets you edit filenames the same way you edit text.
From within Emacs, you can interact with not just files and directories, but system utilities, compilers, debuggers, personal information managers, the web, email, various internet services, and more, and there's an ecosystem of third-party tools to make even more functionality accessible from within Emacs. And they all use roughly the same editing commands, so the benefits of learning to any particular feature of Emacs (say, search and replace) are multiplied many times over.
Basic editing commands
Working with Emacs is so incredibly efficient in part because Emacs gives you so many high-level tools for moving around in, and manipulating, text: there are commands that apply to characters, lines, sentences, paragraphs, pages, function definitions, whitespace, and more. Keep in mind that you get to leverage them everywhere you do editing: source code, web pages, shells, directory listings, email messages, and so on. Emacs even uses text in buffers as UI.
Moving around in buffers
The basic buffer movement commands move point (the cursor) by rows (lines) or columns (characters):
| C-f | Forward one character | C-b | Back one character |
| C-n | Next line | C-p | Previous line |
Here are some ways to move around in larger increments:
| C-a | Beginning of line | C-e | End of line |
| M-f | Forward one word | M-b | Back one word |
| M-a | Previous sentence | M-e | Next sentence |
| M-v | Previous screen | C-v | Next screen |
| M-< | Beginning of buffer | M-> | End of buffer |
You'd do well to learn and use the keys above, even though many of them have more familiar equivalents in modern applications: Home, End, Ctrl+Left, etc., respectively. Once you get used to these keys, which you can use without moving your hands from the touch typing position, they are far faster than using the mouse to point and click on places in a buffer, especially if you'd need to use the scroll bars.
As you can see, Emacs allows you to move around buffers in units of various sizes. Emacs often provides additional commands for moving around in context-specific ways (e.g. to the previous or next function definition in source code).
Many of the above commands move to a location relative to your current position in the buffer, so you can use them repeatedly (e.g. C-p C-p C-p to move back three lines). You can use the prefix argument to save time: C-u followed by a number and a movement command repeats that command the specified number of times. You can also use M-[digit] instead of C-u [digit]. If you use C-u without specifying a digit, the default is 4. Omitting the digit saves you time, and it can be handy when you don't know exactly how many units you want to jump anyway.
| C-u 3 C-p | Back 3 lines |
| C-u 10 C-f | Forward 10 characters |
| M-1 M-0 C-f | Forward 10 characters |
| C-u C-n | Forward 4 lines |
| C-u C-u C-n | Forward 16 lines |
| C-u C-u C-u C-n | Forward 64 lines |
You can jump directly to a particular line in your buffer:
| M-g g | Jump to specified line |
Searching for text is a handy way to move around in a buffer. Think of search as just another facility for movement. When you're looking for something specific, use incremental search to take you right there instead of moving by lines or pages. Even if the text is already visible on the screen, search is often the fastest way to move the cursor there.
| C-s | Incremental search forward |
| C-r | Incremental search backward |
This is one way that advanced Emacs users always seem to be able to zip around buffers super-quickly: they can jump straight to the place they want to go instead of stumbling around in order to get there. More about search later.
Emacs remembers something called the mark, which is a previous cursor position. You can set mark to indicate a particular place in your buffer so you can return to it easily. C-x C-x at a later time will return point to mark. Actually, that command also moves mark to where point formerly was; therefore, a second C-x C-x returns point to its original position.
| C-SPC | Set mark to the current location |
| C-x C-x | Swap point and mark |
Certain commands set mark automatically for you, providing you with convenient footholds as you move around your buffer. More about mark later.
Killing ("cutting") text
As with text movement, Emacs provides commands for deleting text in various amounts.
C-k kills the portion of the current line after point (or deletes the newline following point if point is at the end of line). The prefix argument for C-k can be used to kill multiple lines:
| C-k | Kill line |
| C-u 10 C-k | Kill 10 lines |
| C-u C-k | Kill 4 lines |
| C-u C-u C-k | Kill 16 lines |
These commands operate on the region, and are the closest analogs to "cut" and "copy" in Emacs:
| C-w | Kill region ("cut") |
| M-w | Save region to kill ring without deleting ("copy") |
These commands are also handy:
| M-d | Kill next word |
| M-Backspace | Kill previous word |
| M-k | Kill to end of sentence |
| M-z [char] | Kill ("zap") to next occurrence of character |
All of the above commands kill the text being deleted, which means that Emacs removes the text and squirrels it away for later retrieval ("yanking"— more about this later). Most commands which delete significant amounts of text kill it rather than simply removing it, so that you can use those commands either to "delete" text or to "cut" it for later use.
The following commands delete single characters, although they do not kill them:
| Backspace | Delete previous character |
| C-d | Delete next character |
Yanking ("pasting") text
After a piece of text has been killed, it goes to a place called the kill ring which is analagous to the "clipboard": you can yank to restore it from the kill ring with C-y. Unlike the clipboard, however, the kill ring is capable of holding many items, not just the most recent thing you put there. If the item you want to yank is not placed when you type C-y, type M-y (repeatedly, if necessary) to cycle through previously killed items.
| C-y | Yanks last killed text |
| M-y | Replace yanked text with previously killed text |
Recall that most commands which delete a large amount of text in fact kill it (i.e. place it in the kill ring) so you can restore it later. Emacs makes it very difficult to lose a lot of text permanently: in editors with only a single clipboard, it's easy to simply delete a large chunk of text or to accidentally clobber the contents of the clipboard (by copying a second item before you're done with the first). You can also use the kill ring as a sort of scratch space, to pick up different pieces of text at once for later insertion.
Mark
As I've already mentioned, mark remembers a cursor position for later return. C-x C-x swaps mark and point, so that one C-x C-x takes you to mark, and another C-x C-x brings you back to where you were.
Mark can be set explicitly, but sometimes it is set as part of another command:
| When you... | mark is set to... |
| C-SPC | your current location |
| Jump to either end of the buffer (M-< or M->) | your previous location |
| Exit a search (C-s or C-r) | your previous location |
| Yank text | the beginning of the yanked region |
| Insert a buffer | the beginning of the inserted text |
As you can see, Emacs tries to be helpful: many commands that have the potential to take you long distances in text set mark so that a simple C-x C-x takes you back to where you were. Emacs makes it difficult to lose your place in a buffer: even if you take a detour, you don't need to scroll around in your buffer to get back to where you were.
Since mark can be set automatically, Emacs saves many previous locations so a mark you've set yourself isn't lost permanently. You can cycle through the mark ring, which contains the last 16 marks you've set in the current buffer:
| C-u C-SPC | Cycle through mark ring |
Mark serves another purpose: mark and point together delineate the region. Many commands operate only on the text in the region (i.e. between mark and point). You can set the region explicitly by setting mark (C-SPC) and then moving point elsewhere, but Emacs provides some commands which set the region for you:
| M-@ | Make region contain the current word |
| C-x h | Make region contain the entire buffer |
| M-h | Make region contain the current paragraph |
Other commands helpfully set the region as part of what they do. C-y (yank), as well as inserting a file or a buffer, all set the region to include the inserted text.
Undo
In most editors you can undo previous actions, then redo them if you'd like. Consider a sequence of edits you've made in a file; call the states of the file A, B, C, and D. At D, all the previous states of your file are still accessible via the 'undo' command (shown as a blue arrow):

If you undo some of your actions, each state of your file is still accessible, some via 'undo' and some via 'redo' (shown as a green arrow):

However, in most editors (but not in Emacs), after performing some undos, you then do anything other than 'undo' or 'redo', the states previously accessible with 'redo' are permanently lost:

Emacs uses a different undo model which does not have this deficiency. After any consecutive sequence of undos, when you perform any non-undo action, Emacs makes it so that the the undos you did are now themselves undoable, by "folding" the chain of states:

While this may seem terribly confusing, the thing to remember is that, no matter what you've done, 'undo' is always capable of getting you back to any previous state your buffer was in (unless Emacs has run out of memory to store the undo history). The principle here is that Emacs makes it very difficult to lose the work you've already done.
Undo is available under three different keys. The first one is preferable since it only requires two fingers:
| C-/ | Undo |
| C-_ | Undo |
| C-x u | Undo |
If you want to undo something you did in a particular region, you can use 'undo within region' to do it without affecting subsequent actions you did:
| C-u C-/ | Undo within region |
To learn more about undo, see (info "(emacs)Undo").
Incremental search
Typing C-s followed by some text starts incremental search. As you type, Emacs jumps to the next occurrence of whatever you have typed, as you are typing it (you may have seen similar behavior in Mozilla Firefox).
| C-s | Incremental search |
Within incremental search, you can type C-s again at any time to jump to the next occurrence.
When you've found what you're looking for, you can either type RET (or use almost any movement or editing command) to exit search at the occurrence you've found, or C-g ("cancel") to return to where your search started. If you exit search at the found occurrence, you can easily jump back to where you started with C-x C-x since incremental search sets mark appropriately.
There are various commands for issuing previously issued queries:
| C-s C-s | Search for most recently searched item |
| C-s M-p | Previous item in search history |
| C-s M-n | Next item in search history |
| C-h k C-s | Guide to more commands available in incremental search |
You can incremental search backwards with C-r. All commands available with C-s can be used with C-r as well. At any time during a forward search, you can type C-r to switch to a backwards search, and the opposite is true as well.
| C-r | Reverse incremental search |
See (info "(emacs)Incremental Search") for more information.
Instead of jumping through matches one by one, you can also choose to display them all at once. M-x occur prompts you for a search string, then displays in a separate buffer a list of all lines in the current buffer which contain that string (as well as their line numbers). Clicking on any occurrence takes you to that line in the buffer.
Search and replacement
| M-% | Query replace |
The query replace command prompts you for a search string and a replacement. Then, for each match in the buffer, you can choose whether or not to replace the search string. Here are some of the options available at each prompt:
- Type y to replace the current match.
- Type n to skip to the next match without replacing.
- Type q to exit without doing any more replacements.
- Type . to replace this match, then exit.
- Type ! to replace all remaining matches with no more questions.
See (info "(emacs)Query Replace") for more information about these options. You can also type ? anytime inside a search-and-replace operation to see a guide.
Regular expression search
Emacs allows you to search for regular expressions:
| C-M-s | Regular expression incremental search |
If you're new to regular expressions (regexps), they are a succinct way of searching for many different strings at once, but without typing out each one. A regular expression is a way of describing the form of what you're looking for. Regexp syntax allows you to make queries like the following:
- "Search for any uppercase letter between A and F."
- "Search for any sequence of five digits in a row at the end of a line."
- "Search for a string which looks like a phone number, i.e. is of the form '(xxx)xxx-xxxx' where each 'x' is some digit, and the parentheses and dash are optional."
See (info "(emacs)Regexps") for more information about regexp syntax.
If you're new to regexps, or you are constructing a particularly complicated regexp, you can use the regexp builder (M-x re-builder). This command pops up a separate window in which you can test out your regexp, and any matches in your original buffer will get highlighted as you edit your regexp.
Regular expression search and replacement
Regular expressions are handy for search, but they are far more powerful when combined with rule-based replacement. Emacs allows the replacement text to depend on the found text. You can do this by inserting special escape sequences in the replacement string, which Emacs will substitute appropriately:
| When you type this in a replacement string: | Emacs replaces it with: |
| \& | the original found text |
| \1, \2, etc. | the 1st, 2nd, etc. parenthesized subgroup in the found text |
| \# | the number of replacements done so far |
| \? | a string obtained by prompting the user on each match |
| \,(lisp-expression ...) | the result of evaluating an arbitrary function |
Here's an example. Suppose we have a buffer containing names like this:
George Washington John Adams Thomas Jefferson James Madison James Monroe
If we run M-x replace-regexp and replace the regexp \(\w+\) \(\w+\) with \,(upcase \2), \1, our buffer now looks like this:
WASHINGTON, George ADAMS, John JEFFERSON, Thomas MADISON, James MONROE, James
As you can see, regexp replacement is capable of doing some pretty sophisticated transformations on text! (Roughly, the search expression searches for two blocks of consecutive letters, separated by a space, and saves the words for later recall; the replacement string inserts an uppercased version of the second word, followed by a comma, followed by the first word.) You can find more cool regexp replacement demo examples here, or see (info "(emacs)Regexp Replace") for more information.
Useful features
Integration with common tools
Emacs is notable for its integration with many common tools. Not only can you invoke them from within the editor, Emacs usually helps you somehow use their output more effectively. Here are some examples:
- M-x shell
- Starts a shell in its own buffer. Emacs keeps track of "cd" (and other) commands and changes the working directory so that when you type C-x C-f (among other commands) it starts in your shell's working directory.
- M-x compile
- Invokes make (with targets and options of your choice) and displays output in a new buffer. Emacs identifies error lines containing filenames and line numbers, and you can click on them to jump directly to the corresponding buffer and line.
- M-x gdb
- Invokes gdb in a new buffer. You can use the gdb command line as usual in that buffer. However, Emacs lets you set breakpoints directly from your source buffers and shows execution by marking the active line in your source buffers.
- M-x grep
- Invokes grep and prints results in a new buffer. Like M-x compile, when you click on a match it opens up the correct file and takes you to the matching line.
- M-x woman
- View man pages. (So called because it lets you view man pages without ("w/o") the man utility.)
Here are some more assorted tools:
| M-x calculator | A calculator. |
| M-x calendar | A calendar. |
| M-x phases-of-moon | Shows upcoming quarters of the moon. |
Invoking shell commands
If you need to execute an arbitrary shell command, these commands will frequently save you the trouble of switching to an xterm or starting a new Emacs shell buffer:
- M-x shell-command or M-!
- Executes a command and displays the output in a new buffer.
- C-u M-x shell-command or C-u M-!
- Executes a command and inserts the output into your current buffer.
- M-x shell-command-on-region or M-|
- Executes a command, piping in the current region as input; displays the output in a new window.
- C-u M-x shell-command-on-region or C-u M-|
- Executes a command, piping in the current region as input; replaces the region with the output of your command.
Version control
Emacs helps you manipulate and edit files stored in version control. Emacs supports CVS, Arch, RCS, Subversion and more, but it offers a uniform interface, called VC, regardless of the version control system you are using.
Emacs automatically detects when a file you're editing is under version control, and displays something like this in the mode line: CVS-1.14 to indicate the version control system in use, and the current version.
M-x vc-next-action or C-x v v generally does the next thing you'd want to do with a file in version control: it commits the file (prompting you for a log message) if you've modified the file, and locks the file for you if you haven't acquired a lock. (You don't need the second use for CVS and other non-locking version control systems).
- C-x v =
- Displays a diff showing the changes you've made to the current file.
- C-x v ~
- Prompts you for a version number and shows you that version of the current file in another window.
See (info "(emacs)Version Control") for more information.
Tramp
GNU Emacs now includes Tramp, which allows you to edit remote files as if they were local. Anytime Emacs asks for a file, you can give a path which indicates a remote file, like so: /myname@remotehost:/remote/path/to/file. Emacs retrieves the file over SSH, FTP, or another method and takes care of saving it when you're done.
With Tramp, you can do remote editing without running an editor remotely, which would be undesirable if the connection had high latency, or if Emacs weren't installed or configured the way you wanted it at the remote end.
You can also use Tramp to edit local files with another user's permissions. You can edit files with root privileges via sudo: /sudo::/etc/file, or with anyone's privileges via su: /root@localhost:/etc/file.
See (info "(TRAMP)") for more information.
Emacs server
Some people like to keep only single instance of Emacs open and edit all their files in there. There are numerous advantages to doing so:
- You can kill/yank text between buffers, but only in the same instance of Emacs.
- Emacs remembers argument histories (what commands you've used, what files you've opened, terms you've searched for, etc.), but only within each instance.
- If you have many customizations, starting new instances of Emacs is slow.
Alas, when you type $ emacs in a shell to edit a file (or when $EDITOR is invoked by a program like mail or cvs), a new instance of Emacs is started, which can be a pain. You can prevent this from happening by using Emacs-client, which contacts an existing instance of Emacs and tells it instead to open the file for you:
- In your existing instance of Emacs, do M-x server-start. Or add (server-start) to your .emacs file to get it to do this automatically.
- To edit a file, type $ emacsclient FILENAME at a prompt. The file appears in one of your existing Emacs frames. You can also change $EDITOR to emacsclient instead of emacs to force applications that rely on it to use emacsclient.
- When you're done editing, type C-x #. Emacs will close the buffer and you can return to whatever you were doing in the shell.
For more information, see (info "(emacs)Emacs Server").
Macros
Macros are a way to remember a fixed sequence of keys for later repetition. They're really handy for automating some boring editing tasks.
| C-x ( | Start recording macro |
| C-x ) | Stop recording macro |
| C-x e | Play back macro once |
| C-x e e e... | Play back macro multiple times |
| M-0 C-x e | Play back macro over and over until it fails |
For example, this sequence of keys does the exact same transformation that we did with regular expression replacement earlier, that is, it transforms a line containing George Washington to WASHINGTON, George:
M-d C-d M-u , [SPC] C-y C-n C-a
After we record that key sequence as a macro, we can do C-x e e e e e to transform the buffer pictured earlier (since it has five lines).
See (info "(emacs)Keyboard Macros") for more information.
Narrowing
Narrowing restricts the view (and editing) of a buffer to a certain region. This is handy when you're only working with a small part of a buffer (e.g. a chapter in a book). Then commands like incremental search, or beginning-of-buffer or end-of-buffer don't lead you astray, and commands like search and replacement don't affect the entire file.
| C-x n n | Narrow buffer to the current region |
| C-x n w | Restore ("widen") buffer |
Registers
Registers are spaces where you can save text, buffer positions, window configurations, and other things for later use. Each register is named with a single character. As an example, here are commands for using registers to save window configurations (the exact tiling of windows you have on your screen, and what buffers are in the windows):
| C-x r w REGISTER | Store window configuration in REGISTER |
| C-x r j REGISTER | Load window configuration from REGISTER |
Commands for loading and storing text and other things in registers are analagous. See (info "(emacs)Registers") for more information.
Being unproductive with Emacs
Some random diversions:
| M-x tetris | Tetris |
| M-x hanoi | Towers of Hanoi game |
| M-x doctor | Emacs psychotherapist |
Common Emacs concepts and motifs
Now that we've picked up some tools, we can go back and learn some more about how Emacs does things.
Prefix arguments
As we've seen, prefix arguments are sometimes used to indicate repetition:
| C-u 10 C-f | Forward 10 characters |
| C-u M-a | Backward 4 sentences |
We've also seen a prefix argument used to modify the following command (the numeric argument, if provided, is ignored):
| C-/ | Undo |
| C-u C-/ | Undo within current region |
| M-x shell | Switch to shell buffer |
| C-u M-x shell | New shell buffer with specified name |
If you ever get confused, the command documentation for any command describes the effect of the prefix argument, if any. Look up a particular command with C-h f or a particular key with C-h k.
See (info "(emacs)Arguments") for more information.
Major modes
Every buffer has an associated major mode, which alters certain behaviors, key bindings, and text display in that buffer. The idea is to customize the appearance and features available based on the contents of the buffer. For example, there are major modes for editing particular programming languages. You've also seen M-x dired, M-x compile, and M-x shell, which all use their own major modes to make their buffers provide special features.
The current major mode is displayed in the mode line. The last item on the mode line should be one or more words in parentheses, like (Python Narrow). The first item is the name of the major mode.
You can switch modes in an existing buffer by using M-x MODENAME. MODENAME always ends in -mode:
| M-x java-mode | Mode for editing Java files |
| M-x python-mode | Mode for editing Python files |
| M-x text-mode | Mode for editing text files |
| M-x fundamental-mode | Mode with no specializations at all |
Emacs is actually really good at determining the right mode to use when you open a file, so you'll rarely have to use the above commands.
Many major modes are used for special purposes, so it doesn't make sense to switch to them directly with M-x MODENAME. Instead you'll use a separate command which will create a buffer and initialize it for you:
| M-x shell | Create a new shell buffer (or switch to an existing one) |
| M-x dired | Create a new Dired buffer |
Emacs ships with major modes for many widely used programming languages, markup languages, and configuration file formats. These major modes provide language-specific indentation rules and syntax highlighting, and other language-specific commands. Some examples:
| Language | Some special commands available |
| Lisp | Manipulate s-exps in various ways |
| Python | Indent, unindent blocks |
| HTML | Insert and close tags; preview in browser |
In almost all cases, major modes for unsupported formats are available as extension packages. You can find many of them on EmacsWiki.
See (info "(emacs)Major Modes") for more information.
Minor modes
Every buffer can also have any number of minor modes, which are extra pieces of functionality you can turn on or off, independently of each other and of the major mode. Minor modes are listed in the mode line after the major mode inside the parentheses. Here are a few commonly used ones:
- M-x auto-fill-mode
- Wraps your lines automatically when they get longer than 70 characters.
- M-x flyspell-mode
- Highlights misspelled words as you type.
- M-x follow-mode
- If you have a buffer displayed in two windows side by side, follow-mode forces them to scroll together such that the text displayed in the second window comes right after the text in the first window, and moving your cursor off the bottom of the left window causes it to appear at the top of the right window.
Some minor modes are global, i.e. they affect the behavior of your editor, rather than just that of a specific buffer.
| M-x icomplete-mode | In the M-x prompt (and elsewhere), show completions as you type |
| M-x iswitchb-mode | Show all buffer names when you use C-x b |
See (info "(emacs)Minor Modes") for more information.
The minibuffer
The minibuffer (the space at the bottom of the frame) is where Emacs prompts you for input in most situations: for a command, when you type M-x; for a file name, under M-x find-file; for an Elisp expression, under M-x eval-expression, etc. Here are some useful tips for minibuffer use:
- Most buffer editing and movement commands work. You can move around in, kill text from, and yank text to minibuffers.
- Often you can browse previous inputs for the current prompt, using M-p and M-n.
- Tab-completion is often available. If you're worried about the time it takes to type long command names, or you're worried about remembering the names (M-x normal-erase-is-backspace-mode!?) typing TAB at any time makes Emacs complete what you're typing to the best of its ability.
Learning more about Emacs
Even expert Emacs users are always learning new things about Emacs. Here are some of the tools which will help you help yourself when it comes to learning more about Emacs.
Emacs help facilities
If you've read this far, you are probably now thoroughly confused. If you have trouble remembering all those keys and commands, don't worry— Emacs has top-notch documentation, and context-sensitive help is always only a couple of keys away. Learn to use the documentation whenever you're unsure about a feature; that will help you remember things sooner (and give you a crutch in the meantime).
- C-h k
- Type any key command to show documentation for the command associated with that key. This is useful for looking up the full name of the command, figuring out what it does, or finding any other keys which are bound to it.
- C-h f
- Type any command name to show documentation for it. The documentation explains what the command does and what keys (if any) are bound to it.
By using the above two commands, you can figure out both the keybindings and the full name of a command if you only remember one of them. This is great for reinforcing what you're learning with Emacs: if you ever have any doubt about what a key or command does, you can look it up with C-h k or C-h f. The documentation gives a precise specification of what each command does, and may even mention some cool features of the command that you didn't know.
- C-h m
- Describes features available in the current major and minor modes.
- C-h b
- Describes the list of keybindings, that is, what every key does in the current context.
- C-h a
- ("apropos") Search for commands by keyword. Useful if you're looking for a command and you don't remember its name.
- C-h C-h
- Get a list of all the help facilities available in Emacs.
You can also read the GNU Emacs manual in Emacs with (info "(emacs)"). Alternatively, type M-x info and select the entry for emacs. The manuals are very well-written and complete, although, as with much technical documentation, it's can be difficult to understand the significance or usefulness of a feature just from reading about it in the manual.
Emacs ships with a FAQ which explains how to do many common tasks. See (info "(efaq)Common requests").
In the event of an emergency...
Since Emacs UI is somewhat different from that of other modern applications, and it's very keyboard-heavy, you may get the deer-trapped-in-headlights feeling when you type the wrong key. Here are some tips:
- If you executed a wrong command and Emacs has modified your buffer in a way you didn't want, type C-/ (or any of the other keys for undo) to undo that change.
- If you typed a wrong key which is a prefix key (e.g. C-x) or you activated a command which is now prompting you for input (e.g. Find file: ...), type C-g, repeatedly if necessary, to cancel.
C-g also cancels a long-running operation if it appears that Emacs has frozen.
After you recover from typing wrong keys, if you want to figure out what you did, type M-x view-lossage, which displays the most recent keys you've typed.
Common problems
Due to the keyboard or terminal configuration, you may find that some keys seem to do the wrong thing. This problem is especially common when using Emacs remotely over SSH.
Is your DEL key not working? (Sometimes, typing DEL brings up a help screen, as if you typed C-h.) Try M-x normal-erase-is-backspace-mode.
Is your meta key not working? Any time you are called upon to type meta in combination with other keys, you can instead type ESC, then the other keys without meta. For example, ESC x is the same as M-x, and ESC C-s is the same as C-M-x.
Migrating to Emacs
Emacs has a number of options for easing the transition from other editing environments.
Emacs for Windows users
In Windows, the bread and butter editing commands are C-z, C-x, C-c, and C-v. Unfortunately, these keys are frequently used in Emacs for other purposes (suspend, prefix key, prefix key, and next page). You can get those keys back for Undo, Cut, Copy, and Paste by turning on "CUA mode" from the Options menu. CUA mode also lets you make a selection by using Shift and movement keys, as you would do on Windows.
Since C-x and C-c are so integral to Emacs operation (they are prefix keys for many commands), CUA mode only binds C-x and C-c to Cut and Copy, respectively, when you have selected some text.
You can learn more about CUA mode by typing C-h f cua-mode RET.
Emacs for vi/vim users
Viper (M-x viper-mode) is a set of modes for emulating vi editing behavior in Emacs. It provides different levels of vi-adherence, depending on how vi-like you want your Emacs to be.
For more information about Viper, see (info "(viper)Viper").











