Skip to content

Instantly share code, notes, and snippets.

@myegorov
Created March 19, 2019 05:57
Show Gist options
  • Save myegorov/9c7088428031225c023980198dc06b58 to your computer and use it in GitHub Desktop.
Save myegorov/9c7088428031225c023980198dc06b58 to your computer and use it in GitHub Desktop.
repeat an arbitrary sequence of edits in emacs a la vim's dot command

Repeat one or more commands in sequence

Emacs C-x z can be used to repeat a single command. To emulate Vim's dot command (.), use keyboard macros.

A typical workflow:

  • C-x ( to start recording a macro, C-x ) to end the recording.
  • execute the last recorded macro with C-x e (repeat with e); execute until end of file (or error) with C-u 0 C-x e (any other numeric prefix will do as well);
  • insert a 0-based counter in a macro with C-x C-k C-i (or set arbitrary counter base with C-x C-k C-c <number>);
  • use search -- forward (C-s) and reverse (C-r) -- to position the point;
  • can limit the macro application to a region with C-x n n (disable with C-x n w), or via M-x apply-macro-to-region-lines

More tricks listed in Emacs wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment