Skip to main content

19.5 Operating on Several Buffers

M-x buffer-menu​

Begin editing a buffer listing all Emacs buffers.

M-x buffer-menu-other-window​

Similar, but do it in another window.

The Buffer Menu opened by C-x C-b (see List Buffers) does not merely list buffers. It also allows you to perform various operations on buffers, through an interface similar to Dired (see Dired). You can save buffers, kill them (here called deleting them, for consistency with Dired), or display them.

To use the Buffer Menu, type C-x C-b and switch to the window displaying the *Buffer List* buffer. You can also type M-x buffer-menu to open the Buffer Menu in the selected window. Alternatively, the command M-x buffer-menu-other-window opens the Buffer Menu in another window, and selects that window.

The Buffer Menu is a read-only buffer, and can be changed only through the special commands described in this section. The usual cursor motion commands can be used in this buffer. The following commands apply to the buffer described on the current line:

d​

Flag the buffer for deletion (killing), then move point to the next line (Buffer-menu-delete). The deletion flag is indicated by the character ‘D’ on the line, before the buffer name. The deletion occurs only when you type the x command (see below).

C-d​

Like d, but move point up instead of down (Buffer-menu-delete-backwards).

s​

Flag the buffer for saving (Buffer-menu-save). The save flag is indicated by the character ‘S’ on the line, before the buffer name. The saving occurs only when you type x. You may request both saving and deletion for the same buffer.

x​

Perform all flagged deletions and saves (Buffer-menu-execute).

u​

Remove all flags from the current line, and move down (Buffer-menu-unmark). With a prefix argument, moves up after removing the flags.

DEL​

Move to the previous line and remove all flags on that line (Buffer-menu-backup-unmark).

M-DEL​

Remove a particular flag from all lines (Buffer-menu-unmark-all-buffers). This asks for a single character, and unmarks buffers marked with that character; typing RET removes all marks.

U​

Remove all flags from all the lines (Buffer-menu-unmark-all).

The commands for removing flags, d and C-d, accept a numeric argument as a repeat count.

The following commands operate immediately on the buffer listed on the current line. They also accept a numeric argument as a repeat count.

~

Mark the buffer as unmodified (Buffer-menu-not-modified). See Save Commands.

%​

Toggle the buffer’s read-only status (Buffer-menu-toggle-read-only). See Misc Buffer.

t​

Visit the buffer as a tags table (Buffer-menu-visit-tags-table). See Select Tags Table.

The following commands are used to select another buffer or buffers:

q​

Quit the Buffer Menu (quit-window). The most recent formerly visible buffer is displayed in its place.

RET​

f​

Select this line’s buffer, replacing the *Buffer List* buffer in its window (Buffer-menu-this-window).

o​

Select this line’s buffer in another window, as if by C-x 4 b, leaving *Buffer List* visible (Buffer-menu-other-window).

C-o​

Display this line’s buffer in another window, without selecting it (Buffer-menu-switch-other-window).

1​

Select this line’s buffer in a full-frame window (Buffer-menu-1-window).

2​

Set up two windows on the current frame, with this line’s buffer selected in one, and a previously current buffer (aside from *Buffer List*) in the other (Buffer-menu-2-window).

b​

Bury this line’s buffer (Buffer-menu-bury) (i.e., move it to the end of the buffer list).

m​

Mark this line’s buffer to be displayed in another window if you exit with the v command (Buffer-menu-mark). The display flag is indicated by the character ‘>’ at the beginning of the line. (A single buffer may not have both deletion and display flags.)

v​

Select this line’s buffer, and also display in other windows any buffers flagged with the m command (Buffer-menu-select). If you have not flagged any buffers, this command is equivalent to 1.

The following commands affect the entire buffer list:

S​

Sort the Buffer Menu entries according to their values in the column at point. With a numeric prefix argument n, sort according to the n-th column (tabulated-list-sort).

}​

Widen the current column width by n (the prefix numeric argument) characters.

{​

Narrow the current column width by n (the prefix numeric argument) characters.

T​

Delete, or reinsert, lines for non-file buffers (Buffer-menu-toggle-files-only). This command toggles the inclusion of such buffers in the buffer list.

Normally, the buffer *Buffer List* is not updated automatically when buffers are created and killed; its contents are just text. If you have created, deleted or renamed buffers, the way to update *Buffer List* to show what you have done is to type g (revert-buffer). You can make this happen regularly every auto-revert-interval seconds if you enable Auto Revert mode in this buffer, as long as it is not marked modified. Global Auto Revert mode applies to the *Buffer List* buffer only if global-auto-revert-non-file-buffers is non-nil. See global-auto-revert-non-file-buffers, for details.