7.1 Buffers Hold Your Work

A buffer holds the content or application view you are working with. It might contain a file, an Info manual, a Dired listing, a Web page, mail search results, a shell session, or Help text. Some buffers visit files; others exist only within the Emacs session.

The mode line identifies the selected buffer and its major mode. Press C-e m to hear it. These are the main ways to change buffers:

C-x b

Switch to another buffer by name. Completion lets you narrow the choices instead of remembering the complete name.

C-x C-b

Open a buffer list. In that list, use C-h m to learn its navigation, selection, saving, and cleanup commands.

C-x k

Close a buffer that you no longer need. Emacs asks before discarding unsaved file changes.

Switching buffers does not close the one you left. You can work on a document, consult Help or a reference, visit a shell, and return to the document without reopening it.

7.1.1 Cycle Between Buffers of the Same Kind

When several buffers use the same major mode, you can cycle among them without recalling their names. This is useful for comparing Org notes, visiting several Dired directories, or moving between source files.

Press C-e n to select the next buffer with the same major mode, or C-e p to select the previous one. For example, from an Org buffer these commands visit other Org buffers, skipping all buffers that do not use the same major mode. Buffers are grouped by major mode, not by project or directory.

After the first command, you only need the final letter: n continues forward and p moves backward. You can change direction at any time, and cycling wraps around when you reach the end. For example, C-e n n p moves forward twice, then returns to the buffer you just left.

To navigate without the major-mode filter, use C-e . for next buffer or C-e , for previous buffer. You can then repeat with just . or ,, in the same way as n and p. You can also switch between these controls while cycling.

The temporary buffer-selection controls also include b to select a buffer by name, f to open a file, k to kill a buffer, and o to change windows.

Press C-g when finished to return to normal editing. A key outside the temporary buffer-selection controls also ends cycling and performs its normal action. To choose a particular buffer by name, use C-x b.