On Thu, Apr 27, 2006 at 08:30:03PM +0800, Strange wrote:
> hi, vimmers
>
> 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.
>
> Xi Juanjie
I think we can fix this by rearranging a few lines in the
matchparen plugin. Since this is a runtime file, you do not need to
recompile vim for it to take effect. Patch below.
HTH --Benji Fisher
*** /usr/local/share/vim/vim70f/plugin/matchparen.vim 2006-04-25
09:25:30.000000000 -0400
--- temp/matchparen.vim 2006-04-27 09:13:41.012655163 -0400
***************
*** 1,6 ****
" Vim plugin for showing matching parens
" Maintainer: Bram Moolenaar <[EMAIL PROTECTED]>
! " Last Change: 2006 Apr 04
" Exit quickly when:
" - this plugin was already loaded (or disabled)
--- 1,6 ----
" Vim plugin for showing matching parens
" Maintainer: Bram Moolenaar <[EMAIL PROTECTED]>
! " Last Change: 2006 Apr 27
" Exit quickly when:
" - this plugin was already loaded (or disabled)
***************
*** 87,103 ****
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
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
if before > 0
call setpos('.', save_cursor)
--- 87,102 ----
let c2 = '\]'
endif
! " When the match 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'
+ " Find the match.
let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
if before > 0
call setpos('.', save_cursor)