English 中文(简体)
Vim - Macros
  • 时间:2024-10-18

Vim - Macros


Previous Page Next Page  

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

Recording

Perform Vim actions

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

:registers

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

Perform

Stop recording

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

Stop

Play

To play execute below command −

@{macro-name}

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

@a

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

10@a
Advertisements