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

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

up vote 3 down vote accepted

Try escaping your /s, with a \.

\/. yes, it looks awful. That's how I remember it :P

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"

  • that has already been said by ephemient – Aaron Thoma Jan 16 '12 at 23:30

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.