Replacing in vi
November 21st, 2003
Practical Linux Guide - Using vi
5.3. Search & Replace
To search for a regular expression (see section Regular Expressions) press slash, type the pattern and then start search with the enter key. vi jumps to the first occurrence of the specified pattern. To go to the next occurrence, press 'n'.
Replacing is done using the ':s' command. Type ':s/pattern/replacement/g' to replace all occurrences of pattern with replacement in the current line.
Most of the time you want to work with the whole file, though. That is done using the ':%s' command. Use ':%s/pattern/replacement/g' and pattern is changed to replacement in the whole file. If you aren't sure whether you really want to replace all occurrences, you can append the character `c' at the end of the line. This stops at every occurrence of the pattern and asks if you really want to replace.
Source: http://www.ibiblio.org/gferg/ldp/practical_linux_guide/x360.html
Potentially similar posts
- My first (useful) Ruby program – June 2011
- Adding your choice of text editor to Flare’s Open With menu – December 2010
- Fix “No topics found” issue in CHM output – November 2010
- Deleting those pesky lines in Microsoft Word – August 2010
- Perl basics for beginners (on Windows) – August 2010