Create incremental number list in vim with using simple macro

I  do not use vim macros often, but they can be useful from time to time. But when I need them I always need to re-learn the shortcuts, so now I will summarize them in simple example which will create number list from 1. to 50.

Start your vim editor by typing:

vim list.txt

ESC+i and enter:

1.

Start recording with ESC+q and vim will show “recording” at bottom of the screen.

Copy & paste first line with ESC+yy+p

1.
1.

Increment the number with CTRL+a

1.
2.

Stop recording by pressing q and you will notice “recording” is gone from the bottom line.

Repeat the recording 48 more times by typing 48+@+a

1.
2.
3.
....
48.
49.
50.

This same macro logic can be applied in other cases which involve repetitive actions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.