Windows Navigation in Emacs

Efficient switching between windows in Emacs

Last week there were some quite interesting posts about windows management in Emacs — Emacs’ windows navigations and some Emacs zen (a review by Irreal), Emacs window management tweaking, for instance.

In this regard, I’ve decided to share my configuration for the issue.

For switching between windows in Emacs I use the ace-window package by Oleh Krehel aka abo-abo, a renowned author of such gems as Hydra, avy, Swiper, and others. Most of these packages have found their place in my .emacs.

My configuration is quite simple.

(use-package avy :ensure t)
(use-package ace-window :ensure t
  :after avy
)

(global-set-key [(f2)]  #'ace-window)

The main function, ace-window is meant to replace other-window by assigning each window a short, unique label. When there are only two windows present, other-window is called… If there are more, each window will have its first label character highlighted. Once a unique label is typed, ace-window will switch to that window.

By default, ace-window uses numbers for window labels so the window labeling is intuitively ordered.

I’ve bound ace-window to <F2>. Why <F2>? For ergonomic reasons. On most keyboards, the numeric keys (1-2-3-…) are located right under the <F2> key. It would be easy to press <F2> then, for example, 2 using the same finger.

Window labels are in the top left corner of each window (shown in red). The frame is dimmed when activating `ace-window`.

The ace-window package has many other options; you can find more detailed information at the ace-window GitHub repository.

Happy emacsing!

— The Emacs Cat.