Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I repeat the last VIM macro?

Tags:

vim

vim-macros

I know how to repeat the last command in Vim. I use ..

But how can I repeat the last macro? It's a little non-comfortable to press @q everytime I want to repeat it.

I tried with . but it just repeats the last command from the macro.

Is there a shorter way of doing that?

like image 636
Ionică Bizău Avatar asked Dec 26 '13 13:12

Ionică Bizău


People also ask

How do you repeat the last command in Vim?

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 .

How do I repeat in Vim?

The " @: " command repeats the last command-line change (a command invoked with " : ", for example :s/old/new/ ). You can move the cursor before using either of the repeat commands. Suppose you press dd to delete a line. Next, you might move the cursor, then press 5.

Do Vim macros persist?

6) actually persists macros and named buffers automatically (by default, although I haven't looked for a way of turning this behavior off). Closing a Vim session will update the ~/. viminfo file with any named buffers / macros.


Video Answer


2 Answers

Yes, you can use @@ to replay the last used macro.

As a bonus, use @: to replay the last ex command. (And then that becomes the "last used macro" that can be repeated with @@.)

like image 95
john Avatar answered Sep 24 '22 05:09

john


I find @@ a bit hard to type and as I don't use , much - and it's close enough to .:

:map , @@ 
like image 40
Goblinhack Avatar answered Sep 23 '22 05:09

Goblinhack