Skip to content

Instantly share code, notes, and snippets.

@jeffkreeftmeijer
Last active February 2, 2021 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffkreeftmeijer/4ee3a6747f7c642b360e586bec6ec429 to your computer and use it in GitHub Desktop.
Save jeffkreeftmeijer/4ee3a6747f7c642b360e586bec6ec429 to your computer and use it in GitHub Desktop.

Vim Macros

To record a macro, press q in normal mode, followed by a paste registry to store the macro in. To define a quick macro to use a couple of times, I usually use the q registry, meaning I type qq. Vim will tell you you’re currently recording a macro in the status line.

--recording @q

Vim will now record your commands to be used later. For example, to convert a markdown-style link ([Jeff Kreeftmeijer](https://jeffkreeftmeijer.com)) to an asciidoc-style one (Jeff Kreeftmeijer) one, the recorded macro looks like this [1]:

f(di(F[Pa:^[f(xx

To use a defined macro again, press @q in normal mode.

To save a macro for reuse later, we can paste the contents of the q registry by pressing "qp, which produces the result above. We can then save our macro in our ~/.vimrc file like this:

let @q = 'f(di(F[Pa:^[f(xx'

Now Vim will remember the macro for the next time we accidentally use Markdown-style links in Asciidoc documents.


1. A subsitution might be a better fit for this specific case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment