ShowLove
ShowLove

Reputation: 909

vim: replace a string with the "/" character in it

I've been using the following to replace characters:

  1. To find each occurrence of eth0 in the current line only, and replace it with br0,enter (first press Esc key and type):

    :s/eth0/br0/g
    
  2. To find and replace all occurrences of eth1 with br1, enter:

    :%s/eth1/br1/g
    
  3. To find and replace all occurrences of eth1 with br1, but ask for confirmation first, enter:

    :%s/eth1/br1/gc
    
  4. To find and replace all occurrences of case insensitive eth1 with br1, enter:

    :%s/eth1/br1/gi
    

However, how would I replace a string with one that has a / in it. For example, I want to replace all my debug printf statements with //. When I type..

:%s/printf/ // /gc

it gives me a Trailing characters error. If someone could teach me how to do this i would be thankful.

Thank You!

Upvotes: 0

Views: 85

Answers (2)

R Sahu
R Sahu

Reputation: 206577

You can use a different separator:

:s+sprintf+ // +g

Upvotes: 1

Kent
Kent

Reputation: 195059

escape the / in :s/.../../ or better, use other separator:

e.g. s:@...@...@g

Upvotes: 3

Related Questions