Vim positive look behind match pattern

Issue

Here is the code:

return (

    <div></div>
)

Notice there is a blank line above <div></div>.

I want to match < in <div>. Here is what I have tried:

  • Pattern \((\_s*\)\@<=< won’t work, but \((\_s*\)\zs< work.
  • Pattern \((\_s*\)\@<=< work only when I remove the blank line above `.

So, my questions are:

  • What’s the difference between \@<= and \zs?
  • How to use \@<= to match the < without remove the blank line above? (This one is more important to me)

Solution

What’s the difference between \@<= and \zs?

  1. The lookbehind operator \@<= cannot search earlier than the previous line
  2. \zs and \ze allow you to explicitly define the match

See :help \@<= and :help \zs

How to use \@<= to match the < without remove the blank line above?

You cannot. For performance reasons, lookbehind will not look 2 lines before the match

Answered By – Jim U

Answer Checked By – Terry (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.