On 12/01/11 22:11, Rick R wrote:
I often will find a multi line snippet of text that I'd like
to then replace in multiple files in my project after a
certain block of text (maybe it's some javascript for example
so I'll want the multiple lines pasted after the
initial<script>  tag.)

How do I do this easily in vim (or MacVim/gVim if those gui
editors on top can help?)

Without particulars, it's a bit hard to give a concrete example. In the general case, it sounds like you want to mix a combination of an argdo/windo/bufdo/tabdo command (to iterate over all the associated buffers/windows) and issue a search&replace (or insertion) command anchored at at a given text. Thus you might have something like

  :windo %s/block_of_text\zsmulti\nline\ntext/replacement

or

  :set hidden
  :bufdo g/block_of_text/sil! put='some text to put after'
  (verify it all looks good)
  :wall

If you have content in the clipboard you want to paste after each line, you can do

  :[whatever]do g/where_to_put_it/put=@*

The reason for the 'hidden' is that Vim won't let you leave a modified buffer unless it's set. With :windo or :tabdo it's not a problem because they aren't closed, but with argdo/bufdo, they leave the current (modified) buffer to progress to the next. If you're feeling reckless, you can include a ":w" after your command to also write the file out before leaving it (with the caveats listed at ":help :bar" regarding commands that may require an :exec )

Hope this points you in the right direction. With greater detail from you, perhaps more detailed help can be given :)

-tim



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to