How to repeat some action certain times on Vim?

Martín Fixman picture Martín Fixman · Jul 13, 2010 · Viewed 14.9k times · Source

In Vim, I usually want to repeat some series of commands some times. Say, I want to comment 5 lines, I would use

I//<Esc>j
.j.j.j.j

Is there any way to repeat the last ".j" part several times?

Answer

Greg Hewgill picture Greg Hewgill · Jul 13, 2010

One way to do this is to assign your key sequence to a macro, then run the macro once followed by the @@ run-last-macro command. For example:

qa.jq@a@@

If you know how many times you want to repeat the macro, you can use 4@@ or whatever.