Vim: for multiple files: copy all text, replace and paste

I want to do the following for multiple files using Vim:

  • Copy all text to each file
  • Replace text
  • Paste the copied text at the end of each file
  • Replace other text

Here are my commands for a single file:

:%y
:%s/old1/new1/g
:G
:P
:%s/old2/new2/g

Can someone tell me the syntax? Especially that I'm new to Vim!

I found out that argdo can execute commands for multiple files. I found many examples of using argdo in replacing text, but I could not find the syntax for using argdo with:% y,: G or: P

Thank.

+5
source share
2 answers

Like @ib, I would do this with ex commands 1

:argdo %y | %s/old1/new1/g | $pu | %s/old2/new2/g

, ( , ):

:argdo $mark a | %co$ | 1,'a s/old1/new1/g | 'a,$s/old2/new2/g

, s///e silent!, .

:silent! argdo $mark a | %co$ | 1,'a s/old1/new1/ge | 'a,$s/old2/new2/ge

1 ( , argdo Ex . , , argdo norm! ggyG)

+4

UPD: Vim-fu , @ib @sehe, .

( Vim), .


vimrc:

function! MyTmpFunc()
   :%y
   :%s/old1/new1/g
   normal! G
   normal! P
   :%s/old2/new2/g
endfunction

Vim , (- vim myfile1.txt myfile2.txt myfile3.txt), :

:argdo call MyTmpFunc()

, : MyTmpFunc() , Vim.

MyTmpFunc() vimrc.

:bufdo - . :windo, , :bufdo .

, , . , "old1" "new1" , :

:bufdo %s/old1/new1/g

.

+3

All Articles