Search and replace /’s in VI

Posted on

Problem :

I was wondering how I would search and replace all /’s with -‘s in vi.

%s///-/g doesn’t work obviously.

Solution :

Try escaping your /s, with a .

/. yes, it looks awful. That’s how I remember it 😛

You can use any delimiter you wish, not just /. For example, !:

%s!/!-!g

This way, / becomes non-special and doesn’t have to be escaped.

replacing separator is not always /.

Try

%s;hoge/hoge;fuga/fuga;g

in the text of “http://hoge/hoge

Leave a Reply

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