On Mon, Sep 18, 2006 at 10:23:27PM +0200, Thomas Holder wrote:
> Yakov Lerner wrote:
> > On 9/18/06, Thomas Holder <[EMAIL PROTECTED]> wrote:
> >> Peng Yu wrote:
> >> > I'm writing some xml code in vim. In xml, there are some pair like
> >> > <g> </g>. Would you please let me know how to pair them as "{" and
> >> > "}" such that I can us % to visit them?
> >>
> >> source $VIMRUNTIME/macros/matchit.vim
> >> let b:match_words = '<g>:</g>'
> > 
> > Hmm, the set of xml tags that I have is large and
> > basically open-ended. Do you mean, there is no method
> > to let plugin handle *any* <...> tag, automatically ?
> > Isn't it unproductive to add manually each and every tag
> > to b:match_words ?
> 
> Try this:
> 
> let b:match_words = '<\(\w\+\)\(\s[^>]*\)\?>:</\1>'
> 
> This pattern also allows attributes inside the opening tag after some
> space (but not newline). You could figure this out yourself if you would
> read the help file for this macro.
> 
> Regards,
>   Thomas

     Do not reinvent the wheel!  Assuming that you have filetype support
enabled, i.e., something like

:filetype plugin on

in your vimrc file, $VIMRUNTIME/ftplugin/xml.vim will be :source'd
automatically whenever you edit an xml file.  It already sets
b:match_words to something reasonable.  To test, try

:e foo.xml
:echo b:match_words

     If you want to use matchit rather than default % pairing all the
time, add something like

source $VIMRUNTIME/macros/matchit.vim

or

runtime macros/matchit.vim

to your vimrc file.

     Historical note:  Johannes Zellner suggested adding support for
variable matching pairs (such as matching <anything> with </anything> in
*ML) shortly after I started maintaining the script.  Implementing that
suggestion was complicated enough that I started to think of it as my
script, rather than just something I had tinkered with.

HTH                                     --Benji Fisher

Reply via email to