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?
vim Normal mode commands (Editing) Repeat the Last Change Your cursor will be at position 1 of line 1, and all you need to do to fix the next two lines is press j. twice - that is, j to move down a line and . to repeat the last change, which was the addition of the I .
To replay the macro once, move the cursor to the next line and press @h where h represents the register on which you saved the macro. Notice that the macro automatically moves the cursor to the next line as required. This allows you to repeat its execution. To repeat the macro execution, press @@.
Hit the colon ( : ) and then use the up arrow to start going back through previous commands. You can use the up/down arrows too to move around the list.
Use ↑ / ↓ / j / k to select multiple lines. Press Shift + i and start typing what you want. After you press Esc , the text will be inserted into all the lines you selected.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With