On Jun 11, 9:01 am, Adriaan <[email protected]> wrote:
> > Adriaan wrote:
> > > I've a text which is tagged with an XML/HTML like syntax, like this:
>
> > > Lorem ipsum <A> dolor sit amet, consectetur adipisicing </A> elit, sed
> > > <B> do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
> > > enim ad minim veniam, quis </B> nostrud exercitation ullamco <D>
> > > laboris nisi ut aliquip <E> ex ea </E> commodo consequat. Duis aute </
> > > D> irure dolor in reprehenderit ...
>
> > > Now I want vim to highlight the text between <A> and </A> with red,
> > > <B> and </B> with yellow, <D> and </D> with blue and between <E> and </
> > > E> with green.
>
> > Adriaan,
> > Before writing your own, you might have a look at the following plugin:
>
> > Txtfmt (The Vim 
> > Highlighter)http://www.vim.org/scripts/script.php?script_id=2208
> > Hope it helps...
> > Brett Stahlman
>
> Thanks Brett,
>
> I know about The Vim Highlighter.
> But these files contain about 40-100 times "<A> blah blah </A>" idem
> for <B> etc.
> So I would have to re-tag these files to get them highlighted, which
> is just to much work.
>
> Well, I could replace "<A>" by "<A> + token Txtfmt uses" to get
> highlighting.

Yes. It would actually be quite simple. Far be it from me, however, to
discourage someone from writing his own Vim script. Still, if you did
want the added flexibility of Txtfmt in your files (e.g., being able
to highlight a piece of text with bold, italic, blue fg, and red bg
all at the same time), there are at least two simple ways to convert
your existing files...

-- Method #1 --
:%s/<A>/\=nr2char(0xE005)/g
:%s/<B>/\=nr2char(0xE007)/g
:%s/<D>/\=nr2char(0xE002)/g
:%s/<E>/\=nr2char(0xE003)/g
:%s/<\/[ABDE]>/\=nr2char(0xE000)/g

-- Method #2 --
:set ft=txtfmt
:%s/<A>/\=Txtfmt_GetTokStr("cred")/g
:%s/<B>/\=Txtfmt_GetTokStr("cyellow")/g
:%s/<D>/\=Txtfmt_GetTokStr("cblue")/g
:%s/<E>/\=Txtfmt_GetTokStr("cgreen")/g
:%s/<\/[ABDE]>/\=Txtfmt_GetTokStr("c-")/g

The latter method uses a function defined by the Txtfmt plugin; hence,
you would need to set filetype to txtfmt first...

Brett Stahlman

>
> I looked at writing my onw syntax file, which I found rather complex.
> And I found the match command which I couldn't get to do what I
> wanted, probably because I'm no good in regular expressions.
>
> It should not be too complicated though...
>
> Thanks anyway!- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message from the "vim_use" 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

Reply via email to