The excellent avy package for emacs provides an efficient mechanism for positioning the cursor in the current window. The avy workflow is:
- Active avy via one of several possible functions
- Type a few characters corresponding to the location on screen you want to navigate to
- Avy will highlight each occurrence of those characters with navigation hints
- Type the one or two letters corresponding to the desired destination
Avy typically enables navigation to any position on screen in four or five keystrokes. There are variants to highlight candidates based on a single character (
avy-goto-char), two characters (
avy-goto-char-2), a character at the beginning of a word (
avy-goto-word-1), or an arbitrary number of characters entered within a short time limit (
I find that the one and two character variants produce too many matches for me to easily visually identify my target. As a result, I have been using
avy-goto-char-timer, which allows you to enter any number of characters; after a timeout following the final character, avy activates and highlights matches for selection.
avy-goto-char-timer function, unfortunately, does not provide a means for correcting typos. This minor annoyance has kept me from using avy as much as I would like for navigation within a buffer. I finally decided to fix it by introducing my own variant:
(defun tr/avy-prompt (s) "Prompt for an avy target and activate avy with it." (interactive "MAvy: ") (avy-process (avy--regex-candidates s)))
This function (which I bind to
C-]) simply uses the minibuffer to prompt for a string and activates avy on that string. Since the string is entered in the minibuffer, all normal editing commands work on it. A future variant could potentially use
completing-read to provide a filtered list of candidates (e.g., via selectrum).