I recently found a replacement command for vim where the author replaced / with ! as follows:: :%s!foo!bar , and I do not understand the difference with the traditional :%s/foo/bar .
I was looking for some documentation on this syntax, but I did not find anything suitable, so I tried to experiment myself, and I could not clearly understand the difference between the two forms. Here is what I found:
- You cannot mix
/ and ! in the same team. For example:: :%s/foo!bar does not work. - Sign
! may be useful with templates, including / . For example, if I want to replace </ with % in my file, I can do :%s!</!%!g instead of :%s/<\//%/g : I do not need to hide / in the first command, but I would be surprised if this is the only use ! . - Some regex seems to fail with
/ and works fine with ! , but since I am far from being a master of regular expressions, I am not sure about this question.
So my question is: what is the difference between / and ! in vim lookup and when should I use one instead of the other?
vim regex substitution
statox
source share