On The Fly Command Repeat

As many of you know, I spent many years as a Vi/Vim user. A bit more than 15 years ago, I moved to Emacs, mostly I think, because I was moving a lot of my coding to various Lisps and loved the idea of an editor that was programmed and extensible in Lisp. As I’ve written before, when I moved to Emacs I went all in learning and internalizing the native Emacs key sequences rather than fall back to Vim by using Evil. I’ve never regretted that decision but one thing I do miss is the easy Vim command repeat bound to the . key.

Emacs has its own repeat commands but the situation is complicated by Emacs’ complex commands. One nice feature in Emacs, though, is that some commands with a long prefix can be repeated without retyping the prefix on subsequent invocations. Being Emacs, it is, of course, possible to set up your own repeatable bindings but this has to be done in advance.

Karthik Chikmagalur has an interesting post that shows how to build and invoke a repeatable key sequence on the fly. He does this by cleverly leveraging the Ctrl+h helper function that is called when you type Ctrl+h after inputting part of a binding. The only downside—if it is one—is that you have to type Ctrl+g to get out of the repeat mode.

If you’re like many (most?) Emacsers and are striving to be as efficient as possible, this may be something you’ll like. It requires only eleven lines of code so it’s easy to add to your init.el.

This entry was posted in General and tagged . Bookmark the permalink.