How to insert the same line into multiple files using VIM

I would like to insert lines into multiple files in the same way that I can search and replace multiple files. For example, to search and replace the same line across 4 files, I would do this (when opening multiple files):

:115s/fidget/widget/|:wn|:115s/fidget/widget/|:wn|:115s/fidget/widget/|:wn|:115s/fidget/widget/|:wq

      

How would I insert a string instead of search and replace?

+3


source to share


1 answer


Insert the line by doing the replacement like so:

:115/$/\rfoo/

      

However, let's ditch that with :windo

:

:windo 115s/$/\rfoo/

      

:windo {cmd}

will execute {cmd}

in every window.

Replacements are not your thing or your text in the registry? Then use :put

. An example of placing a line after line 115 from a register "a

:

:windo 115put a

      



Do you have more files and don't want to be disturbed by windows? Then use :args

and: argdo`.

:args `find . -name '*.foo'
:argdo 115put a

      

There are several Vimcasts related episodes that might be interesting:

For more help see:

:h :s
:h :windo
:h :pu
:h :args
:h :argdo

      

+2


source







All Articles