I want to do the following for multiple files using Vim:
- Copy all text in each file
- Replace some text
- Paste the copied text at the end of the each file
- Replace some other text
Here are my commands for one file:
:%y
:%s/old1/new1/g
:G
:P
:%s/old2/new2/g
Can anybody tell me the syntax to do so? Especially that I’m new to Vim!
I found out that argdo can execute commands on multiple files. I found many examples to use argdo in replacing text, but I couldn’t find the syntax to use argdo with :%y, :G, or 😛
Thanks.
Like @ib mentioned, I’d do this with ex commands1
There’s also a good chance that you might want to operate on exclusive ranges (do the first substitution only on the first part, and the second only on the second):
To allow non-matching substitutions, add
s///eand addsilent!to make operation much faster in the case of many files.1 (note that argdo expects an Ex command list by default. You’d use e.g.
argdo norm! ggyGto use normal mode commands)