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.
In normal mode, press / to start a search, then type the pattern ( \<i\> ), then press Enter. If you have an example of the word you want to find on screen, you do not need to enter a search pattern. Simply move the cursor anywhere within the word, then press * to search for the next occurrence of that whole word.
\<
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
.
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