neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

dockerfile.vim (2466B)


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