robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #39435 from zeertzjq/vim-0ca1121f69aadd2b4

master
2.5 KiB45 linesraw
1" dockerfile.vim - Syntax highlighting for Dockerfiles
2" Maintainer:   Honza Pokorny <https://honza.ca>
3" Last Change:  2024 Dec 20
4"               2026 Mar 26 by Vim Project: dockerfileShell comments (#19829)
5" License:      BSD
6
7" https://docs.docker.com/engine/reference/builder/
8
9if exists("b:current_syntax")
10    finish
11endif
12
13syntax include @JSON syntax/json.vim
14unlet b:current_syntax
15
16syntax include @Shell syntax/sh.vim
17unlet b:current_syntax
18
19syntax case ignore
20syntax match dockerfileLinePrefix /\v^\s*(ONBUILD\s+)?\ze\S/ contains=dockerfileKeyword nextgroup=dockerfileInstruction skipwhite
21syntax region dockerfileFrom matchgroup=dockerfileKeyword start=/\v^\s*(FROM)\ze(\s|$)/ skip=/\v\\\_./ end=/\v((^|\s)AS(\s|$)|$)/ contains=dockerfileOption
22
23syntax keyword dockerfileKeyword contained ADD ARG CMD COPY ENTRYPOINT ENV EXPOSE HEALTHCHECK LABEL MAINTAINER ONBUILD RUN SHELL STOPSIGNAL USER VOLUME WORKDIR
24syntax match dockerfileOption contained /\v(^|\s)\zs--\S+/
25
26syntax match dockerfileInstruction contained /\v<(\S+)>(\s+--\S+)*/             contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileValue
27syntax match dockerfileInstruction contained /\v<(ADD|COPY)>(\s+--\S+)*/        contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileJSON
28syntax match dockerfileInstruction contained /\v<(HEALTHCHECK)>(\s+--\S+)*/     contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileInstruction
29syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>/         contains=dockerfileKeyword skipwhite nextgroup=dockerfileShell
30syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>\ze\s+\[/ contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
31syntax match dockerfileInstruction contained /\v<(SHELL|VOLUME)>/               contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
32
33syntax region dockerfileString contained start=/\v"/ skip=/\v\\./ end=/\v"/
34syntax region dockerfileJSON   contained keepend start=/\v\[/ skip=/\v\\\_./ end=/\v$/ contains=@JSON
35syntax region dockerfileShell  contained keepend start=/\v/ skip=/\v\\\_.|^\s*#.*/ end=/\v$/ contains=@Shell
36syntax region dockerfileValue  contained keepend start=/\v/ skip=/\v\\\_./ end=/\v$/ contains=dockerfileString
37
38syntax region dockerfileComment start=/\v^\s*#/ end=/\v$/ contains=@Spell
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"