Emacs: List Buffers

By Xah Lee. Date: . Last updated: .

This page is a tutorial on managing buffers in emacs.

In emacs, every file is shown in a “buffer”. (You can think of “buffer” as opened file or tabbed window without the tab.)

2 most useful commands for buffer are:

  1. list-buffersCtrl+x Ctrl+b
  2. switch-to-bufferCtrl+x b

Try them now.

Close a Buffer

To close a buffer, use:

kill-bufferCtrl+x k】 → close the current buffer.

List Buffers: ibuffer

The command ibuffer is a improved version of list-buffers. It colors the files by type.

emacs ibuffer 2015-10-13
A screenshot of ibuffer mode.

To make ibuffer as default, put the following in your init file:

(defalias 'list-buffers 'ibuffer) ; make ibuffer default

Select the code and call eval-region. Now, call list-buffers.

Batch Operation on Buffers

You can do operation in batch to the marked ones. Example:

emacs ibuffer operate 2015-04-09
Emacs ibuffer “Operate” menu.
emacs ibuffer mark 2015-04-09
Emacs ibuffer “Mark” menu.

Call describe-mode to see a full list of ibuffer commands.

Here's most useful ibuffer commands.

* uMark unsaved
SSave marked buffer
DClose marked buffers

In ibuffer, the key sequence 【* u S D】 will save all unsaved files and close them. This is particularly useful after you've done a find replace on hundreds of files with dired-do-query-replace-regexp. 〔►see Emacs: Find Replace Text in Directory

Buffer Switching: ido-mode

Emacs: Switch Buffer

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs