Loading ...
Sorry, an error occurred while loading the content.

55224Re: Multiple file find and replace

Expand Messages
  • Tim Chase
    Dec 2, 2004
    • 0 Attachment
      >> I have a friend who uses Textpad and likes the multiple file
      >> search and replace. I want to demonstrate this in Vim, but
      >> am unsure how to do this.
      >
      > :see ":help :s"

      I think the OP was looking for how to do it across multiple
      files. While Jurgen suggested the "argdo", it's also helpful to
      mention "windo" and "bufdo" which are also helpful.

      I'll give the caveat that with bufdo and argdo, you leave that
      buffer so you'll get an error if the file has been modified.
      Thus, you can either ":set hidden" beforehand (and then do a
      ":wall" to write all the changed files), or you can append "|w"
      to the ex command.

      So if you have started vim with "vim *.cpp", you can do

      :set hidden
      :argdo %s/foo/bar/ge

      (which is my preferred method) or, IIRC, you can do

      :argdo %s/foo/bar/ge |w

      to make the changes in each file and then write them before
      proceeding on to the next file.

      So an expanded combination of Jurgen's and Antoine's answers
      might yield pointers to

      :he windo
      :he argdo
      :he bufdo
      :he :s
      :he 'hidden'
      :he :s_flags

      (that last one is for the "e" in the :s command which supresses
      error reporting if no changes were made)

      Hope this helps,

      -tim
    • Show all 9 messages in this topic