admin管理员组

文章数量:1122846

How can I in Vim highlight, e.g., the first 10 words in a line ?

I have found in Stackoverflow the answer for the first word :

/^\s*\w\+/

but I cannot figure how to tinker it for 10 words, or any number of words, by the way.

How can I in Vim highlight, e.g., the first 10 words in a line ?

I have found in Stackoverflow the answer for the first word :

/^\s*\w\+/

but I cannot figure how to tinker it for 10 words, or any number of words, by the way.

Share Improve this question edited Nov 22, 2024 at 16:13 romainl 196k21 gold badges297 silver badges333 bronze badges asked Nov 22, 2024 at 15:26 ThGThG 2,4014 gold badges23 silver badges35 bronze badges 4
  • You are not supposed to find these things on stack overflow. You are supposed to learn how to use your tools properly (:help user-manual) and refer to the relevant section of the documentation when you need to dig deeper (:help \+ and scroll around). – romainl Commented Nov 22, 2024 at 16:16
  • I acknowlede your comment, but the answer given by @Kent shows that even if I had rtfm, I could not have come out with such a sophisticated answer (for me, at least). I simply hope that this answer will be as useful for other users, as it has been for me. Again, sorry – ThG Commented Nov 22, 2024 at 16:40
  • There is nothing sophisticated in that answer. – romainl Commented Nov 22, 2024 at 17:03
  • I see thqt you hqve deleted your downvote. This is elegant. Thank you. – ThG Commented Nov 23, 2024 at 10:15
Add a comment  | 

1 Answer 1

Reset to default 1

Does this help?

/\v^\s*(<\w+>\s*){,5}

In the screenshot, it "highlights" 0-5 words as an example.

本文标签: highlightVim words syntax highlightingStack Overflow