On 9/22/06, Kim Schulz <[EMAIL PROTECTED]> wrote:
Hi
Is there any way to get vim to show the line where the matching start
bracket is placed (or the line above if line only contains bracket)
whenever a closing bracket is pressed.
e.g.,
if( foo == bar )
{
        bla bla
}
should show "if( foo == bar ) {" when the } is inserted.

Emacs has this feature and I think that it is quite useful when
programming, and would love to have it in Vim.
I am not looking for showmatch, and dont want to jump to the line - i
simply want a preview at the bottom of the script.

If this is not possible directly in Vim, I an planning to write a
script for this - any ideas are welcome.

The patch to $VIMRUNTIME/plugin/matchparen.vim, attached,
shows the line number of the matching paren on the bottom line.
It's basically a demonstration of how easy it's doable with
matchparen.vim.

If you want to show it differently, this gives you a starting place.
Look into matchparen.vim, just search two places with 3match, that's
the place.

Yakov
--- matchparen.vim.000	2006-09-22 23:35:11.000000000 +0300
+++ matchparen.vim	2006-09-22 23:57:18.000000000 +0300
@@ -30,6 +30,7 @@
   " Remove any previous match.
   if exists('w:paren_hl_on') && w:paren_hl_on
     3match none
+    echo ''
     let w:paren_hl_on = 0
   endif
 
@@ -109,6 +110,9 @@
   if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$')
     exe '3match MatchParen /\(\%' . c_lnum . 'l\%' . (c_col - before) .
 	  \ 'c\)\|\(\%' . m_lnum . 'l\%' . m_col . 'c\)/'
+    let show=strpart(substitute(getline(m_lnum),'\t',' ',''),0,&columns-30)
+    let show=substitute(show,'^ *','','')
+    echo substitute(c,'\\','','').substitute(c2,'\\','','').' '.m_lnum.' '.show
     let w:paren_hl_on = 1
   endif
 endfunction

Reply via email to