I'm using searchpos instead of search is I can echo the column where the match happens, which, with example file below coincides with the matched character.

    +-- cursor is here

In this condition, echo searchpos('[28]', 'nWz')[1] gives 8 and that's what I expect from the doc. In this case the option W is irrelevant, because there is match after the cursor, and the option z is also irrelevant, because there are no overlapping matches.

In the same condition, echo searchpos('[28]', 'nWzb')[1] returns 0, which means that no match was found. This is in line with the doc too:

When searching backwards and the 'z' flag is given then the search starts in column zero, thus no match in the current line will be found (unless wrapping around the end of the file).

But the description of the z option reads like this

'z' start searching at the cursor column instead of zero

The two seem a bit inconsistent to me, unless I assume the latter quote lacks the accessory "unless 'b' is given too", in which case I'd be tempted to conclude that when the b flag is given, the z flag is ineffective.

However, echo searchpos('[28]', 'nWbz')[1] returns 0, which is in line with

thus no match in the current line will be found

but echo searchpos('[28]', 'nWb')[1] returns 2, as if the search started from the cursor position instead of from the colum zero.

So I gather that

  • z in nWbz => search starts in column 0
  • no z in nWb => search starts at the cursor

which is kind of opposite of what z is documented to do. Should I interpret this as b reversing the meaning of presence/absence of z?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.