17.2 Buffers

In Emacs, the concept of “buffers” is essential. Every file that you open is loaded into its own buffer. Furthermore, Emacs has several special buffers, which do not contain a file but are used for other things. Such special buffers usually have a name that starts and ends with an asterisk. For example, the buffer that Emacs shows when it is first started, is the so-called *scratch* buffer. In the *scratch* buffer, you can type text in the normal way, but text that is typed there is not saved when Emacs is closed.

There is one other special buffer you need to know about, and that is the minibuffer. This buffer consists of only one line, and is always on the screen: it is the very last line of the Emacs window, below the status bar for the current buffer. The minibuffer is where Emacs shows messages for the user, and it is also the place where commands that require some user input are executed. For example, when you open a file, Emacs will ask for its name in the minibuffer.

Switching from one buffer to another can be done with the command C-x b. This will prompt you for the name of a buffer (a buffer's name is usually the name of the file you are editing in it), and it gives a default choice, which is normally the buffer that you were in before you switched to or created the current buffer. Just hitting Enter will switch to that default buffer.

If you want to switch to another buffer than the default offered by Emacs, just type its name. Note that you can use so-called Tab-completion here: type the first few letters of the buffer's name and hit Tab; Emacs will then complete the name of the buffer. Tab completion works everywhere in Emacs where it makes sense.

You can get a list of open buffers by hitting C-x C-b. This command will usually split the screen in two, displaying the buffer you were working in in the top half, and a new buffer called *Buffer List* in the bottom half. This buffer contains a list of all the buffers, their sizes and modes, and the files, if any, that those buffers are visiting (as it is called in Emacs). You can get rid of this split screen by typing C-x 1.

Note

Under X, the list of buffers is also available in the Buffer menu in the menu bar.