1

When I work with Azure DevOps pipeline files (yaml), I don't get any syntax highlighting in script or bash blocks:

Azure DevOps pipeline with yaml syntax highlighting

That's why I have installed inkarkat/vim-SyntaxRange and configured it to recognize bash syntax between bash:/script: and displayName/condition.

~/.vim/after/syntax/yaml/SyntaxInclude.vim:

call SyntaxRange#Include('^\ *- \(script\|bash\): |', 'condition\|displayName', 'bash')

Now it looks like this:

Azure DevOps pipeline with SyntaxInclude plugin

The script block looks great now, except that pipeline template variables (${{ ... }}) are highlighted as syntax errors.

Can I somehow overrule the syntax highlighting of ${{ ... }}?

3
  • 1
    Not sure how inkarkat/vim-SyntaxRange works, but you can usually add new :syntax commands in various ways (files, autocommands, by hand, etc.)
    – D. Ben Knoble
    Jun 13 at 22:01
  • I tried :syntax match parens "\v\{\{.{-}\}\}", :highlight parens ctermfg=red guifg=red, but with no effect.
    – MaxGyver
    Jun 14 at 13:25
  • It still has no effect, when I put these lines into ~/.vim/after/syntax/sh/double-braces.vim. But these commands work after :set syntax=.
    – MaxGyver
    Jun 14 at 13:32

1 Answer 1

2

This fixes it:

~/.vim/after/syntax/yaml/SyntaxInclude.vim:

call SyntaxRange#Include('^\ *- \(script\|bash\): |', 'condition\|displayName', 'bash')

" Allow template variables ...

" ... in YAML
syntax match doublebraces "\v\$\{\{.{-}\}\}" containedin=ALL
highlight doublebraces ctermfg=blue guifg=blue

syntax match braces "\v\$\{[0-9A-Za-z_.]{-}\}" containedin=ALL
highlight braces ctermfg=green guifg=green

syntax match parens "\v\$\([0-9A-Za-z_.]{-}\)" containedin=ALL
highlight parens ctermfg=green guifg=green

" ... in script block
syntax match shDerefSimple "\${{.*}}" nextgroup=@shNoZSList

Screenshot of an Azure DevOps pipeline in vim

UPDATE: The first solution didn't not work well for some files. The updated configuration is not yet perfect but quite usable.

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.