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 Alt+x eval-region. Now, Alt+x 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.

Alt+x 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

Buffer Topic

  1. List Buffers
  2. Switch Buffer
  3. Ido Mode
  4. New Empty Buffer
  5. Next/Previous User Buffer

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp