tags:

views:

37

answers:

1

I have a syntax highlighting file for the q/kdb+ language and I'd like to convert it to a vim compatible file so my q code won't look any more ugly than usual.

Are there utilities available to automatically convert notepad++ xml syntax highlighting files to vi versions? I had a look around but I couldn't find anything.

Alternatively does anyone have a vim q syntax highlighting file?

+2  A: 

The answer to both questions is no (I don't know of any converters and I don't have a q syntax highlighting file), but the Notepad++ syntax highlighting XML format looks extremely simple. I don't have the 'Q' one to hand, but I had a look at one of the ones from the website and the translation looks pretty trivial. In that case, you could do most of the work with:

" Remove all the lines that aren't lists of keywords
" (there doesn't seem to be anything much more complicated
" than that in the definition file)
:g!/<Keywords name=/d
" Convert the lines (fairly poor XML parsing here!)
:%s/\s*<Keywords name="\([^"]\+\)">\([[:alpha:]_ ]\{-}\)<\/Keywords>/syn keyword \1 \2/

This generates lots of lines that look like:

syn keyword Words1 case then do while

You'll have to tweak the syntax class (Words1 in this case) to be something that will be highlighted in Vim (or syn-link it to something that will be highlighted in Vim).

You could probably then deal with the symbols with a regexp, but it might be easier to just do them by hand, so convert:

<Keywords name="Operators">- ! &quot; # $ &amp; * , . ; ? @ \ ^ { | } ~ + &lt; = &gt;</Keywords>

into:

syn match Operators /\<[-!"#$&*,.;?@\\^{|}~+<=>]/

(this is \< to mark a word boundary, followed by a character class [..] with all the symbols in it).

You would then just need to add:

if exists("b:current_syntax")
    finish
endif

at the start and:

let b:current_syntax = "q"

at the end.

Of course, this doesn't get you all the way, but hopefully it will give you a lot of what you need to get the syntax file that you want. There is plenty of help available in:

:help syntax

and by looking at the examples in the syntax directory of the runtime folder.

Good luck!

Al
Thanks for the tips! That should make the process of making a vim file easier, it doesn't look hugely complicated.. I'm just lazy.
Peter Byrne