I recently saw a substitute command where the author had the /
replaced by a !
like this: :s!abc!ABC!g
I tried to find some documentation on this usage but I couldn't find anything relevant. So I tried to experiment by myself and once again I couldn't figure out the real difference between the two signs. Here's what I found:
- It's not possible to mix
!
and/
in a command. For example:s!abc/ABC
fails. - It may be useful to use
!
to avoid escaping a/
in a pattern. For example if I want to replace</
with%
I can use:%s!</!%!g
instead of:%s/<\//%/g
. - It seems that in some case some regex won't work with
/
and works properly with!
but as I'm not really a regex expert i'm not sure of that.
So my question is simple: What is the advantage of using !
in a substitute command and when should I decide to use it instead of /
?