In this article, we’re going to take a look at windows and buffers in Emacs and the differences between these two concepts. We’ll also look at switching buffers and closing buffers. Let’s get into it.
Table of Contents
Buffers vs. Windows
In Emacs, the word window means something different from what you might expect.
- A buffer is an open file (or any piece of content) held in memory. You can have dozens of buffers open at once.
- A window is a pane on your screen that displays a buffer. One frame can contain multiple windows.
Think of it this way: buffers are like tabs in a browser, but you can display more than one at a time by splitting the frame into windows.
Switching Between Buffers
To switch to a different open buffer:
| Key | Action |
|---|---|
C-x b |
Switch to a named buffer |
C-x C-b |
List all open buffers |
C-x → |
Cycle to the next buffer |
C-x ← |
Cycle to the previous buffer |
When you press C-x b, Emacs shows a prompt in the minibuffer. Start typing the buffer name and press RET to switch to it. You can also press TAB for auto completion options.
Closing a Buffer
To close (kill) the current buffer:
C-x k RET
Emacs asks which buffer to kill and suggests the current one. Press RET (the return or Enter key) to confirm.
If the buffer has unsaved changes, Emacs will ask whether you want to save before closing.
Splitting the Frame into Windows
You can divide the Emacs frame into multiple panes to see two files side by side.
| Key | Action |
|---|---|
C-x 2 |
Split the current window horizontally (top and bottom) |
C-x 3 |
Split the current window vertically (left and right) |
C-x 1 |
Close all other windows, keep only the current one |
C-x 0 |
Close the current window |
Moving Between Windows
Once you have split the frame, move focus between windows with:
C-x o
Press it repeatedly to cycle through all open windows.
Opening a File in Another Window
To open a file without leaving the current window:
C-x 4 f
Emacs splits the frame and opens the file in the new window, with focus moving there automatically.
The Buffer List
Press C-x C-b to open a full buffer list. Each line shows:
- Whether the buffer has unsaved changes (
*in the first column) - Whether the buffer is read-only (
%) - The buffer name
- The file it is visiting, if any
From this list you can press d to mark a buffer for deletion, then x to execute deletions. Press q to close the buffer list.
What Comes Next
Once you are comfortable moving between buffers and windows, search and replace becomes the next essential skill — it works across whatever is currently visible in a buffer.