Emacs Advent Calendar 08: Managing Buffers
In Emacs, text is contained and edited inside buffers. Most buffers are created by visiting a file, others are used to display information or interact with external programs like the shell.
To switch to a buffer, use
C-x b BUFFER <RET> (the usual
Minibuffer commands work). If
BUFFER does not exist, Emacs
will create it. Note however that no file will be associated with this
buffer (unlike when visiting a file with
C-x C-f). If you try
to save the buffer, Emacs will ask for a file name.
To cycle through buffers, use the
C-x <LEFT> and
<RIGHT> commands. Here,
C-x <LEFT> selects the previous
buffer (the one that was selected last) while
moves in the other direction.
Buffers are closed ("killed" in Emacs terminology) with
C-x k BUFFER
<RET>. The default argument is the current buffer. The command
M-x kill-some-buffers loops through all buffers, offering to
kill each one.
To display a list of all existing buffers, use
C-x C-b. To
only list buffers that are visiting files, use a
C-u C-x C-b. The
*Buffer List* buffer offers special
keybindings to quickly manipulate the list. Some basic ones to know
|d||flag buffer for killing|
|s||flag buffer for saving|
|u||remove flags from buffer|
|n, <DOWN>||move to next line|
|p, <UP>||move to previous line|
|x||save and/or kill all flagged buffers|
|o||select buffer in other window|
|S||sort column at point|
|g||refresh buffer list|
|q||quit buffer list|
This text by Ludger Sandig is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.