Next: , Up: Buffers


14.1 Creating and Selecting Buffers

C-x b buffer <RET>
Select or create a buffer named buffer (switch-to-buffer).
C-x 4 b buffer <RET>
Similar, but select buffer in another window (switch-to-buffer-other-window).
C-x 5 b buffer <RET>
Similar, but select buffer in a separate frame (switch-to-buffer-other-frame).

To select the buffer named bufname, type C-x b bufname <RET>. This runs the command switch-to-buffer with argument bufname. You can use completion on an abbreviation for the buffer name you want (see Completion). An empty argument to C-x b specifies the buffer that was current most recently among those not now displayed in any window.

To select a buffer in a window other than the current one, type C-x 4 b bufname <RET>. This runs the command switch-to-buffer-other-window which displays the buffer bufname in another window. By default, if displaying the buffer causes two vertically adjacent windows to be displayed, the heights of those windows are evened out; to countermand that and preserve the window configuration, set the variable even-window-heights to nil.

Similarly, C-x 5 b buffer <RET> runs the command switch-to-buffer-other-frame which selects a buffer in another frame.

You can control how certain buffers are handled by these commands by customizing the variables special-display-buffer-names, special-display-regexps, same-window-buffer-names, and same-window-regexps. See Force Same Window, and Special Buffer Frames, for more about these variables. In addition, if the value of display-buffer-reuse-frames is non-nil, and the buffer you want to switch to is already displayed in some frame, Emacs will raise that frame.

Most buffers are created by visiting files, or by Emacs commands that want to display some text, but you can also create a buffer explicitly by typing C-x b bufname <RET>. This makes a new, empty buffer that is not visiting any file, and selects it for editing. Such buffers are used for making notes to yourself. If you try to save one, you are asked for the file name to use. The new buffer's major mode is determined by the value of default-major-mode (see Major Modes).

Note that C-x C-f, and any other command for visiting a file, can also be used to switch to an existing file-visiting buffer. See Visiting.

Emacs uses buffer names that start with a space for internal purposes. It treats these buffers specially in minor ways—for example, by default they do not record undo information. It is best to avoid using such buffer names yourself.