1

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 Answer 1

0

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
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the late reply. Your first solution #.*$' styles everything after the #` as comment - but no # itself. The other two solutions you wrote don't work either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.