(or emacs irrelevant)

Hydra-repeat

Did you know that you can repeat the most recent Emacs command with repeat:

Repeat most recently executed command. If REPEAT-ARG is non-nil (interactively, with a prefix argument), supply a prefix argument to that command. Otherwise, give the command the same prefix argument it was given before, if any.

The default binding to repeat is C-x z. You can then continue with just z: C-x zzzzzzzz.

Unfortunately, since defhydra defines new command names based on the ones that you give it, passing repeat as one of the heads will not work. So I've added hydra-repeat that's supposed to work in the same way.

So now, I can define a Hydra like this:

(defhydra hydra-vi ()
  "vi"
  ("h" backward-char)
  ("j" next-line)
  ("k" previous-line)
  ("l" forward-char)
  ("." hydra-repeat))
(global-set-key (kbd "C-v") 'hydra-vi/body)

And if I press C-v 4l.., it will result in movement forward (forward-char) by 4 chars 3 times:

  • first time from 4l
  • other two times, with the same prefix 4, from ..