Thursday, April 23, 2015

positive lookbehind

Hello everybody,

I came across a strange behavior of Vim. Consider the following two
lines; the 2nd line starts with spaces.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test test test
Test test test
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I want to match each 1st word of a line, ignoring preceding white
spaces. The expression

/\v^\s*\zs\w+

works perfectly, however,

/\v^(\s*)@<=\w+

does not. It only matches words in the very beginning of a line, but not
those preceded by whitespaces. I cannot see why the latter would not be
equivalent to the first expression.

According to

:h @<=

"Vim allows non-fixed-width patterns". Thus, I would expect the positive
lookbehind to work also for the 2nd line. (I know that \zs is the
preferable solution anyway, but I'm curious.)

Any ideas?

Best,
Claus

No comments: