Emacs: Switch Buffer
This page is a tutorial on switching buffers in emacs. If you don't know what buffers are, first see: Emacs: List Buffers.
switch-to-buffer 【Ctrl+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 will show a list of candidates AUTOMATICALLY as you type (no need to press Tab ↹ first).
- First, call
ido-modeto turn it on.
- Then, call
ido-switch-buffer【Ctrl+x b】 to switch buffer.
When ido-mode is on, the key 【Ctrl+x b】 will call ido's version (
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:
- 【→】 → Select the next choice.
- 【←】 → Select the previous choice.
- 【↑】 → Go to the buffer you switched to last time. 【↓】 for next.
- 【Enter ↵】 → Use the first choice.
- 【Ctrl+f】 → stop suggestion. useful for creating new file. 【Ctrl+b】 to go back to buffer selection mode.
- 【Ctrl+d】 → switch to open directory mode.
- 【Ctrl+g】 → cancel.
How to create a new file with ido-mode?
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.
(require 'ido) ;; 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)
Stop ido Suggestion When Writing File
When you call
write-file 【Ctrl+x Ctrl+w】
(aka “save as”), when ido is on, it'll make suggestions.
This is annoying because usually you don't want the name to be a existing file.
Here's how to stop ido suggestion when calling
(require 'ido) ;; stop ido suggestion when doing a save-as (define-key (cdr ido-minor-mode-map-entry) [remap write-file] nil)
Switching Next/Previous User Buffers
See also: Emacs: Next/Previous User Buffer
Create New Empty Buffer
or, buy something from Best Keyboard for Emacs