In this simple code:
char **s = NULL;
char **s1 = NULL;
I want to replace "**s" with "*s",
the result should be:
char *s = NULL;
char **s1 = NULL;
but if I try:
%s/\<\*\*s\>/\*s/g
replace failed. If try this:
%s/\*\*s/\*s/g
the result is:
char *s = NULL;
char *s1 = NULL;
replace succeded, but also "**s1" is replaced
Why the first method FAIL?
In vim regular expressions, \< means a word boundary. There's no word boundary between the space and the asterisk — neither one is part of a word — so \<\* doesn't match. You need this:
%s/\*\*s\>/\*s/g
which addresses that issue, while still retaining the word-boundary after s (so as not to match *s1). (\< and \> are frequently used in pairs to match a whole word, but they don't have to be. Either can be used without the other.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With