1

In short: how do I define a regex that matches 'iskeyword'.

My initial thought was that match(str, '\w*') would match an arbitrary number of keyword characters in str, but it really only matches to a predefined list (as confirmed by :h \w). Of course, I could manually make up a target with [], but that does not feel right. Am I missing something here?

4

From :h /character-classes you are looking for \k:

    magic   nomagic matches ~
/\k \k      \k      keyword character (see 'iskeyword' option)
/\K \K      \K      like "\k", but excluding digits

Also \w matches "word" characters (i.e. [0-9A-Za-z_]) as in opposition to "WORD" characters. The difference is explained in :h word.

  • Perfect! That is precisely what I was looking for. I still have a hard time finding the right places in the help. Thanks for the pointer to there as well. – Octaviour Dec 11 '17 at 14:02
  • @Octaviour You're welcome! You might also want to have a look at this question romainl's answer contains some pretty good bits of advice. – statox Dec 11 '17 at 14:04
  • Just FYI, there's potential for confusion when using the word "word" in relation to \w compared to its usage when talking about things like the commands w, e, etc and whose counterpart is "WORD". The latter is dictated by the 'iskeyword' setting while \w is always the pattern @statox indicates. – B Layer Dec 14 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.