On 05-Jun-2013 11:20 +0200, Marcin Szamotulski wrote: > On 09:40 Wed 05 Jun , Ingo Karkat wrote: >> On 05-Jun-2013 09:10 +0200, Christian Brabandt wrote: >> >>> On Wed, June 5, 2013 08:56, Ingo Karkat wrote: >>>> On 05-Jun-2013 08:03 +0200, Christian Brabandt wrote: >>>> >>>>> [...] the old engine has an long standing bug with \%V ;( >>>>> >>>>> e.g: >>>>> >>>>> vim -u NONE -N >>>>> ifoobar<esc> >>>>> 0ve<esc> >>>>> /\%Vfoobar\%V >>>>> >>>>> I should have probably provided a fix long ago. >>>> >>>> Where is the bug, that there's no match?! That's intended, as the last >>>> \%V matches zero-width _after_ the end of "foobar", but the visual >>>> selection ends on the "r". You'd have to use /\%Vfooba\%Vr here. (The >>>> example at :help \%V is wrong about this corner case, too.) >>> >>> I am not sure, it is intended. I certainly wouldn't expect this (and >>> the doc is wrong in this regard, as you said). Since >>> \%V is zero-width, I would expect the \%V to still match the end of the >>> visual selection. >> >> Zero-width means: Matches at the current position, but does not consume >> the character; i.e. the next match is made at the same position. >> What is needed at the final atom is: Matches at the previous position >> (that has already been consumed). I don't know how difficult that is to >> implement in the regular expression engine(s), but I think such a new >> \%<V atom would be helpful. >> >> In my opinion it is hard to change the existing \%V in a way to fit both >> uses: It just matches anywhere inside a selection, and has no notion of >> start or end of selection. Therefore, it's presumably difficult to >> change its behavior at the end of the selection without introducing >> off-by-one errors elsewhere. I'm already struggling to come up with a >> good and precise documentation for the new behavior; the current one is >> at least simple to grasp (when you understand zero-width matches). And >> it would be a compatibility-breaking change. >> >>>> The general case is this ugly beast: /\%Vfoobar\%(\%V\|\%(\%V.\)\@<=\). >>> >>> Yes, very ugly and not easily understandable. >>> >>>> Since restricting the match to inside the entire selection is such a >>>> common use case (see the related vis.vim plugin), I think it would be >>>> worthwhile to have a special atom (e.g. \%<V) that matches if the >>>> _preceding character_ is inside the selection, allowing this much nicer >>>> pattern: /\%Vfoobar\%<V >>> >>> I can understand why this happens but nevertheless it is an annoying >>> corner-case to consider when using the \%V atom, so I'd like to have >>> this issue resolved. >> >> Yes, at least the help should warn about this corner case. I ran into it >> (and came up with the complex correct regexp) in some of my plugins, but >> I think \%V is one of the more obscure atoms few people use. Probably >> more users rely on the vis.vim plugin, which solves the problem in a >> completely different way. >> >> -- regards, ingo >> >> -- >> -- >> You received this message from the "vim_dev" 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 >> >> --- >> You received this message because you are subscribed to the Google Groups >> "vim_dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > And what about this pattern: > /\%Vfooba\%Vr
That's fine (but hard to read) for literal text, but difficult when you have a regular expression with multiple branches. Thinking of custom commands that take a pattern, it's close to impossible to parse the regular expression to insert the \%V before the match of the last character. > Thanks I did not know this pattern and it is very handy. I always felt > that the search commands /, ? should have a range, so that one can limit > the search to part of a text. What about having two commands :<range>/ > and :<range>? for searches limited to the <range> of lines. You can use the range-search plugin (http://www.vim.org/scripts/script.php?script_id=1396) for that. -- regards, ingo -- -- You received this message from the "vim_dev" 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 --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
