Skip to Content
Mastering Vim
book

Mastering Vim

by Ruslan Osipov
November 2018
Beginner
330 pages
7h 21m
English
Packt Publishing
Content preview from Mastering Vim

Recursive macros

Earlier we ran macros multiple times by prefixing @ with a number. That's not very computer science-like, and we can do better.

Vim supports recursive macros, but there are a few quirks to be aware of.

First, you'll need to make sure the register you will be recording to is empty. You can do this by entering macro recording mode, and immediately exiting it. For instance, if you wanted to empty register b, you'll run qbq to clear it.

Then, record your macro as usual, and insert that same register into itself (for example, by using @b).

Let's say we wanted to swap keys with values in a Python dictionary:

animal_noises = {    'bark': 'dog',    'meow': 'cat',    'silence': 'dogfish',}

We could record a macro as follows, starting with ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Vim

Mastering Vim

Damian Conway
Vim Masterclass

Vim Masterclass

Jason Cannon
Modern Vim

Modern Vim

Drew Neil

Publisher Resources

ISBN: 9781789341096Supplemental Content