I am writing a plugin where a certain filetype must possess their own syntax highlight. Therefore I have created

├── ...
├── plugin
└── syntax

and syntax/newfiletype.vim containing

syntax clear
syntax match MyPattern /regexpattern/
highlight default link MyPattern Title

where regexpattern is a valid regex pattern that matches, say, vim search or vim regex functions, but that however does not work when having to match for syntax highlight. In the particular case at hand I want to highlight all lines containing dashes at the start of the line, therefore /^--.*/. The same happens if instead of the - one uses any other non-alphanumerical character.

Problem: regex pattern ^-- (or any similar one) does not work for the filetype in question when for syntax highlight.

Similar questions: here, here or here.

  • 1
    Welcome to Vi and Vim!
    – filbranden
    Commented Feb 17, 2021 at 23:13
  • 2
    Please edit to include sample text, what you expect to be matched, and what is actually matched. (Getting the syntax groups under the cursor can be helpful; plenty of tricks around this site or the internet at large for that.) Also, make sure verbose set filetype? shows what you expect—if the filetype is new, I would expect to see an ftdetect (and possibly ftplugin instead of/in addition to plugin) directory.
    – D. Ben Knoble
    Commented Feb 17, 2021 at 23:43


Your Answer

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