views:

500

answers:

2

I have a custom xml file format which can contain blocks of code within certain tags.

For example:

<Root>
    <Sql> select * from foo </Sql>
    <MoreJunk> ... </MoreJunk>
    <Python><![CDATA[
    def Bar(*args):
        return False
    ]]></Python>
</Root>

How can I get vim to use sql syntax highlighting for the text inside <Sql> tags and use python higlighting for text inside <Python> tags?

I know Vim can already do this because it correctly highlights javascript inside html files.

I tried inspecting the html syntax file but couldn't really figure it out.

A: 

This document describes how to write your own syntax highlighting. You should probably be able to figure out how the HTML-syntax highlighting works with javascript, with that as a reference.

Simon Jensen
+4  A: 

For your XML with python example you would have to do something like this:

runtime! syntax/xml.vim
unlet b:current_syntax
syntax include @Python syntax/python.vim
syntax region pythonCode  start=+<Python>+ keepend end=+/</Python>+  contains=@Python

These lines will include the XML syntax and the python syntax, and the specify a python region where VIM will use the python syntax instead of the XML syntax...

Of course, all this is well documented in VIM. See :he :syn-include on how to include syntax files.

f3lix