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

Open File topics

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

Buffer topics

  1. List Buffers
  2. Switch Buffer
  3. New Empty Buffer
  4. Next/Previous User Buffer
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.