Search code examples
vimvim-syntax-highlighting

Matching characters in first column


I'm trying to write a custom syntax highlighting file (.vim) and comments for the language are either a '.', '', or '+' starting in the first column of the line.

.comment
*comment
+comment
  not a comment

Is there a way to match these types of comments? I've tried

syn match myComment '(\s)@![.|*|+]*.*'

Basically, I tried testing for no whitespace, because I wanted to start in the first column, but it does not work that way.


Solution

  • The ^ atom matches in the first column:

    syn match myComment '^[.*+].*'
    

    Additional critique

    Also, your regular expression syntax is off:

    • Unless you switch to very magic mode by prepending \v, you have to escape the \(...\) capture group and the \@! multi.
    • Inside the collection [...], you don't separate via \|.