Reputation: 63
I know for searching a whole word I should use /\<mypattern\>
. But this is not true for dash (+U002d) character and /\<-\>
always fails. I also try /\<\%d45\>
and it fails too. anyone know the reason?
Edit2: As @bobbogo mentioned dash is not in 'iskeyword' so I add :set isk+=-
and /\<-\>
works!
Edit1: I think in Vim /\<word\>
only is valid for alphanumeric characters and we shouldn't use it for punctuation characters (see Edit2). I should change my question and ask how we can search punctuation character as a whole world for example I want my search found the question mark in "a ? b" and patterns like "??" and "abc?" shouldn't be valid.
Upvotes: 6
Views: 4759
Reputation: 20162
As OP said. In order to include dash -
into search just execute:
:set isk+=-
Thats all.
Example: When you press *
over letter c
of color-primary
it will search for entire variable name not just for color
.
Upvotes: 0
Reputation: 15483
\<
matches the zero-width boundary between a non-word character and a word character. What is a word character? It's specified by the isk option (:help isk
).
Since -
is not in your isk option, then -
can never start a word, thus \<-
will never match.
I don't know what you want, but /\>-\<
will match the dash in hello-word
.
Upvotes: 5