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