Vim - Macros

Macro is record and play feature. When this is combined with Vim commands it becomes really powerful combination. In this section, we will discuss following items −

  • Start recording
  • Perform Vim actions
  • Stop recording
  • Play recording

Start recording

To start recording press q followed by any lower case letter as a macro name. For instance in below example I have used “a” as a macro name


Perform Vim actions

In this step you can perform any Vim actions like: cut, copy, delete, replace and so on.You can see these actions by executing following command −


For instance, below command shows that yank and delete actions were performed −


Stop recording

Once you are done with actions, press q again to stop recording. Now recording mode will disappear as shown below −



To play execute below command −


For instance to execute macro “a”, execute below command −


To play same macro multiple times use numbers with it. For instance, to execute same macro 10 times execute following command −