vim-polyglot/syntax/dockerfile.vim

64 lines
2.1 KiB
VimL
Raw Normal View History

if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vim') == -1
" dockerfile.vim - Syntax highlighting for Dockerfiles
" Maintainer: Honza Pokorny <https://honza.ca>
" Version: 0.6
" Last Change: 2016 Aug 9
" License: BSD
if exists("b:current_syntax")
finish
endif
let b:current_syntax = "dockerfile"
syntax case ignore
syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)\s/
syntax region dockerfileString start=/\v"/ skip=/\v\\./ end=/\v"/
syntax match dockerfileComment "\v^\s*#.*$"
hi def link dockerfileString String
hi def link dockerfileKeyword Keyword
hi def link dockerfileComment Comment
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1
2013-09-26 06:48:01 -04:00
" dockerfile.vim - Syntax highlighting for Dockerfiles
" Maintainer: Honza Pokorny <https://honza.ca>
2013-09-26 06:48:01 -04:00
" Version: 0.5
if exists("b:current_syntax")
finish
endif
let b:current_syntax = "dockerfile"
2013-09-26 06:48:01 -04:00
syntax case ignore
syntax match dockerfileKeyword /\v^\s*(ONBUILD\s+)?(ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR)\s/
2013-09-26 06:48:01 -04:00
highlight link dockerfileKeyword Keyword
syntax region dockerfileString start=/\v"/ skip=/\v\\./ end=/\v"/
highlight link dockerfileString String
syntax match dockerfileComment "\v^\s*#.*$"
highlight link dockerfileComment Comment
2014-11-10 20:37:21 -05:00
set commentstring=#\ %s
2014-11-10 20:37:21 -05:00
" match "RUN", "CMD", and "ENTRYPOINT" lines, and parse them as shell
let s:current_syntax = b:current_syntax
unlet b:current_syntax
syntax include @SH syntax/sh.vim
let b:current_syntax = s:current_syntax
syntax region shLine matchgroup=dockerfileKeyword start=/\v^\s*(RUN|CMD|ENTRYPOINT)\s/ end=/\v$/ contains=@SH
" since @SH will handle "\" as part of the same line automatically, this "just works" for line continuation too, but with the caveat that it will highlight "RUN echo '" followed by a newline as if it were a block because the "'" is shell line continuation... not sure how to fix that just yet (TODO)
endif