How to include forward slash in vi search & replace

I have a file that contains the string usrbin. I want to search for usrbin and replace it with /usr/bin/.

I tried :%s/usrbin/usr/bin/g, but it's showing error E488: Trailing characters.

How do I include a forward slash in a search and replace?


Here are two ways:

  • escape the / which is the default substitute separator: :s/usrbin/\/usr\/bin
  • use another substitute separator, e.g., using the hash # character: :s#usrbin#/usr/bin. Note that there are characters that you can't use as a separator: ", \, |