• vim编辑Dockerfile时语法高亮


    参考Dockerfile构建容器---语法高亮

    三个文件扔进相关的目录即可

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

        *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:
    

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

        au BufNewFile,BufRead [Dd]ockerfile,Dockerfile.*,*.Dockerfile set filetype=dockerfile
    

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

        " 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*(ONBUILDs+)?(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)
    

    效果展示

    附录

    上面三个文件的git地址

  • 相关阅读:
    快速排序和归并排序的迭代实现
    Longest Increasing Subsequence Review
    IOCCC 1987 最佳单行代码解读
    C++类的成员函数对应的链接器符号的解析
    Scalable Global ID Generator Design
    欧拉回路 (Euler Circuit) POJ 1780
    深入理解函数内静态局部变量初始化
    memcached 线程模型
    类的加载与ClassLoader的理解
    字符集常见码表说明
  • 原文地址:https://www.cnblogs.com/ifme/p/11797111.html
Copyright © 2020-2023  润新知