vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

dockerfile.vim (2552B)


      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 
      9 if exists("b:current_syntax")
     10     finish
     11 endif
     12 
     13 syntax include @JSON syntax/json.vim
     14 unlet b:current_syntax
     15 
     16 syntax include @Shell syntax/sh.vim
     17 unlet b:current_syntax
     18 
     19 syntax case ignore
     20 syntax match dockerfileLinePrefix /\v^\s*(ONBUILD\s+)?\ze\S/ contains=dockerfileKeyword nextgroup=dockerfileInstruction skipwhite
     21 syntax region dockerfileFrom matchgroup=dockerfileKeyword start=/\v^\s*(FROM)\ze(\s|$)/ skip=/\v\\\_./ end=/\v((^|\s)AS(\s|$)|$)/ contains=dockerfileOption
     22 
     23 syntax keyword dockerfileKeyword contained ADD ARG CMD COPY ENTRYPOINT ENV EXPOSE HEALTHCHECK LABEL MAINTAINER ONBUILD RUN SHELL STOPSIGNAL USER VOLUME WORKDIR
     24 syntax match dockerfileOption contained /\v(^|\s)\zs--\S+/
     25 
     26 syntax match dockerfileInstruction contained /\v<(\S+)>(\s+--\S+)*/             contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileValue
     27 syntax match dockerfileInstruction contained /\v<(ADD|COPY)>(\s+--\S+)*/        contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileJSON
     28 syntax match dockerfileInstruction contained /\v<(HEALTHCHECK)>(\s+--\S+)*/     contains=dockerfileKeyword,dockerfileOption skipwhite nextgroup=dockerfileInstruction
     29 syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>/         contains=dockerfileKeyword skipwhite nextgroup=dockerfileShell
     30 syntax match dockerfileInstruction contained /\v<(CMD|ENTRYPOINT|RUN)>\ze\s+\[/ contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
     31 syntax match dockerfileInstruction contained /\v<(SHELL|VOLUME)>/               contains=dockerfileKeyword skipwhite nextgroup=dockerfileJSON
     32 
     33 syntax region dockerfileString contained start=/\v"/ skip=/\v\\./ end=/\v"/
     34 syntax region dockerfileJSON   contained keepend start=/\v\[/ skip=/\v\\\_./ end=/\v$/ contains=@JSON
     35 syntax region dockerfileShell  contained keepend start=/\v/ skip=/\v\\\_.|^\s*#.*/ end=/\v$/ contains=@Shell
     36 syntax region dockerfileValue  contained keepend start=/\v/ skip=/\v\\\_./ end=/\v$/ contains=dockerfileString
     37 
     38 syntax region dockerfileComment start=/\v^\s*#/ end=/\v$/ contains=@Spell
     39 
     40 hi def link dockerfileString String
     41 hi def link dockerfileKeyword Keyword
     42 hi def link dockerfileComment Comment
     43 hi def link dockerfileOption Special
     44 
     45 let b:current_syntax = "dockerfile"