16

I have some scripts(linux) which are generating the o/p with respect to Windows. I expect it to be /home/manty/... it generates \home\manty\... It is very annoying when I try to change one by one all the time. So just for this purpose, I am leaving vim and going to gedit to perform "find and replace". How can I do it in vim?

I tried with following :

:%s/\\/\/

It changed only in the two places. I tried several other combinations as well nothing is working out.

Sandeep
  • 18,356
  • 16
  • 68
  • 108
  • possible duplicate of [How to include forward slash in vi search & replace](http://stackoverflow.com/questions/11823616/how-to-include-forward-slash-in-vi-search-replace) – kenorb Mar 15 '15 at 13:39
  • Or: [How does one escape backslashes and forward slashes in VIM find/search?](http://stackoverflow.com/q/2465156/55075) – kenorb Mar 15 '15 at 13:41

2 Answers2

28

Ah. I missed the g thing.

:%s/\\/\//g

This command does the trick. g stands for global and will make the change globally (complete file).

Also, you can add an extra option of c if you want to monitor each change. If you want to use c option the command would be :%s/\\/\//gc and then select y or n for each change.

I will wait for better answers from vim geeks. I am sure there must be a better way.

Sandeep
  • 18,356
  • 16
  • 68
  • 108
7

You can use another delimiter like this:

 :%s,\\,/,g
kenorb
  • 155,785
  • 88
  • 678
  • 743
SergioAraujo
  • 11,069
  • 3
  • 50
  • 40