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.

KeyPurpose
mMark
uUnmark
* 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

Open File topics

  1. Emacs: File Manager, dired
  2. Emacs: Bookmark Tutorial
  3. Emacs: Open Recently Opened File
  4. Emacs: Open File Fast
  5. Emacs: Open Last Closed File
  6. Emacs: Open File Path Under Cursor

Buffer topics

  1. Emacs: List Buffers
  2. Emacs: Switch Buffer
  3. Emacs: New Empty Buffer
  4. Emacs: Next/Previous User Buffer
Like it? Buy Xah Emacs Tutorial. Thanks.