Vim: For Multiple Files: Copy all Text, Replace and Paste
vim
Solution
Like @ib mentioned, I'd do this with ex commands1
:argdo %y | %s/old1/new1/g | $pu | %s/old2/new2/g
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):
:argdo $mark a | %co$ | 1,'a s/old1/new1/g | 'a,$s/old2/new2/g
To allow non-matching substitutions, add `s///e` and add `silent!` to make operation much faster in the case of many files.
:silent! argdo $mark a | %co$ | 1,'a s/old1/new1/ge | 'a,$s/old2/new2/ge
1 (note that argdo expects an Ex command list by default. You'd use e.g. `argdo norm! ggyG` to use normal mode commands)
Problem
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 :P Thanks.