Search and Replace in VI , VIM Editor – Tips

Vi and Vim is very powerful editor in Linux operating system. I already discussed vi, vim commands in my previous tutorial.

In this post i’ll discuss search and replace feature in vi,vim editor. Like all other editor vi also provides this facility. Let’s check how to search and replace any¬†word,text in vi,vim editor.

Search in VI, VIM Editor

How do you search any word or text in vi. By simply using slash and question mark (/ and ?) and type the word you are searching.

Linux Commands with Examples .

Before using these commands make sure you’r vi editor in normal mode. If it’s not press <ESC> so that it comes in normal mode.

a) Search string forward using slash (/).

To continue searching same word press n.

b) Search string backward using question mark (?).

When you use question mark (?) and string it will start searching string from bottom of the file.

To continue searching word from opposite direction press shift+n .

Search and Replace in VI, VIM Editor

Syntax of search and replace –

Learn Coding Online

Subscribe Our Tutorials

Get Latest Updates on Facebook

Now we have to find all the occurrence of foo in a file and replace with bar.

Find each occurrence of product and replace it with product_desc.

Ask for confirmation before replacing. Replace all occurrence of product to product_desc, but it asks for confirmation.

Insensitive find and replace.

Find product (Product, PRODUCT, proDUCT and so on) and replace with product_desc.

Recommended Books for Vi,Vim Editor

Vi, Vim Editor Books on

Vi, Vim Books on Flipkart

Vi, Vim Books on


I hope this short tip will be helpful for you. If you want to add some more tips please let us know through your comments.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.