Emacs: Switch Buffer, ido-mode

By Xah Lee. Date: . Last updated: .

This page is a tutorial on switching buffers in emacs. If you don't know what buffers are, first see: Emacs: List Buffers.

Call switch-to-bufferCtrl+x b】 to switch to a different buffer. Emacs will prompt you for a name, and you can press Tab ↹ for name completion.

A better command to switch buffer is ido-switch-buffer in ido-mode.

ido-switch-buffer will show a list of candidates AUTOMATICALLY as you type (no need to press Tab ↹ first).

emacs ido-mode show vertical 2016-06-27 52017
Emacs ido-mode's ido-switch-buffer in action.
  1. First, call ido-mode to turn it on.
  2. Then, call ido-switch-bufferCtrl+x b】 to switch buffer.

When ido-mode is on, the key 【Ctrl+x b】 will call ido's version (ido-switch-buffer).

Ido Hotkeys

When ido-switch-buffer is called, it will prompt for a choice of buffer name.

Here's the most useful ido hotkeys when in the prompt:

  1. 】 → Select the next choice.
  2. 】 → Select the previous choice.
  3. 】 → Go to the buffer you switched to last time. 【】 for next.
  4. Enter ↵】 → Use the first choice.
  5. Ctrl+f】 → stop suggestion. useful for creating new file. 【Ctrl+b】 to go back to buffer selection mode.
  6. Ctrl+d】 → switch to open directory mode.
  7. Ctrl+g】 → cancel.

How to create a new file with ido-mode?

Call ido-switch-buffer, then press 【Ctrl+f】 to stop suggestion. This is useful when creating new file.

When you want to open a directory, you can press 【Ctrl+d】.

Set ido-mode as Default

To make ido-mode default for switching buffer, put the following in your emacs init:

;; make buffer switch command auto suggestions, also for find-file command
(ido-mode 1)

Make Ido Suggestions Display Vertically

Ido can show suggestions vertically. This makes it easier to read.

Put the following in your emacs init file.

;; make ido display choices vertically
(setq ido-separator "\n")

;; display any item that contains the chars you typed
(setq ido-enable-flex-matching t)

(setq max-mini-window-height 0.5)

Switching Next/Previous User Buffers

See also: Emacs: Next/Previous User Buffer

Create New Empty Buffer

Emacs: New Empty Buffer

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from my keyboard store.