Xi Juanjie wrote: > I found a strange behavior about highlighting matching parens with c > files, I wonder if it's a bug or not. > > I have this code in my c file. > Foo(Bar("FOOBAR")); > and I use the arrow key to move the cursor through the code > when cursor stand like this, > Foo(Bar|("FOOBAR")); > it highlighted the 2nd left paren and the 1st right paren, everything is ok. > but when cursor stand like this, > Foo(Bar(|"FOOBAR")); > it highlighted the 2nd left paren and the 2nd right paren. > and when move cursor to the end of code, > Foo(Bar("FOOBAR"))|; > it also highlighted the 2nd left paran and the 2nd right paren. > > I can reproduced this in many known filetypes with systax highlighting. > like c,java,pl,jsp files and so on. > but filetypes with out highlighting seems be ok, for example the txt file. > > Is this a bug of the vim7? > I used the vim7f on win2k.
I see the problem. The check for the paren being inside a string is off by one column. This patch will fix it: --- ../runtime/plugin/matchparen.vim 5 Apr 2006 20:19:48 -0000 1.8 +++ ../runtime/plugin/matchparen.vim 27 Apr 2006 13:32:00 -0000 @@ -87,18 +87,20 @@ let c2 = '\]' endif - " When not in a string or comment ignore matches inside them. - let s_skip ='synIDattr(synID(line("."), col(".") - before, 0), "name") ' . - \ '=~? "string\\|comment"' - execute 'if' s_skip '| let s_skip = 0 | endif' - " Find the match. When it was just before the cursor move it there for a " moment. if before > 0 let save_cursor = getpos('.') call cursor(c_lnum, c_col - before) endif + + " When not in a string or comment ignore matches inside them. + let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' . + \ '=~? "string\\|comment"' + execute 'if' s_skip '| let s_skip = 0 | endif' + let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline) + if before > 0 call setpos('.', save_cursor) endif -- [Autumn changed into Winter ... Winter changed into Spring ... Spring changed back into Autumn and Autumn gave Winter and Spring a miss and went straight on into Summer ... Until one day ...] "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///