Working with Multiple Buffers

You already know how to get into Emacs by typing emacs filename. If you want to create a second buffer that contains a file, simply type C-x C-f to find the file. Emacs automatically creates a second buffer and moves you there. If you already have a copy of the file in a buffer, C-x C-f just moves you to the existing buffer. This move is sensible and probably really what you want anyhow; if C-x C-f read the file from disk every time, you could end up with many versions of the same file that were each slightly different. If the filename you give C-x C-f doesn’t exist, Emacs assumes you want to create a new file by that name and moves you to a blank buffer. (If you make a mistake typing the filename, type C-x C-v to get the right one.)

C-x C-f is always followed by a filename. The command for moving between buffers, C-x b, is followed by a buffer name. Did you realize that the mode line doesn’t display filenames but only buffer names? Some versions of Emacs show both, but GNU shows only the buffer name. The buffer name and the filename, if any, are the same unless you change them (see Section 4.2.3 later in this chapter).

You can do the following with C-x b:

If you type C-x b followed by


A new buffer name

Creates a new buffer that isn’t connected with a file and moves there.

The name of an existing buffer

Moves you to the buffer (it doesn’t matter whether the buffer is connected with a file or not).

To move between the buffers, ...

Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.