On Mon, 8 Nov 2010, Christian Brabandt wrote:

Hi Benjamin!

(re-posting to vim-dev, for clarity).

On Fr, 05 Nov 2010, Benjamin R. Haskell wrote:

I still don't quite understand why my attempted solution to rameo's problem didn't work... As a pared down example, why is the entire visual range matched in this:

x = outside visual block, V = nonspaces in visual, ' ' = space in visual

/\%V\%(\S\+\s*\)*\%V

xxxxx  VVV VVV VVV  xxxxx - text
     mmmmmmmmmmmmmmm      - match
xxxxx  VVV  xxxxx - text
     mmmmmmm      - match

I don't understand how the leading spaces in the visual range can be matched by a pattern that can't match leading spaces.

I think, I understand this part. This part boils down to a visual selection item followed by zero or more of a sequence of any number of non-space items followed by zero or more space. In other words, this can match /\%V\%V and in fact that is what it matches.

Ah! Thank you. I finally see now. I was thrown by the fact that hlsearch hilights the character following a zero-width match. (So, the highlight wasn't indicating a single match of the entire string; it was indicating three matches: one for each leading space where \%V\%V was matched, and the last for the runs of non-space+ space* within the visual range.)


Removing the optionality, it's also weird, as the trailing space (singular!?) isn't matched:

/\%V\S\+\s*\%V
xxxxx  VVV VVV VVV  xxxxx - text
       mmmmmmmmmmmm       - match
xxxxx  VVV  xxxxx - text
       mmmm       - match

Can anyone shed some light on this?

This is a bug. The regular expression engine is quite complex in Vim. I think, the attached patch fixes it.


Works for me for this particular case.

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to