Repeat last normal mode command, including moves, in Vim
In Vim, with .
, I can repeat the last normal mode command; for example:
dd.
deletes a line twice.
But, if I type
5j.
the cursor does't move 10 lines down. How do I repeat the last normal mode command, especially a move?
Solution 1:
it's doable even in vanilla vim, but applicability depends on your use case, ie. how often you'll need to repeat it, since it requires few more keystrokes to make it repeatable.
Option 1: turn it into a command mode operation
using moving down 5 lines as example, you can do:
- enter
:norm 5j
, it'll move the cursor down 5 lines - use
@:
to repeat the movement
:norm
stands for normal, any following string is regarded as your keystrokes under normal mode
Option 2: Use macro
-
qa
(store macro into registera
, you can pick your own register likeqb
,qc
) 5j
-
q
(finish recording macro) -
@a
to repeat your recorded operation (replacea
with the register name you picked, eg.@b
,@c
)
macro requires more spiritual power to set up but it's more repeatable in the sense that you can store multiple operations in different registers without being overriden by latest operations.
Solution 2:
vim
doesn't do this unfortunately. The best you can do is install the repmo.vim plugin, which repeats movement commands that have a count.