如何更新Vim以对新的html元素进行颜色编码 [英] How to update Vim to color-code new html elements

查看:98
本文介绍了如何更新Vim以对新的html元素进行颜色编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何设置vim来为现有的脚本,body元素(或其他语言中的保留字,如python's)添加新的html5元素(即canvas和video) def)等等。当前版本来自通常用于终端仿真器的MacPorts。 html .vim 是Vim咨询确定哪些标签将被着色的语法文件。这个位置取决于您安装的Vim。在这个语法文件中,您会看到很多行,如下所示:

 new html 4.0 tags 
syn关键字htmlTagName contains abbr acronym bdo按钮col标签
syn关键字htmlTagName包含colgroup del字段集iframe ins图例
syn关键字htmlTagName包含对象optgroup qs tbody tfoot thead

这些行定义了语法关键字,在这种情况下,它们专门定义了HTML标签名。第一行告诉Vim给 abbr acronym bdo 按钮 col 标签标签,您可以告诉Vim使用以下语法为其他标签着色:

 new html 5 tags 
syn关键字htmlTagName包含视频画布

Vim现在将着色视频画布标签以及任何其他关键字你添加。



但是如果你更新内置的 html.vim 下次更新Vim时会被覆盖,因此最佳做法是将规则附加到这些内置的规则中。为此,请在 .vim 文件夹中的/ syntax 之后创建文件夹路径,并将 html.vim



在这个 gist 。将这些内容粘贴到新创建的 html.vim 中。



请参阅:help html.vim 获取更多信息。


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

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 will now color video and canvas tags and any additional keywords you add.

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.

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.

Consult :help html.vim for some more info.

这篇关于如何更新Vim以对新的html元素进行颜色编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆