Hello people!
Can anybody please tell me how you can globally insert words into a text file using vi??
I need to be able to insert the words 'echo dummy' between 2 words on many lines of a text file.
Any help would be very much appreciated.
Thanks
CaKiwi's response shows how the words from expression1 are retained with the additional text. In this case, you can just include them in expression2, but the other method -- using the \( and \) -- allows you to preserve selections found with wildcards. (In case you don't know, the \n in the replacement text indicates the nth block from the find text.) Ex:
From "word2 word2" to "word2 echo dummy word2"
and "word3 word8" to "word3 echo dummy word8"
Like CaKiwi, I'm assuming that you want to insert the new text between two words that are constant throughout the file, but if not, the above may help. If this is not enough, please post a more detailed description of the sort of thing you're trying to do.
You're right, Steve. I started to write a solution like your improvement, but decided that it was not what rik1551 asked, but then left it overly complicated. Nice description of how buffers and [] work.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.