UNIX/Linux

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

Leave a comment

 

^ back to top ^

Page 9 of 9« FirstNewer56789