Select only the first match

With Vim, I want to highlight only the first match of the expression.

For example, in the following text I want to highlight only the first a:

bdjh abc olkd abc abc

How can I understand that?

+4
source share
2 answers

You can make it explicit

/^.\{-}\zsa

It does:

  • ^ (start of the match)
  • .\{-} (as few characters as possible)
  • \zs (start of the match)
  • a (your template)

enter image description here

+10
source
/\v(.*a.*)@<!a

this should work.

+1
source

Source: https://habr.com/ru/post/1541094/


All Articles