Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I repeat the last n changes in Vim?

Tags:

vim

repeat

Doing . repeats the last change. Doing 2. repeats the last change two times.

But imagine I want to repeat the change before the last one. How do I do it in Vim?

like image 243
scc Avatar asked Jul 10 '11 22:07

scc


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.

Does vim do previous commands?

Entering colon : then ctrl+p shows your previous command, i.e., moving backward through your vim command history. ctrl+n moves forward. This is very convenient if you're used to using the command line and prefer not to change your keyboard hand positioning to use arrow keys.


1 Answers

Don't think you can, see :help . However, what you can do is to record a macro for your edits, you have a lot of registers to choose from {0-9a-zA-Z"} (uppercase to append). Then use e.g. @u for edit 1, @t for edit 2 and so on.

Great tips about recording from Best of VIM Tips

" Recording (BEST TIP of ALL) qq  # record to q your complex series of commands q   # end recording @q to execute @@ to Repeat 5@@ to Repeat 5 times qQ@qq                             : Make an existing recording q recursive *N* " editing a register/recording "qp                               :display contents of register q (normal mode) <ctrl-R>q                         :display contents of register q (insert mode) " you can now see recording contents, edit as required "qdd                              :put changed contacts back into q @q                                :execute recording/register q 

Have a look at these for more hints for repeating:

:&     last substitute :%&    last substitute every line :%&gic last substitute every line confirm g%     normal mode repeat last substitute g&     last substitute on all lines @@     last recording @:     last command-mode command :!!    last :! command :~     last substitute :help repeating 
like image 113
Fredrik Pihl Avatar answered Oct 11 '22 09:10

Fredrik Pihl