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. > 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. regards, Christian -- 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
diff --git a/src/regexp.c b/src/regexp.c --- a/src/regexp.c +++ b/src/regexp.c @@ -3061,6 +3061,7 @@ static linenr_T reglnum; /* line number, relative to first line */ static char_u *regline; /* start of current line */ static char_u *reginput; /* current input, points into "regline" */ +static int need_adv_col; /* adjust end column after visual match */ static int need_clear_subexpr; /* subexpressions still need to be * cleared */ @@ -3724,6 +3725,8 @@ { reg_endpos[0].lnum = reglnum; reg_endpos[0].col = (int)(reginput - regline); + if (reg_endpos[0].col == need_adv_col) + reg_endpos[0].col++; } else /* Use line number of "\ze". */ @@ -3735,6 +3738,8 @@ reg_startp[0] = regline + col; if (reg_endp[0] == NULL) reg_endp[0] = reginput; + if (reg_endp[0] == need_adv_col) + reg_endp[0]++; } #ifdef FEAT_SYN_HL /* Package any found \z(...\) matches for export. Default is none. */ @@ -4012,6 +4017,7 @@ } lnum = reglnum + reg_firstlnum; col = (colnr_T)(reginput - regline); + need_adv_col = col; if (lnum < top.lnum || lnum > bot.lnum) status = RA_NOMATCH; else if (mode == 'v')