created September 20, 2006 · complexity intermediate · author Thomas Ibbotson · version 5.7
I had a long list of files open in buffers, and I wanted to do the same thing to all of them, only that thing required the use of some normal commands in the form of a macro.
I recorded the macro into register a using qa <Do some stuff> q, and I wanted to repeat that for all of the files in the buffer. The solution:
:bufdo exe "normal @a" | w
Let's look at the reasoning behind this.
The command to do normal commands from the command-line is "normal" and I wanted to run the macro recorded in register a, so that explains the "normal @a".
I also wanted to do this over multiple buffers, which explains the "bufdo".
However, I also wanted to make the changes and then save the file so it moved happily onto the next buffer and everything was saved. This required the use of the | w. Initially I tried:
:bufdo normal @a | w
but that didn't work as the "| w" part was interpreted as a normal command, so that's where the exe command comes from.
References
Comments
You can also do
:set autowrite
to get files auto-written.
I often take a look at :help :bar to see which commands see the '|' as their argument.
To save all buffers:
:wa