Is there a good way to do this? Much of the time I find myself using avy-mode
I only want to jump somewhere within the current paragraph or line. With stock avy, this involves entering numerous keys to select a nearby location. How is this done? Or maybe my usage of avy here is flawed, and there is a better way to use it?

- 462
- 2
- 14
2 Answers
The avy commands like avy-goto-char
run avy--generic-jump
underneath, and that function takes a begin/end range. Here's a proof of concept modification to avy-goto-char
that runs on the paragraph:
(defun avy-goto-char-in-paragraph (char)
"Jump to the currently visible CHAR in current paragraph."
(interactive (list (read-char "char: " t)))
(let (beg end)
(save-excursion
(forward-paragraph)
(setq end (point))
(backward-paragraph)
(setq beg (point)))
(avy-with avy-goto-char
(avy--generic-jump
(regexp-quote (string char))
nil
avy-style
beg
end))))
You could make a version of the commands you want by modifying how beg/end are calculated (line vs paragraph vs defun etc.).
The avy
package provides the command avy-goto-line
for this:
avy-goto-line is an interactive autoloaded compiled Lisp function in
‘avy.el’.
(avy-goto-line &optional ARG)
Jump to a line start in current buffer.
When ARG is 1, jump to lines currently visible, with the option
to cancel to ‘goto-line’ by entering a number.
When ARG is 4, negate the window scope determined by
‘avy-all-windows’.
Otherwise, forward to ‘goto-line’ with ARG.
See also the project's README: https://github.com/abo-abo/avy#avy-goto-line
There are also the more restricted variants avy-goto-line-above
and avy-goto-line-below
which only consider lines above and below the current line, respectively.
There are no paragraph-specific commands as far as I'm aware; if you think this would be a useful addition you may consider suggesting it on the project's issue tracker: https://github.com/abo-abo/avy/issues

- 12,019
- 43
- 69
-
1Thanks, but the question is about confining the avy search (e.g., `avy-goto-char`) to the current line or paragraph, not searching to a specific line. – Dodgie Jan 24 '18 at 19:20
-
Woops, so it is. Sorry about the confusion. – Basil Jan 24 '18 at 19:22
-
All is forgiven :) – Dodgie Jan 24 '18 at 19:23