代码之家  ›  专栏  ›  技术社区  ›  unmounted

如何将Vim更新为新的html元素的颜色代码

  •  24
  • unmounted  · 技术社区  · 14 年前

    我想知道如何设置vim来为新的html5元素(即“canvas”和“video”)上色,就像它对现有的“script”、“body”元素(或python的“def”等其他语言中的保留字)上色一样。当前的版本来自MacPorts,通常在终端仿真器中使用。

    7 回复  |  直到 14 年前
        1
  •  29
  •   ghickman MikeSullivan    13 年前

    html.vim 是Vim用来确定哪些标记将被着色的语法文件。其位置取决于Vim的安装。在这个语法文件中,您将看到许多行,如下所示:

    " new html 4.0 tags
    syn keyword htmlTagName contained abbr acronym bdo button col label
    syn keyword htmlTagName contained colgroup del fieldset iframe ins legend
    syn keyword htmlTagName contained object optgroup q s tbody tfoot thead
    

    abbr , acronym bdo , button , col label 标签。您可以告诉Vim使用以下语法为其他标记上色:

    " new html 5 tags
    syn keyword htmlTagName contained video canvas
    

    video canvas 标签和您添加的任何其他关键字。

    但是,如果您更新内置 它将在下次更新Vim时被覆盖,因此最佳实践是将规则附加到这些内置规则。为此,请创建文件夹路径 after/syntax .vim 文件夹并放置 html.vim文件 在里面。

    这里有大量的HTML5元素和参数 gist 以下@user240515提到。将此内容粘贴到新创建的 html.vim文件 .

    :help html.vim 了解更多信息。

        2
  •  22
  •   Johan    14 年前

    谢谢你的提问,谢谢你的回答!这是要为HTML5添加的新标记的完整列表,它们是在编写本文时定义的:

    " new html 5 tags
    syn keyword htmlTagName contained article aside audio canvas command datalist
    syn keyword htmlTagName contained details embed figcaption figure footer header
    syn keyword htmlTagName contained hgroup keygen mark meter nav output progress
    syn keyword htmlTagName contained rp rt ruby section source summary time video
    
        3
  •  10
  •   TKrugg    12 年前

    我正要试试这个:

    http://github.com/othree/html5.vim

    看起来很完整。

    编辑:我没有看到任何关于缩进的内容(

    编辑[12/23/2012]:我有:)但可能是后来添加的: https://github.com/othree/html5.vim/tree/master/indent

        5
  •  4
  •   Roy    14 年前

    压痕可以使用类似于michaelmichael所描述的扩展压痕的方法来支持 html.vim html.vim文件 ~/.vim/indent 您可以使用找到的内容创建它 here ~/.vim/indent/html.vim

    " [-- <ELEMENT ? - - ...> --]
    call <SID>HtmlIndentPush('a')
    call <SID>HtmlIndentPush('abbr')
    call <SID>HtmlIndentPush('acronym')
    call <SID>HtmlIndentPush('address')
    " ...and many more...
    

    " New HTML 5 elements
    call<SID>HtmlIndentPush('table')
    call<SID>HtmlIndentPush('article')
    call<SID>HtmlIndentPush('aside')
    call<SID>HtmlIndentPush('audio')
    call<SID>HtmlIndentPush('canvas')
    call<SID>HtmlIndentPush('command')
    call<SID>HtmlIndentPush('datalist')
    call<SID>HtmlIndentPush('details')
    call<SID>HtmlIndentPush('embed')
    call<SID>HtmlIndentPush('figcaption')
    call<SID>HtmlIndentPush('figure')
    call<SID>HtmlIndentPush('footer')
    call<SID>HtmlIndentPush('header')
    call<SID>HtmlIndentPush('hgroup')
    call<SID>HtmlIndentPush('keygen')
    call<SID>HtmlIndentPush('mark')
    call<SID>HtmlIndentPush('meter')
    call<SID>HtmlIndentPush('nav')
    call<SID>HtmlIndentPush('output')
    call<SID>HtmlIndentPush('progress')
    call<SID>HtmlIndentPush('rp')
    call<SID>HtmlIndentPush('rt')
    call<SID>HtmlIndentPush('ruby')
    call<SID>HtmlIndentPush('section')
    call<SID>HtmlIndentPush('source')
    call<SID>HtmlIndentPush('summary')
    call<SID>HtmlIndentPush('time')
    call<SID>HtmlIndentPush('video')
    

    缩进现在会在上面列出的HTML5标签上触发。

        6
  •  4
  •   Brian Gershon    14 年前
        7
  •  0
  •   Chad Skeeters    8 年前

    syntax/html.vim vim(8.0)附带的文件是 非常 过时的。保持语法高亮显示更新的一个好方法是使用维护良好的插件,例如 vim-polygot html.vim syntax 支架, canvas video , section main (其他答案不支持),举几个例子。