dockerfile.vim 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. " dockerfile.vim - Syntax highlighting for Dockerfiles
  2. " Maintainer: Honza Pokorny <https://honza.ca>
  3. " Version: 0.5
  4. if exists("b:current_syntax")
  5. finish
  6. endif
  7. let b:current_syntax = "dockerfile"
  8. syntax case ignore
  9. syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|CMD|ENTRYPOINT|ENV|EXPOSE|FROM|MAINTAINER|RUN|USER|LABEL|VOLUME|WORKDIR|COPY|STOPSIGNAL|ARG)\s/
  10. highlight link dockerfileKeyword Keyword
  11. syntax region dockerfileString start=/\v"/ skip=/\v\\./ end=/\v"/
  12. highlight link dockerfileString String
  13. syntax match dockerfileComment "\v^\s*#.*$"
  14. highlight link dockerfileComment Comment
  15. set commentstring=#\ %s
  16. " match "RUN", "CMD", and "ENTRYPOINT" lines, and parse them as shell
  17. let s:current_syntax = b:current_syntax
  18. unlet b:current_syntax
  19. syntax include @SH syntax/sh.vim
  20. let b:current_syntax = s:current_syntax
  21. syntax region shLine matchgroup=dockerfileKeyword start=/\v^\s*(RUN|CMD|ENTRYPOINT)\s/ end=/\v$/ contains=@SH
  22. " since @SH will handle "\" as part of the same line automatically, this "just works" for line continuation too, but with the caveat that it will highlight "RUN echo '" followed by a newline as if it were a block because the "'" is shell line continuation... not sure how to fix that just yet (TODO)