Emacs Elements has a great video on one of my favorite navigation packages: Avy. The idea is a generalization of Steve Yegge’s recommendation to navigate with search. When I first read Yegge’s tip it was an Epiphany to me. Suddenly, moving around a buffer was quick and easy. Abo-abo’s Avy generalizes Yegge’s idea and makes it even faster and easier. It’s my goto way of navigating and I’ve already used it several times while writing this post.
The video is an excellent introduction to Avy and what it can do. As the video notes, there are several commands that are similar but differ in subtle ways to provide a wide range of functionality. My first choice when I need a navigation command is always avy-goto-word-1
. It provides an easy way of jumping to a word by specifying its first character.
My second most used Avy command is avy-goto-char-timer
. The video fails to capture its true utility. The point of the timer is that you can type any number of characters until there’s a delay of the timer’s value and Avy will identify all the strings beginning with those characters and jump to the start of the one you select. It’s almost like using incremental search as Yegge suggests but the command leaves the point at the beginning of the string, which is convenient.
The video demonstrates two commands that I wasn’t aware of: avy-copy-line
and avy-move-line
that do just what it says on the tin. When you invoke one of the commands, each line is added to the list of targets and the one you choose is copied or moved to the point.
Finally, there’s avy-goto-line
that allows you to immediately jump to a line without knowing its absolute line number. I have it bound to Meta+g Meta+g so that it’s really easy to invoke.
If you’re interested, here’s my complete Avy configuration:
(use-package avy
:ensure t
:diminish avy-mode
:bind (("H-a" . avy-goto-word-1)
("H-s" . avy-goto-char-timer)
("M-g M-g" . avy-goto-line)
("M-g g" . avy-goto-line)
("H-A" . avy-goto-char))
:config (setq avy-all-windows nil))
The Hyper+A binding is for those rare occasions when I want to jump into the middle of a word. The problem with it is that it generates a large number of targets. I never use the Meta+g g binding and don’t know why it’s still there.
If you aren’t using Avy, you’re working too hard. Take a look at the video to see what it has to offer. The video is only 7 minutes, 29 seconds so it should be easy to fit in.