Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM search and replace whole word starting with dollar

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"

like image 574
Scarabol Avatar asked Nov 14 '14 11:11

Scarabol


1 Answers

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\>

like image 194
Ingo Karkat Avatar answered Oct 21 '22 14:10

Ingo Karkat