Quick Emacs Buffer Switching with ace-jump-mode
I recently put in the effort to turn this into a more convenient Emacs lisp package. Enhancements include:
- No longer are your pre-existing
perspectivemode is optional.
- When the
ace-jump-buffermenu is activated,
C-gor any non-found ace-jump key-binding will clear
ace-jump-modeand dismiss buffer menu.
This article’s code should only be entertained as a reference to the initial thought experiment. Grab the latest version on Github:
Or install directly from MELPA:
Beyond typing and text-editing related commands, switching buffers is my most common Emacs action. I’m constantly hopping back and forth between scripts and stylesheets and templates, popping into shells, etc.
ido-mode’s fuzzy-match choosing is typically the de facto standard of this kind of interface: after triggering an appropriate binding you are usually several keystrokes from naming and selecting your target. But life is short, can we do this faster?
There are also buffer flipping managers like
iflip that behave much like beloved ⌘+TAB application switching, but when buffers start to pile up it can take a handful of repeated commands to get where you are going.
ace-jump-mode got me thinking. I’m continually finding it to be super useful in my day to day workflow. In just 2 or 3 keystrokes you can put your cursor anywhere in your Emacs environment. Then I realized I could bend it to allow me to hop to any buffer in 1 character. Here it is what I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
So what’s going on here?
bs is a lightweight, built-in emacs lisp package for buffer switching, seemingly a predecessor to
ibuffer. I choose it for its simplicity and configuration. As I rely heavily on
perspective for keeping my workspaces (projects) organized, I created a configuration to only display buffers in the current one.
bs buffer switching popup appears and
ace-jump-line is called, placing a character at the beginning of each line. The buffer ordering is from most recently viewed to backwards in time, so you can assume the current buffer is
c, the previous buffer is
d, and so on. Pressing the key that matches the line’s character selects the buffer.