Examples of replacing text

Examples of replacing text

To replace one word in the current line with another:

   :s/that/which

This replaces the first instance of the word "that" in the current line with the word "which".


To replace every instance of one word in the current line with another:

   :s/destroy/delete/g

This replaces every occurrence of the word "destroy" with the word "delete" in the current line.


To replace every occurence of a word throughout the file, with another:

   :g/insert/s//add/g

This replaces every occurence of "insert" with "add".


To interactively replace every occurence of a word throughout the file, with another:

   :g/in conjunction with/s//with/gc
   option used in conjunction with the ls command
           ^^^^^^^^^^^^^^^^^^

This displays the first line containing an occurence of the pattern "in conjunction with", and identifies this occurence by underlining each character with a ^ (caret).

Entering y (yes) replaces this instance of "in conjunction with" by "with" and proceeds on to the next.

Pressing <RETURN> leaves this instance unchanged and proceeds to the next.


[Home] [Search] [Index] This site maintained by unixhelp@math.rutgers.edu
This page was last updated on September 05, 2006 at 10:29 am and is maintained by webmaster@math.rutgers.edu.
For questions regarding courses and/or special permission, please contact mclausen@math.rutgers.edu.
For questions or comments about this site, please contact help@math.rutgers.edu.
© 2012 Rutgers, The State University of New Jersey. All rights reserved.