Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use macro more than once in gVIM

Tags:

vim

in gVim, I am trying to do

q 2 dd j q

Then

@2

at several points later. It works the first time (meaning vim deletes three lines and moves down when I type @2), but anytime after that, my screen blinks and the cursor moves down once.

Is there a setting I need in vimrc or something to allow this macro?

like image 810
µBio Avatar asked Oct 28 '10 06:10

µBio


People also ask

How do I run a macro multiple times in Vim?

If you want to run a macro repeatedly, type a number before pressing the @ key. Example: 23@a will repeat macro " a " 23 times. Press @@ to repeat the last macro. This does not work instantly after recording, you need explicitly call the macro once.

How do I delete a macro in Vim?

To clear a single macro - record over it - with nothing. For your situation in normal mode you'd just type "qwq".

How do I view macros in Vim?

Viewing a macro You can use the :registers command to view the current contents of any or all register values in Vim. For example, use :reg to view all registers, or :reg a to view only what you have recorded into register a . Typing :reg abx will show the contents of registers a, b, and x.


1 Answers

What is happening is that Vim uses the Numbered registers to store recent changes made with the yank and delete commands. That will wipe your macro from the register.

As a general recommendation, avoid the numeric registers when recording macros.

like image 179
Christian C. Salvadó Avatar answered Sep 20 '22 23:09

Christian C. Salvadó