blob: da3a3fc9d28cfcaf4c8058b22a3fd260af16b35d [file] [log] [blame]
Bram Moolenaar34401cc2014-08-29 15:12:19 +02001" dockerfile.vim - Syntax highlighting for Dockerfiles
Bram Moolenaar09521312016-08-12 22:54:35 +02002" Maintainer: Honza Pokorny <https://honza.ca>
Bram Moolenaar560979e2020-02-04 22:53:05 +01003" Last Change: 2020 Jan 27
Bram Moolenaar34401cc2014-08-29 15:12:19 +02004" License: BSD
5
Bram Moolenaar560979e2020-02-04 22:53:05 +01006" https://docs.docker.com/engine/reference/builder/
Bram Moolenaar34401cc2014-08-29 15:12:19 +02007
8if exists("b:current_syntax")
9 finish
10endif
11
Bram Moolenaar560979e2020-02-04 22:53:05 +010012syntax include @JSON syntax/json.vim
13unlet b:current_syntax
14
15syntax include @Shell syntax/sh.vim
16unlet b:current_syntax
Bram Moolenaar34401cc2014-08-29 15:12:19 +020017
18syntax case ignore
Bram Moolenaar560979e2020-02-04 22:53:05 +010019syntax 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
Bram Moolenaar34401cc2014-08-29 15:12:19 +020021
Bram Moolenaar560979e2020-02-04 22:53:05 +010022syntax 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+/
Bram Moolenaar34401cc2014-08-29 15:12:19 +020024
Bram Moolenaar560979e2020-02-04 22:53:05 +010025syntax 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
Bram Moolenaar56c860c2019-08-17 20:09:31 +020031
Bram Moolenaar560979e2020-02-04 22:53:05 +010032syntax 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
Bram Moolenaar34401cc2014-08-29 15:12:19 +020036
Bram Moolenaar560979e2020-02-04 22:53:05 +010037syntax region dockerfileComment start=/\v^\s*#/ end=/\v$/
38set commentstring=#\ %s
Bram Moolenaar34401cc2014-08-29 15:12:19 +020039
40hi def link dockerfileString String
41hi def link dockerfileKeyword Keyword
42hi def link dockerfileComment Comment
Bram Moolenaar560979e2020-02-04 22:53:05 +010043hi def link dockerfileOption Special
44
45let b:current_syntax = "dockerfile"