Using Vim Macro feature you can record and play a sequence of actions inside the editor.
This article explains how to perform record and play inside Vi and Vim editor using two detailed examples.
$ vim sequence-test.txt
Type: Esc i followed by 1.
$ vim sequence-test.txt
1.
Type: Esc q followed by a
Type: Esc yy followed by p
$ vim sequence-test.txt
1.
1.
Note: Vim will still show recording at the bottom as shown below.

Fig: Vim showing recording message at the bottom
Type: Control a
By placing the cursor at the 2nd line, press Ctrl+a which increment the number to 2. as shown below.
$ vim sequence-test.txt
1.
2.
Note: vim will still show recording at the bottom.
Type: q
Press q to stop the recording. You’ll notice that recording message at the bottom of the vim is now gone.
Type: 98@a

Fig: Generate Sequence Number in Vim using Macro
This example explains how you can executing the same command, with different input for it. i.e Framing the same command, with different arguments.
$ vim change-password.sql
Annette
Warren
Anthony
Preston
Kelly
Taylor
Stiller
Dennis
Schwartz
$ vim change-password.sql
ALTER USER Annette IDENTIFIED BY 'Annette';
ALTER USER Warren IDENTIFIED BY 'Warren';
ALTER USER Anthony IDENTIFIED BY 'Anthony ';
ALTER USER Preston IDENTIFIED BY 'Preston';
ALTER USER Kelly IDENTIFIED BY 'Kelly ';
ALTER USER Taylor IDENTIFIED BY 'Taylor';
ALTER USER Stiller IDENTIFIED BY 'Stiller';
ALTER USER Dennis IDENTIFIED BY 'Dennis';
ALTER USER Schwart IDENTIFIED BY 'Schwart';
$ vim change-password.sql
Annette
Warren
Anthony
Preston
Kelly
Taylor
Stiller
Dennis
Schwartz
Type: q a
Type: I (Upper case i) followed by “ALTER USER ”
Place the cursor anywhere in the first line, and then press I. Which will take you to the first character of the line. Type ALTER USER
Type: Esc w yw
Type: Esc A followed by ” IDENTIFIED BY ‘”
Type: Esc p
Press Esc, and then type p to paste the name that was copied in the step #4.
Type: Esc A followed by ‘;
Press Esc, and A to go to the end of the line, and ‘;
Type: Esc j followed by q
Note: The recording message shown in the bottom of the vi will now disappear. At this stage, the change-password.sql will look like the following.

Fig: Vim Macro completed the recording
Type: 8 @ a

Fig: Vim Macro Play completed

