Search And Replace Text in VI editor


ok, on the example text file above, lets say i want to change all the 'wallpaper' to 'screensaver' well this is how you would do it.. 

lets assume that wallpaperama.txt is located on my home directory at: /home/me/wallpaperama.txt 

step 1. open the file with the vi editor:

vi /home/me/wallpaperama.txt


step 2. Enter – SHIFT + : (the Shift key and the colon key at the same time) on your keyboard, the screen will look like this: 
20080904_6332_vi-editor.jpg 

step 3. now enter this command and hit enter

:%s/wallpaper/screensaver/g



step 4. now you will see that all the text 'wallpaper' was changed to 'screensaver' 
20080904_6332_vi-linux-editor.jpg 

step 5. save the change with this command:


:qw



DONE 

i hope this helps you 


dpejic has written 85 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>