diff options
Diffstat (limited to '')
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | build | 2 | ||||
-rw-r--r-- | ftdetect/polyglot.vim | 19 | ||||
-rw-r--r-- | ftplugin/Dockerfile.vim | 31 | ||||
-rw-r--r-- | indent/Dockerfile.vim | 27 | ||||
-rw-r--r-- | syntax/docker-compose.vim | 89 | ||||
-rw-r--r-- | syntax/dockerfile.vim | 73 |
7 files changed, 221 insertions, 22 deletions
@@ -63,7 +63,7 @@ If you need full functionality of any plugin, please use it directly with your p - [crystal](https://github.com/rhysd/vim-crystal) (syntax, indent, autoload, ftplugin) - [cucumber](https://github.com/tpope/vim-cucumber) (syntax, indent, compiler, ftplugin) - [dart](https://github.com/dart-lang/dart-vim-plugin) (syntax, indent, autoload, ftplugin) -- [dockerfile](https://github.com/docker/docker) (syntax) +- [dockerfile](https://github.com/ekalinin/Dockerfile.vim) (syntax, indent, ftplugin) - [elixir](https://github.com/elixir-lang/vim-elixir) (syntax, indent, compiler, autoload, ftplugin) - [elm](https://github.com/ElmCast/elm-vim) (syntax, indent, autoload, ftplugin) - [emberscript](https://github.com/yalesov/vim-ember-script) (syntax, indent, ftplugin) @@ -172,7 +172,7 @@ PACKS=" cql:elubow/cql-vim cucumber:tpope/vim-cucumber dart:dart-lang/dart-vim-plugin - dockerfile:docker/docker::/contrib/syntax/vim/ + dockerfile:ekalinin/Dockerfile.vim elixir:elixir-lang/vim-elixir elm:ElmCast/elm-vim emberscript:yalesov/vim-ember-script diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 5eaa9325..62aaf3ab 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -240,6 +240,25 @@ autocmd BufRead,BufNewFile *.dart set filetype=dart augroup end endif +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 + augroup filetypedetect + " dockerfile, from Dockerfile.vim in ekalinin/Dockerfile.vim +" Dockerfile +autocmd BufRead,BufNewFile Dockerfile set ft=Dockerfile +autocmd BufRead,BufNewFile Dockerfile* set ft=Dockerfile +autocmd BufRead,BufNewFile *.dock set ft=Dockerfile +autocmd BufRead,BufNewFile *.[Dd]ockerfile set ft=Dockerfile + augroup end +endif + +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 + augroup filetypedetect + " dockerfile, from docker-compose.vim in ekalinin/Dockerfile.vim +" docker-compose.yml +autocmd BufRead,BufNewFile docker-compose*.{yaml,yml}* set ft=yaml.docker-compose + augroup end +endif + if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elm') == -1 augroup filetypedetect " elm, from elm.vim in ElmCast/elm-vim diff --git a/ftplugin/Dockerfile.vim b/ftplugin/Dockerfile.vim new file mode 100644 index 00000000..a9bba59a --- /dev/null +++ b/ftplugin/Dockerfile.vim @@ -0,0 +1,31 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 + +function! DockerfileReplaceInstruction(original, replacement) + let syn = synIDtrans(synID(line("."), col(".") - 1, 0)) + if syn != hlID("Comment") && syn != hlID("Constant") && strlen(getline(".")) == 0 + let word = a:replacement + else + let word = a:original + endif + let g:UnduBuffer = a:original + return word +endfunction + +inoreabbr <silent> <buffer> from <C-R>=DockerfileReplaceInstruction("from", "FROM")<CR> +inoreabbr <silent> <buffer> maintainer <C-R>=DockerfileReplaceInstruction("maintainer", "MAINTAINER")<CR> +inoreabbr <silent> <buffer> run <C-R>=DockerfileReplaceInstruction("run", "RUN")<CR> +inoreabbr <silent> <buffer> cmd <C-R>=DockerfileReplaceInstruction("cmd", "CMD")<CR> +inoreabbr <silent> <buffer> label <C-R>=DockerfileReplaceInstruction("label", "LABEL")<CR> +inoreabbr <silent> <buffer> expose <C-R>=DockerfileReplaceInstruction("expose", "EXPOSE")<CR> +inoreabbr <silent> <buffer> env <C-R>=DockerfileReplaceInstruction("env", "ENV")<CR> +inoreabbr <silent> <buffer> add <C-R>=DockerfileReplaceInstruction("add", "ADD")<CR> +inoreabbr <silent> <buffer> copy <C-R>=DockerfileReplaceInstruction("copy", "COPY")<CR> +inoreabbr <silent> <buffer> entrypoint <C-R>=DockerfileReplaceInstruction("entrypoint", "ENTRYPOINT")<CR> +inoreabbr <silent> <buffer> volume <C-R>=DockerfileReplaceInstruction("volume", "VOLUME")<CR> +inoreabbr <silent> <buffer> user <C-R>=DockerfileReplaceInstruction("user", "USER")<CR> +inoreabbr <silent> <buffer> workdir <C-R>=DockerfileReplaceInstruction("workdir", "WORKDIR")<CR> +inoreabbr <silent> <buffer> arg <C-R>=DockerfileReplaceInstruction("arg", "ARG")<CR> +inoreabbr <silent> <buffer> onbuild <C-R>=DockerfileReplaceInstruction("onbuild", "ONBUILD")<CR> +inoreabbr <silent> <buffer> stopsignal <C-R>=DockerfileReplaceInstruction("stopsignal", "STOPSIGNAL")<CR> + +endif diff --git a/indent/Dockerfile.vim b/indent/Dockerfile.vim new file mode 100644 index 00000000..a4ba894c --- /dev/null +++ b/indent/Dockerfile.vim @@ -0,0 +1,27 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 + +if exists('b:did_indent') | finish | endif +let b:did_indent = 1 + + +function! DockerfileIndent(line) + let prev_line = getline(a:line - 1) + if a:line > 1 && prev_line =~ '\\\s*$' + let i = indent(a:line - 1) + if i == 0 + let i += &l:shiftwidth + if &l:expandtab && prev_line =~# '^RUN\s' + " Overindent past RUN + let i = 4 + &l:shiftwidth + endif + endif + return i + endif + + return -1 +endfunction + + +set indentexpr=DockerfileIndent(v:lnum) + +endif diff --git a/syntax/docker-compose.vim b/syntax/docker-compose.vim new file mode 100644 index 00000000..d94e3d50 --- /dev/null +++ b/syntax/docker-compose.vim @@ -0,0 +1,89 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 + +" Vim syntax file +" Language: Dockerfile +" Maintainer: Eugene Kalinin +" Latest Revision: 11 September 2013 +" Source: http://docs.docker.io/en/latest/use/builder/ + +if exists("b:current_syntax") + finish +endif + +" case sensitivity (fix #17) +" syn case ignore + +" Keywords +syn keyword dockercomposeKeywords build context dockerfile args cap_add cap_drop +syn keyword dockercomposeKeywords command cgroup_parent container_name devices depends_on +syn keyword dockercomposeKeywords dns dns_search tmpfs entrypoint env_file environment +syn keyword dockercomposeKeywords expose extends extends external_links extra_hosts +syn keyword dockercomposeKeywords group_add image isolation labels links +syn keyword dockercomposeKeywords log_opt net network_mode networks aliases +syn keyword dockercomposeKeywords ipv4_address ipv6_address link_local_ips pid ports +syn keyword dockercomposeKeywords security_opt stop_signal ulimits volumes volume_driver +syn keyword dockercomposeKeywords volumes_from cpu_shares cpu_quota cpuset domainname hostname +syn keyword dockercomposeKeywords ipc mac_address mem_limit memswap_limit oom_score_adj privileged +syn keyword dockercomposeKeywords read_only restart shm_size stdin_open tty user working_dir +syn keyword dockercomposeKeywords healthcheck test interval timeout retries disable sysctls +syn keyword dockercomposeKeywords userns_mode secrets +"" Volume configuration reference +syn keyword dockercomposeKeywords driver driver_opts external labels +"" Network configuration reference +syn keyword dockercomposeKeywords driver driver_opts enable_ipv6 ipam internal labels external +"" Versioning +syn keyword dockercomposeKeywords version services +"" Logging +syn keyword dockercomposeKeywords logging log_driver env options max-size max-file +syn keyword dockercomposeKeywords syslog-address syslog-facility syslog-tls-ca-cert syslog-tls-cert +syn keyword dockercomposeKeywords syslog-tls-key syslog-tls-skip tag syslog-format gelf-address +syn keyword dockercomposeKeywords gelf-compression-type gelf-compression-level fluentd-address +syn keyword dockercomposeKeywords fluentd-buffer-limit fluentd-retry-wait fluentd-max-retries +syn keyword dockercomposeKeywords fluentd-async-connect awslogs-region awslogs-group awslogs-stream +syn keyword dockercomposeKeywords splunk-token splunk-url splunk-source splunk-sourcetype splunk-index +syn keyword dockercomposeKeywords splunk-capath splunk-caname splunk-insecureskipverify gcp-project log-cmd + +" Bash statements +setlocal iskeyword+=- +syn keyword bashStatement add-apt-repository adduser apk apt-get aptitude apt-key autoconf bundle +syn keyword bashStatement cd chgrp chmod chown clear complete composer cp curl du echo egrep +syn keyword bashStatement expr fgrep find gem gnufind gnugrep gpg grep groupadd head less ln +syn keyword bashStatement ls make mkdir mv node npm pacman pip pip3 php python rails rm rmdir rpm ruby +syn keyword bashStatement sed sleep sort strip tar tail tailf touch useradd virtualenv yum +syn keyword bashStatement usermod bash cat a2ensite a2dissite a2enmod a2dismod apache2ctl +syn keyword bashStatement wget gzip + +" Strings +syn region dockercomposeString start=/"/ skip=/\\"/ end=/"/ +syn region dockercomposeString1 start=/'/ skip=/\\'/ end=/'/ + +" Emails +syn region dockercomposeEmail start=/</ end=/>/ contains=@ oneline + +" Urls +syn match dockercomposeUrl /\(http\|https\|ssh\|hg\|git\)\:\/\/[a-zA-Z0-9\/\-\.]\+/ + +" Task tags +syn keyword dockercomposeTodo contained TODO FIXME XXX + +" Comments +syn region dockercomposeComment start="#" end="\n" contains=dockercomposeTodo + +" Highlighting +hi link dockercomposeKeywords Keyword +hi link dockercomposeString String +hi link dockercomposeString1 String +hi link dockercomposeComment Comment +hi link dockercomposeEmail Identifier +hi link dockercomposeUrl Identifier +hi link dockercomposeTodo Todo +hi link bashStatement Function + +let b:current_syntax = "dockercompose" + +set commentstring=#\ %s + +" Enable automatic comment insertion +setlocal fo+=cro + +endif diff --git a/syntax/dockerfile.vim b/syntax/dockerfile.vim index 1c768de7..726240fa 100644 --- a/syntax/dockerfile.vim +++ b/syntax/dockerfile.vim @@ -1,35 +1,68 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1 -" dockerfile.vim - Syntax highlighting for Dockerfiles -" Maintainer: Honza Pokorny <https://honza.ca> -" Version: 0.5 - +" Vim syntax file +" Language: Dockerfile +" Maintainer: Eugene Kalinin +" Latest Revision: 11 September 2013 +" Source: http://docs.docker.io/en/latest/use/builder/ if exists("b:current_syntax") - finish + finish endif -let b:current_syntax = "dockerfile" +" case sensitivity (fix #17) +" syn case ignore + +" Keywords +syn keyword dockerfileKeywords FROM AS MAINTAINER RUN CMD COPY +syn keyword dockerfileKeywords EXPOSE ADD ENTRYPOINT +syn keyword dockerfileKeywords VOLUME USER WORKDIR ONBUILD +syn keyword dockerfileKeywords LABEL ARG HEALTHCHECK SHELL + +" Bash statements +setlocal iskeyword+=- +syn keyword bashStatement add-apt-repository adduser apk apt-get aptitude apt-key autoconf bundle +syn keyword bashStatement cd chgrp chmod chown clear complete composer cp curl du echo egrep +syn keyword bashStatement expr fgrep find gem gnufind gnugrep gpg grep groupadd head less ln +syn keyword bashStatement ls make mkdir mv node npm pacman pip pip3 php python rails rm rmdir rpm ruby +syn keyword bashStatement sed sleep sort strip tar tail tailf touch useradd virtualenv yum +syn keyword bashStatement usermod bash cat a2ensite a2dissite a2enmod a2dismod apache2ctl +syn keyword bashStatement wget gzip -syntax case ignore +" Strings +syn region dockerfileString start=/"/ skip=/\\"|\\\\/ end=/"/ +syn region dockerfileString1 start=/'/ skip=/\\'|\\\\/ end=/'/ -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/ -highlight link dockerfileKeyword Keyword +" Emails +syn region dockerfileEmail start=/</ end=/>/ contains=@ oneline -syntax region dockerfileString start=/\v"/ skip=/\v\\./ end=/\v"/ -highlight link dockerfileString String +" Urls +syn match dockerfileUrl /\(http\|https\|ssh\|hg\|git\)\:\/\/[a-zA-Z0-9\/\-\.]\+/ -syntax match dockerfileComment "\v^\s*#.*$" -highlight link dockerfileComment Comment +" Task tags +syn keyword dockerfileTodo contained TODO FIXME XXX + +" Comments +syn region dockerfileComment start="#" end="\n" contains=dockerfileTodo +syn region dockerfileEnvWithComment start="^\s*ENV\>" end="\n" contains=dockerfileEnv +syn match dockerfileEnv contained /\<ENV\>/ + +" Highlighting +hi link dockerfileKeywords Keyword +hi link dockerfileEnv Keyword +hi link dockerfileString String +hi link dockerfileString1 String +hi link dockerfileComment Comment +hi link dockerfileEmail Identifier +hi link dockerfileUrl Identifier +hi link dockerfileTodo Todo +hi link bashStatement Function + +let b:current_syntax = "dockerfile" set commentstring=#\ %s -" 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) +" Enable automatic comment insertion +setlocal fo+=cro endif |