Vim Syntax-File, Comment after brace not styled

37 views Asked by At

I have the following three lines to style comments in my syntax file. Comments start with # and are allowed to be inline or on a seperate line.

syn keyword     myTodo          contained TODO FIXME
syn match       myComment       "^#.*" contains=myTodo
syn match       myComment       "\s#.*"ms=s+1 contains=myTodo

It does work as long as there is no character (includes braces, etc) right before the #.

I tryed to create a rule like this:

syn match       myComment       ".*#.*"ms=s+1 contains=myTodo

but this would style the whole line as comment.

What do I have to do to make it style correctly, even if there is a character right before the #?

EDIT

syn match       myComment       "\s*#.*"ms=s+1 contains=myTodo

Hightlights the text after # correctly and the text before # is not styled as a comment but the # isn't styled as comment.

1

There are 1 answers

1
yolenoyer On

If I understood well, there is no need to describe the match before the sharp sign.

What happens if you simply try this:

syn keyword     myTodo          contained TODO FIXME
syn match       myComment       "#.*$" contains=myTodo

It's a simple case, which doesn't handle the case where a sharp sign is included into a string for example (if there is some strings in your syntax). To handle this additionnally, you can add:

syn match       Constant      /\v"([^\\]|\\.)*"/
syn match       Normal        /^.*$/ contains=Constant,myComment