Weekly Emacs tip #17: Emacs window management – the basics
Let’s start with a reminder of Emacs terminology. In Emacs parlance, a “frame” is what we normally call a window: the thing you can move around with your mouse (or with keys if you love tiling window managers). A “window” in Emacs, is part of an Emacs frame. By default, a frame starts with a single window, but various commands in Emacs will spawn a new window, for example running M-x magit
, one of the C-h
help keys, or M-x R
will split the frame into two parts and those two parts are what Emacs calls a window. Each window can display its own buffer, but it is also perfectly possible to have two windows showing the same buffer, but, for example, at different positions. I find this especially helpful for large source code files. As each buffer keeps track of its own cursor location, this allows you to e.g. look up a function definition in one place and edit code in another. It also makes it possible to easily edit the same file in two places.
In the screenshot below, the Emacs frame is split into three windows (each showing a different buffer): the one with the text for this blog post occupies the top half of the frame. The bottom half is split vertically into two equal parts, one with a vterm
shell buffer and one with the *scratch*
buffer. Notice how each buffer still has its own modeline, although it is cut off for the two bottom buffers due to the limited space. Also note that there is only one echo area, at the bottom (where it says “Saving all Org buffers… done”).

Figure 1: Screenshot of an Emacs frame with 3 windows. The top window shows the Org mode buffer with the text of this blog post. The first window below it (the one on the left) contains a vterm
buffer, and the lower right one shows the *scratch*
buffer.
Aside from letting (or having) Emacs create these windows for you, you can, of course, create them yourself as well. The main keyboard shortcuts for that are C-x 2
and C-x 3
. The first one runs the command split-window-below
. As can be inferred by the name, it creates a new window below the current one; a horizontal split, so to say. Conversely, C-x 3
runs split-window-right
: a vertical split. So, in order to end up in the window configuration shown in the screenshot, I first ran C-x 2
to create the horizontal split. Next, I focussed that new window at the bottom and created a vertical split with C-x 3
.
OK, so if this is how to create new windows, how does one remove windows? This is done with the delete-window
command, bound to C-x 0
, which deletes the window that is currently focussed (i.e. the one in which the point/cursor is active).
So, with C-x 0
, C-x 2
and C-x 3
accounted for, the next question is: what does C-x 1
do? Well, the function which it invokes is quite telling: delete-other-window
. Or, in a few more words: it deletes all windows, except the one that has focus.
Creating windows is fun, but once you have split your frame into a bunch of windows, how do you move from one to the next? Clicking the mouse certainly works, but what is the “Alt-Tab” of Emacs? How can we switch between windows using the keyboard? The default answer to that is C-x o
(that’s a lowercase o, not a zero), which runs the other-window
command. Pressing it multiple times cycles through all available windows. However, I’m not a big fan of this shortcut: to many keypresses for something I do very often. Therefore, at some point in time, I bound M-o
to the other-window
command in my ~/.emacs
.
A drawback of the other-window
function itself, is the fact that it cycles through the windows in order. With only two windows open this is fine, of course, but with three or more, going back to the previous window means you’ll need to cycle through the others first. You can use a negative prefix argument to the command: C-u -1 C-x o
(or, equivalently, M- M-1 C-x o
, that is: hold Alt and press minus 1, followed by C-x o
) to tell other-window
to move one window backwards1, but in my opinion, that’s too many keypresses to be comfortable, even with my M-o
shortcut. In a future tip, I will cover two alternatives I use: the ace-window
package (described in Karthink’s blog post as “the endgame for keyboard-driven Emacs window control”) and the built-in windmove
.
Emacs’s windows turn out to be quite a complicated topic and several knowledgeable people have written blog posts to try and help clarify it further.
- “The Emacs Window Management Almanac” by Karthink
- “Demystifying Emacs’s Window Manager” by Mickey Petersen
- The Emacs manual chapter 29: Windows
Footnotes:
Instead of -1 you can specify other numbers as well.
Positive numbers move that many windows forward in the cycle, negative
numbers move that many windows backwards.
No Comments