0

I am looking to create a new syntax. This is what I have so far:

syntax match jl_comment "^# .*"

but I have noticed other examples using pattern like this:

"^# .*$"

Example:

https://github.com/vim/vim/blob/12f20038/runtime/syntax/sh.vim#L385

This is confusing to me. With my example, the . matches anything, so it will continue until the end of line. So it seems the $ is redundant. Is that the case, or am I misunderstanding the rules?

  • 1
    That's the case. Yes it's redundant. But it's more explicit and it doesn't hurt. I'd be fine with either expression. – filbranden Feb 27 at 20:10
0

An alternative is to define a Region instead of Match:

syn region jl_comment start=/^# / end=/$/
hi link jl_comment Comment

This also has the benefit of allowing different highlighting for the marker, should you want to do that:

syn region comment_text matchgroup=comment_mark start=/^# / end=/$/
hi link comment_mark Delimiter
hi link comment_text Comment
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.