Weekly Emacs tip #20: Emacs window management — quickly moving to the right window with ace-window
In the previous three Emacs tips, I discussed various ways to select a window:
other-window
bound to the painfulC-x o
, which cycles from one window to the next;- setting the
mouse-autoselect-window
variable tot
for “focus follows mouse”; - the
windmove
package that allows you to use a key prefix (super ctrl
in my config) with the arrow keys to move the focus from one window to another adjacent one; and another prefix (super ctrl meta
) + arrow keys to move a buffer (the contents of a window) from one window to an adjacent one.
In this tip, I’ll cover the ace-window
package, which ended up being the way I most often switch between windows, or kill them.
The way ace-window
works is rather simple: load the package and bind a key to the ace-window
command (I use M-o
as suggested in the package’s README
). Then, when you press that shortcut, a “special” character appears in each window’s top left corner. Next, press the character’s key and there you are: that window is now active.
In the screenshot below, you see the three big blue letters a
, s
, d
in the three buffers. When I pressed M-o
, my cursor was in the top right window marked by s
, in fact, you can still see the white rectangle next to that letter. Now, if I would press a
, I would switch to the Org mode buffer with the text of this post.

Figure 1: Three Emacs windows before using ace-window
.
The two main things I like about ace-window
are its simple shortcuts —which is much easier to press than either the one for other-window
or any of the windmove
key combos— and the fact that I don’t need to think about “direction”. I just look at the window I intend to switch to, press M-o
, see the blue letter and press it. That’s all there is to it.
This is how I load and configure the package in my ~/.emacs
file:
;;; Window switching using ace-window ;;; https://github.com/abo-abo/ace-window (use-package ace-window :bind ("M-o" . ace-window) ("M-O" . ace-delete-window) :custom ;; Don't cycle through other frames, stick to the current one. (aw-scope 'frame) ;; Don't use numbers to label the windows, but the keys on home row. (aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)) :config ;; Set the colour and size of the font used to display the selection ;; characters (set-face-attribute 'aw-leading-char-face nil :foreground "deep sky blue" :weight 'bold :height 3.0) )
In the :bind
section, you bind Alt with the capital O
to ace-delete-window
, which means I can easily delete a window that I’m not using, without the need to first switch to it. Very powerful! The aw-keys
line sets the letters ace-window
should show. Here, I set them to the keys on home row so I can quickly press them, without the need to move my fingers or hands too much. I haven’t run into a case where I had more windows than these letters could cover.
The set-face-attribute
line sets font attributes (a “face” is Emacs speak for a font) for the selection letters: the colour and weight and size. You can, of course adjust these to your taste and theme.
There’s one more thing to note about ace-window
, and that is that it allows you to do more than just switching windows. If you press ?
after pressing M-o
, you’ll see a list of one-key actions. For example, x
will kill the window whose letter you select, m
will swap the contents of the current window with the one corresponding to the key you press, and F
will split the window fairly into two windows. I don’t use these very often as they aren’t (yet?) part of my muscle memory, but it is good to know they exist. Maybe they’ll replace the C-x 0
, 1
, 2
, 3
, keybindings (and more) one day.
And, as a last point: Karthink’s blog post on Emacs window management has a section on ace-window too (and more!).
No Comments