When you visit a file with C-x C-f
, Emacs loads the file into a new
buffer created just for that file. Existing buffers are not destroyed,
but persist and can be switched to with C-x b
. Emacs will prompt you
for a buffer name to switch to; tab-completion works here as it does
in other places. One tip that I wish I had known when I first started
using Emacs is to use a special mode called iswitch mode to help
manage buffers. Since it's not uncommon to have dozens of buffers in
an Emacs editing session, you can easily forget buffer names. With
iswitch mode enabled, a C-x b
displays a list of buffers in the echo
area that changes in real-time as you type characters. You don't even
have to type the first few letters of a buffer name, any substring of
a buffer name will do. To enable iswitch mode, type the extended
command M-x iswitchb-mode
(we'll see later how to permanently enable
modes like this in a startup file). To see a list of all buffers, type
C-x C-b
. The buffer list will appear in a new window. Here is a list
of some useful buffer commands:
C-x b | Switch to another buffer |
C-x C-b | Display buffer list |
C-x k | Kill current buffer (Emacs prompts for confirmation) |
M-x iswitchb-mode | Enable iswitch mode, for smart buffer name completion with C-x b |