Vim Macros

As a developer, we adopt the philosophy of dry. “do not repeat yourself”. This is what sparked my interest in Vim macros, as macros enable us to automate the repetitive process of certain tasks.

Vim macros allow you to repeat a set of keystrokes with the one keyboard shortcut.

Vim Macros allow you to repeat a set of commands of your choosing.

Vim macros are recordings of vim commands which you can easily repeat back.

The way it works, is you record all of commands and then you can play that recorded command back.

Create a macro

start recording a new macro called “a”


End recording / macro

to end a recording


Run a Macro

To run a recording type


Execute a Macro multiple times

to repeat macro h 5 times


Execute the last Macro multiple times

repeat last macro 50 times


See vim macros usage example of adding a dash before each line

img-description vim macros usage example

Macro notes:

  • These recordings are stored in registers.
  • The recordings will be cleared when you close your buffer.
  • The recordings do not persist from buffer to buffer.
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.