dockerfile.vim 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. " dockerfile.vim - Syntax highlighting for Dockerfiles
  2. " Maintainer: Honza Pokorny <https://honza.ca>
  3. " Last Change: 2020 Feb 11
  4. " License: BSD
  5. " https://docs.docker.com/engine/reference/builder/
  6. if exists("b:current_syntax")
  7. finish
  8. endif
  9. syntax include @JSON syntax/json.vim
  10. unlet b:current_syntax
  11. syntax include @Shell syntax/sh.vim
  12. unlet b:current_syntax
  13. syntax case ignore
  14. syntax match dockerfileLinePrefix /\v^\s*(ONBUILD\s+)?\ze\S/ contains=dockerfileKeyword nextgroup=dockerfileInstruction skipwhite
  15. syntax region dockerfileFrom matchgroup=dockerfileKeyword start=/\v^\s*(FROM)\ze(\s|$)/ skip=/\v\\\_./ end=/\v((^|\s)AS(\s|$)|$)/ contains=dockerfileOption
  16. syntax keyword dockerfileKeyword contained ADD ARG CMD COPY ENTRYPOINT ENV EXPOSE HEALTHCHECK LABEL MAINTAINER ONBUILD RUN SHELL STOPSIGNAL USER VOLUME WORKDIR
  17. syntax match dockerfileOption contained /\v(^|\s)\zs--\S+/
  18. syntax match dockerfileInstruction contained /\v<(\S+)>(\s+--\S+)*/ contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileValue
  19. syntax match dockerfileInstruction contained /\v<(ADD|COPY)>(\s+--\S+)*/ contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileJSON
  20. syntax match dockerfileInstruction contained /\v<(HEALTHCHECK)>(\s+--\S+)*/ contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileInstruction
  21. syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>/ contains=dockerfileKeyword skipwhite nextgroup=dockerfileShell
  22. syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>\ze\s+\[/ contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
  23. syntax match dockerfileInstruction contained /\v<(SHELL|VOLUME)>/ contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
  24. syntax region dockerfileString contained start=/\v"/ skip=/\v\\./ end=/\v"/
  25. syntax region dockerfileJSON contained keepend start=/\v\[/ skip=/\v\\\_./ end=/\v$/ contains=@JSON
  26. syntax region dockerfileShell contained keepend start=/\v/ skip=/\v\\\_./ end=/\v$/ contains=@Shell
  27. syntax region dockerfileValue contained keepend start=/\v/ skip=/\v\\\_./ end=/\v$/ contains=dockerfileString
  28. syntax region dockerfileComment start=/\v^\s*#/ end=/\v$/
  29. set commentstring=#\ %s
  30. hi def link dockerfileString String
  31. hi def link dockerfileKeyword Keyword
  32. hi def link dockerfileComment Comment
  33. hi def link dockerfileOption Special
  34. let b:current_syntax = "dockerfile"