Dockerfile没有高亮怎么办

整三个文件即可解决

/usr/share/vim/vimfiles/doc/dockerfile.txt

/usr/share/vim/vimfiles/ftdetect/dockerfile.vim

/usr/share/vim/vimfiles/syntax/dockerfile.vim

创建 /usr/share/vim/vimfiles/doc/dockerfile.txt 文件

cat > /usr/share/vim/vimfiles/doc/dockerfile.txt << EOF
    *dockerfile.txt*  Syntax highlighting for Dockerfiles
    
    Author: Honza Pokorny <https://honza.ca>
    License: BSD
    
    INSTALLATION                                                     *installation*
    
    Drop it on your Pathogen path and you're all set.
    
    FEATURES                                                             *features*
    
    The syntax highlighting includes:
    
    * The directives (e.g. FROM)
    * Strings
    * Comments
    
     vim:tw=78:et:ft=help:norl:
EOF

创建 /usr/share/vim/vimfiles/ftdetect/dockerfile.vim 文件

cat > /usr/share/vim/vimfiles/ftdetect/dockerfile.vim << EOF
    au BufNewFile,BufRead [Dd]ockerfile,Dockerfile.*,*.Dockerfile set filetype=dockerfile
EOF

创建 /usr/share/vim/vimfiles/syntax/dockerfile.vim 文件

cat > /usr/share/vim/vimfiles/syntax/dockerfile.vim << EOF
    " dockerfile.vim - Syntax highlighting for Dockerfiles
    " Maintainer:   Honza Pokorny <https://honza.ca>
    " Version:      0.5
    
    
    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/
    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
    
    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)
EOF

然后再次打开 Dockerfile ,可以看到高亮有了

 

评论 1 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:书香水墨 设计师:CSDN官方博客 返回首页

打赏作者

运维攻城狮 Linke

哥不缺钱,给个赞就行

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值