Raj
Raj

Reputation: 4460

How to replace the '/' character using vi

What substitution command should I use, in order to replace every occurrence of the character / with the string "abc" in a text file with vi?

:1,$ s/?/abc

What should I use instead of the ? in the above snippet?

Upvotes: 1

Views: 197

Answers (2)

Tom
Tom

Reputation: 16208

You could change the substitution delimiter which is by convention / to something else then you would not have to escape the forward slash at all -

:%s;/;abc;g
:%s~/~abc~g
:%s!/!abc!g
:1,$s?/?abc?g
:%s/\//abc/g
:1,$sub;/;abc;g

These all do the same replacement of / with abc on every line.

Upvotes: 6

Danil Speransky
Danil Speransky

Reputation: 30473

The answer is :%s/\//abc/g I think.

Upvotes: 5

Related Questions