如何更新 Vim 以对新的 html 元素进行颜色编码 [英] How to update Vim to color-code new html elements
问题描述
我想知道如何设置 vim 来为新的 html5 元素(即画布"和视频")着色,就像它对现有的脚本"、正文"元素(或其他语言中的保留字,如 python 的"def") 等.当前版本来自 MacPorts,通常用于终端模拟器.
I am wondering how I might set vim to color the new html5 elements (ie "canvas" and "video") as it does with the existing "script", "body" elements (or reserved words in other languages like python's "def") etc. Current version is from MacPorts typically used in a terminal emulator.
推荐答案
html.vim
是 Vim 参考的语法文件,以确定哪些标签将被着色.它的位置取决于您安装的 Vim.在此语法文件中,您将看到许多如下所示的行:
html.vim
is the syntax file Vim consults to determine which tags will be colored. The location of this will depend on your installation of Vim. Within this syntax file you'll see many lines that look like the following:
" 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
这些行定义了语法关键字.在这种情况下,它们专门定义了 HTML 标记名称.第一行告诉 Vim 给 abbr
、acronym
、bdo
、button
、col
着色> 和 label
标签.您可以使用以下语法告诉 Vim 为其他标签着色:
These lines define syntax keywords. In this case they specifically define HTML tag names. The first line tells Vim to color abbr
, acronym
, bdo
, button
, col
, and label
tags. You can tell Vim to color additional tags with the following syntax:
" new html 5 tags
syn keyword htmlTagName contained video canvas
Vim 现在将为 video
和 canvas
标签以及您添加的任何其他关键字着色.
Vim will now color video
and canvas
tags and any additional keywords you add.
但是,如果您更新内置的 html.vim
,它会在您下次更新 Vim 时被覆盖,因此最佳做法是将您的规则附加到这些内置的规则中.为此,在您的 .vim
文件夹中创建文件夹路径 after/syntax
并在其中放置一个 html.vim
.
However if you update the built-in html.vim
it will get overwritten the next time you update Vim, so the best practice is to append your rules to these built-in ones. To do so create the folder path after/syntax
in your .vim
folder and place a html.vim
in it.
下面@user240515 提到的这个 gist 中有大量的 HTML 5 元素和参数.将其内容粘贴到您新创建的 html.vim
中.
There are a large number of the HTML 5 elements and arguments in this gist mentioned by @user240515 below. Paste the contents of this into your newly create html.vim
.
有关更多信息,请参阅 :help html.vim
.
Consult :help html.vim
for some more info.
这篇关于如何更新 Vim 以对新的 html 元素进行颜色编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!