Repeat the nth last command in vim

vim

I've noticed vim can be pretty intuitive, but I'm having trouble finding a way to repeat the second-to-last command (or third-to-last, fourth-to-last, etc.). By typing . in normal mode it will repeat the last command. Pressing 3. will repeat the last command three times.

Let's say I type oHello<Esc> then A, World!<Esc>. I now get

Hello, World!

on the screen.
Now, say I want to get

Hello, World!
Hello
Hello
Hello

without typing Hello. Does vim store the history beyond one command, so I could type something like 3,2. (i.e. repeat the second-to-last command three times)?

Best Answer

No, the . command in vim does not have a history, nor is there any sort of repeat history for normal mode commands that I am aware of. For the fewest number of keystrokes, I'd recommend 4oHello<Esc>3jA, World<Esc>. If you've already done oHello<Esc>A, World<Esc>, you could follow that with uyy<Ctrl-r>3p.

Related Question