How can I search and replace whole words starting with dollar sign ($) in VIM?
I know that \<word\>
matches the whole word and \$
escapes the dollar sign for regular search and replace, but using \<\$word\>
or \$word\>
only results in "E486: Pattern not found"
That's easily explained. $
is normally not a keyword character, so the assertion that \<
provides ("match at the start of a [key]word") cannot be fulfilled.
You can add the $
(for the current buffer) via
:setlocal iskeyword+=$
but that also affects motions and may even break syntax highlighting. Better just drop the regexp assertion; \$word\>
should suffice. If you need to assert that there's only whitespace before it: \S\@<!\$word\>
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