Global search and replace using Vi

to replace all instances of – say – with in a file then using vi you can do:


if you mess it up then press u for undo. Of course if it's an important file then back it up first.


3 responses to “Global search and replace using Vi”

  1. Do you think maybe you could have used a simpler example without all of the escapes for the .’s ? how about this? Replace all instances of overcomplicated in a file:


  2. *shrug* I was simply illustrating the task that I was doing at that moment.

  3. Your example is actually a good one. The fact is that a very common use for global search/replace in vii is to replace ip addresses in .conf files. This example perfectly illustrates doing just that, and is unlikely to confuse anyone with even some experience with posix type os.