Questions tagged [macro]

A macro is a recording of typed commands that can be executed later. Macros are stored in registers; recording a macro can be done with q, and you can run them with @.

The documentation for this feature can be found at :help complex-repeat.

N.B. In most of the Vim documentation, "macro" is used as a synonym for "mapping". However, the Vim community mostly uses the term to refer to Vim's "Complex repeats" feature.

184 questions
28
votes
1 answer

After pressing qq, the status line says "recording". How do I get out of this mode?

I accidentally pressed qq, and now the status line says recording. What does that mean? How do I get out of this "recording" mode? Pressing Esc doesn't work.
200_success
  • 9,549
  • 5
  • 51
  • 64
19
votes
1 answer

Save a macro just created in vimrc

Sometimes I create macros. Sometimes I create the same macro multiple times. Sometimes I get tired of creating the same macro over again. Can I store macros? Can I load a preset of macros? Can I make a macro and save it forever?
sensorario
  • 523
  • 4
  • 14
17
votes
2 answers

How do I stop a recursive macro at the end of the line?

How can I create a recursive macro so that it only runs until the end of the line? Or how to run a recursive macro until the end of the line only?
DinushanM
  • 273
  • 4
  • 8
16
votes
2 answers

Improve macro replay speed?

I recorded a simple macro and replayed it on following lines, but it seems replay speed is very slow (handle a very few lines per second). Is this expected and is there a way to improve such speed?
Thomson
  • 852
  • 8
  • 17
13
votes
2 answers

How can I record a nested macro?

I want to record a macro within a macro, like so: qa [ first macro ... ] qb [ second macro ... ] q [ some more stuff, involving @b ... ] q However, the second q is interpreted as a request to stop the first macro, and the…
Doorknob
  • 15,237
  • 3
  • 48
  • 70
9
votes
5 answers

Can Vim write incremental lines? i.e. on each line A becomes B, and 1 becomes 2

I wanted to write this: A = mapping[0] B = mapping[1] C = mapping[2] D = mapping[3] E = mapping[4] F = mapping[5] G = mapping[6] H = mapping[7] I = mapping[8] J = mapping[9] K = mapping[10] L = mapping[11] M = mapping[12] N = mapping[13] O =…
9
votes
3 answers

How to force macro keep running even pattern is not found?

I have a macro to swap text. For single line, it's running without problem. But if I run this macro many times and one line is empty or different pattern, it will print below error and stop. Is there a way to force it keep running even the pattern…
Fisher
  • 1,086
  • 2
  • 13
  • 28
8
votes
2 answers

Insert code snippets?

I'm creating a folder with common code snippets I use. I want to create a quick command in vim to insert them, for example something like: :snippet codeblock1 Ideally it would be a single command and codeblock1 could be replaced by the file name…
Philip Kirkbride
  • 993
  • 2
  • 11
  • 18
5
votes
1 answer

Weird behaviour when repeating macro

I wanted to delete every 2 lines and then skip one, so I tried recording a macro. I did q1 then d2dj to delete 2 lines and go one down, then q and @1 to execute it. The first time it worked well. However the next time I type @1 weird stuff happens.…
4
votes
1 answer

Delete all recordings?

I don't want to disable recording entirely, but I'm not happy with vim keeping my recordings between sessions, and occasionally I fat finger the @ key and end up with a bunch of garbage in the active buffer. How do I ensure that all recordings are…
Roger Lipscombe
  • 335
  • 3
  • 9
4
votes
2 answers

Apply macro to every `n`-th line

I would like to apply macro a to a set of lines. For consecutive lines, this can be done by :5,10norm! @a (https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines). How to do it for every n-th line from my current…
user5370
4
votes
1 answer

How to execute a macro in command mode?

The contents of register w are xx. When I try to run the following command: :for i in range(1,10) | if i > 5 | @w | endif | endfor It throws an error saying that E492: Not an editor command xx. How do I execute the macro?
TheChetan
  • 417
  • 4
  • 11
3
votes
2 answers

How to execute several macros with one command?

I have three macros that I have created separately over time. a performs a search and replace, b adds tags to every line and c appends text at the beginning and the end of the file. I execute them like this: @a :%norm! @b @c How can I execute them…
lejonet
  • 167
  • 3
3
votes
1 answer

Is there any possibility of making Vim UI show which register a macro is currently being recorded to?

Vim users, tell me how many times you remember looking down at your status bar and unexpectedly seeing recording in bold green. It's been recording your keystrokes since you-dont-know-when. This has happened to me no less than twenty times by now. I…
Steven Lu
  • 2,251
  • 15
  • 26
3
votes
1 answer

Is it safe to do other stuff on a system while a macro runs?

If I'm running a complex macro on a large file that I expect to take a few minutes, is it OK to do other stuff on the system (e.g. opening another application, typing in a different text editor, etc?) or could my mouse movements and keyboard inputs…
Scribblemacher
  • 319
  • 3
  • 11
1
2 3