Vim syntax highlighting - exclude specific text from a template

I defined sqlVariable and sqlString in my syntax file as

 syn match sqlVariable ":[az][a-z0-9_#$]*" syn region sqlString start=+'+ end=+'+ contains=sqlVariable 

(plus some other quote options.) Strings can contain sqlVariable to highlight bindings in dynamic code, for example :b1 in 'select a from b where c = :b1' . (This is for Oracle, by the way.)

All this works great - except in the particular annoying case of date format masks containing a colon, for example

 to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') 

: MI and: SS stand out as variables, because, of course, they match my pattern.

Is there a way to do: MI and: SS does not match sqlVariable in the quoted string? (I think that only these two things will do it.)

+5
source share
1 answer

Does it help?

 syn match sqlVariable ":[az][a-z0-9_#$]*\ze\(\s\|'$\)" 

It will match those :foo if followed by a space or ' , then EOL ( $ ).

So :a1 :b1 and :c1 will match:

 'select * from foo where a= :a1 and b=: b1 and c = :c1' 

but does not match:

 to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') 

Hope this helps.

If this is not the case, perhaps you might consider defining a region .

+1
source

Source: https://habr.com/ru/post/1237598/


All Articles