Friday, April 15, 2011

How to find '-s' inside a vim search

I use Vim to read man pages. But I'm having trouble searching for variables. For example I use:

/\<-s\>

to search for '-s', but it doesn't find anything. Grrr. I see it in the file. What am I doing wrong?

From stackoverflow
  • /-s works just fine for me.

    Leonard : The problem is I want it word-delimited. There are lots of -s strings there.
    Aaron Maenpaa : ":set hi" and "nnnnnnnnn..." are your friends. I mean seriously, how many "-s"s are you going to see? A hundred?
    Aaron Maenpaa : Though on second thought... It is nice to know *why* the regexp you posted didn't work. Thanks Brian.
  • \< matches the beginning of a word, and - normally isn't considered a word character. Do :set iskeyword? to see what characters are considered word characters.

    Try this:

    :set iskeyword+=-
    /\<-s\>
    

    Should work then. See :h /\< and :h 'iskeyword'.

    Leonard : Perfect. Thanks.
    ojblass : Brian is the only man who should provide the answer to the emacs vs. vim debate.

0 comments:

Post a Comment