2010-07-12 64 views
23

我想知道如何设置vim来为新的html5元素(即“canvas”和“video”)着色,就像它与现有的“script”,“body “元素(或其他语言中的保留字,如python的”def“)等等。当前版本来自通常用于终端仿真器的MacPorts。如何将Vim更新为颜色代码新的html元素

回答

29

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 

这些行定义了语法关键字。在这种情况下,他们专门定义HTML标签名称。第一行告诉Vim颜色abbr,acronym,bdo,button,collabel标签。你可以告诉Vim颜色附加标签的语法如下:

" new html 5 tags 
syn keyword htmlTagName contained video canvas 

现在,Vim将颜色videocanvas标签和你添加任何额外的关键字。

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

以下@ user240515提到的这个gist中有大量的HTML 5元素和参数。将这些内容粘贴到新创建的html.vim中。

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

+0

谢谢mikemike – unmounted 2010-07-13 23:16:54

+0

@michaelmichael谢谢,但对我来说不起作用,我在他的回答中加入了@johan说的几句话,但我没有在'

'标记中突出显示......例如,文件夹的权限/文件与常规语法文件中的相同。在这里你有文件的内容:http://pastebin.com/cp8qYDze – ziiweb 2013-04-24 18:03:06

22

感谢这个问题,并感谢您接受的答案!这是新标签的完整列表添加对HTML 5,因为它们是在写作的时候定义:

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

我只是要试试这个:

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

似乎相当完整。

编辑:我没有看到任何关于缩进。 :(

EDIT [2012年12月23日]:我做的:)但也许就是后来补充说:https://github.com/othree/html5.vim/tree/master/indent

+0

对于大量的html5 javascript api(“onmousewheel”,“ondragstart”)很好,omnicomplete – unmounted 2010-09-14 09:04:53

+0

安装它的一种方法是:'git clone https:// github.com/othree/html5.vim“,然后进入该目录并执行:make install。它会将所有必需的文件安装到〜/ .vim目录中。大约需要1秒。 – lepe 2016-05-03 04:27:10

4

压痕可以使用类似于由michaelmichael用于扩展html.vim语法文件中描述的方法来支持。如果您的~/.vim/indent中没有html.vim,则可以使用here的内容创建它。内~/.vim/indent/html.vim,你会看到一个函数调用集组装,看起来像下面的HTML元素的名称列表:

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

这些行定义将触发基本标签缩进标记。使用任何您希望触发缩进的HTML5标记扩展此列表。我添加了下面这个列表的末尾:

" 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标签触发。

0

syntax/html.vim文件附带vim(8.0)是非常过时。保持语法高亮更新的好方法是使用一个维护良好的插件,例如vim-polygot,它保持更新。这是html.vim syntax支持,canvasvideo, sectionmain(其他答案不支持),仅举几例。

相关问题