Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cancel vim recording that has already started, so that it does not overwrite my previous recorded macro?

Tags:

vim

macros

I accidentally hit qq instead of @q, and my vim is now recording into register q. If I type q again, it will overwrite the previously recorded macro.

Is there a way to either

  1. Cancel the recording so that the previous macro is not overwritten or
  2. Restore the previous macro without re-recording it from scratch?
like image 386
merlin2011 Avatar asked Mar 15 '14 01:03

merlin2011


People also ask

How do you stop recording in Vim?

Solve the problem and record the macro To record a macro and save it to a register, type the key q followed by a letter from a to z that represents the register to save the macro, followed by all commands you want to record, and then type the key q again to stop the recording.

How do you stop a recording macro?

It means you're in "record macro" mode. This mode is entered by typing q followed by a register name, and can be exited by typing q again.

How do I stop a macro in vim?

By default*, the l command is such a command, so you can use it to stop a recursive macro. If the cursor is not at the end of the line, then you just need to move it back afterwards with the command h .

What does QQ do in Vim?

QQ is a wrapper over curl for making remote calls inside vim.


2 Answers

You can back the macro up into a different register:

:let @a=@q

Then the previous macro will be stored in register a, and available to be run as @a.

like image 120
rampion Avatar answered Oct 04 '22 01:10

rampion


I just found a less direct way of doing the thing same thing too, also based on the observation that the macro is not recorded until the second q.

I simply use "qp to paste the macro somewhere, and then use "qyy to yank it back in after I cancel the recording.

like image 30
merlin2011 Avatar answered Oct 04 '22 01:10

merlin2011