I know about the :bufdo
command, and was trying to combine it with a macro I had recorded (@a
) to add a #include in the proper spot of each of the header files I'd loaded. However, I couldn't find an easy way to run the macro on each buffer. Is there a way to execute a macro through ex mode, which is what :bufdo
requires? Or is there another command I'm missing?
To replay the macro once, move the cursor to the next line and press @h where h represents the register on which you saved the macro. Notice that the macro automatically moves the cursor to the next line as required. This allows you to repeat its execution. To repeat the macro execution, press @@.
Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.
Just put it to your . vim/plugin directory and then use :BufOnly command to close all buffers but the active one.
You can do it like this:
:bufdo execute "normal @a" | write
The normal command will run the macro, but it has to be run using :execute, otherwise the pipe character will be interpreted as a normal-mode character.
You have to use normal
to execute normal mode commands, such a macro execution (@a
) in command mode:
:bufdo normal @a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With