Skip to content

Instantly share code, notes, and snippets.

@hotoo
Created July 15, 2010 02:01
Show Gist options
  • Save hotoo/476387 to your computer and use it in GitHub Desktop.
Save hotoo/476387 to your computer and use it in GitHub Desktop.
--langdef=html
--langmap=html:.htm.html
--regex-html=/<h1[^>]*>(.*)<\/h1>/\1/h,header/
--regex-html=/<h2[^>]*>(.*)<\/h2>/. \1/h,header/
--regex-html=/<h3[^>]*>(.*)<\/h3>/. \1/h,header/
--regex-html=/<h4[^>]*>(.*)<\/h4>/. \1/h,header/
--regex-html=/<h5[^>]*>(.*)<\/h5>/. \1/h,header/
--regex-html=/<h6[^>]*>(.*)<\/h6>/. \1/h,header/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+id[ \t]*=[ \t]*'([^']+)'/\1#\2/o,object/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+id[ \t]*=[ \t]*"([^"]+)"/\1#\2/o,object/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+id[ \t]*=[ \t]*([A-Za-z][A-Za-z0-9_:.-]*)[ \t>]/\1#\2/o,object/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+class[ \t]*=[ \t]*'([^']+)'/\1.\2/c,class/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+class[ \t]*=[ \t]*"([^"]+)"/\1.\2/c,class/
--regex-html=/<([a-zA-Z][a-zA-Z0-9]*)[^>]*[ \t]+class[ \t]*=[ \t]*([A-Za-z][A-Za-z0-9_:.-]*)[ \t>]/\1.\2/c,class/
let tlist_html_settings = 'html;h:Headers;o:Objects(ID);c:Classes'
let tlist_xhtml_settings = 'html;h:Headers;o:Objects(ID);c:Classes'
@donson
Copy link

donson commented Jul 15, 2010

这个要怎么用呢?

@hotoo
Copy link
Author

hotoo commented Jul 15, 2010

  1. 前提:安装好 ctags 和 TagList.vim
  2. 将 html.ctags 保存为 .ctags (Windows 可以保存为 ctags.cnf ),放置在 $HOME (即用户目录)下;
  3. 将 html.vimrc 代码加入到 vimrc 中即可。

ID 和 Class 的命名规则参考:
http://www.w3.org/TR/html401/struct/global.html#h-7.5.2
http://www.w3.org/TR/html401/types.html#type-name
http://www.w3.org/TR/html401/types.html#type-cdata

缺陷:
ctags 目前不支持正则表达式的非贪婪匹配,所以类似 <h1>A</h1><h1>B</h1> 会被解析为 A</h1><h1>B ,
另外其中标签也会被保留,不做处理。

@donson
Copy link

donson commented Jul 15, 2010

好的,谢谢了,我现在去试下

@donson
Copy link

donson commented Jul 15, 2010

css能用上,但html的用不了,好像是ctags 5.8原来就对html有定义。。。

@hotoo
Copy link
Author

hotoo commented Jul 15, 2010

不知道你的什么情况,能详细描述清楚吗?
另外你用的什么系统、Vim 版本?

@donson
Copy link

donson commented Jul 16, 2010

winXP,vim 7.2,ctags 5.8,taglist 4.5,就是在html文件上打开taglist时,什么也不显示,但php那些文件就有
后来我看文档发现ctags 5.8,taglist 4.5本来就支持html,但也没有,taglist的窗口什么内容也没有

@hotoo
Copy link
Author

hotoo commented Jul 16, 2010

是的,就是因为什么都没有,所以自己来修改了。
ctags 可以很方便的扩展新语言或者修改现有语言的。

你说的“但html的用不了”是怎么回事,加上上面的代码还是没有内容吗?

@donson
Copy link

donson commented Jul 16, 2010

问题解决了,原因比较囧。。。
看到你最新更新的这一句let tlist_xhtml_settings = 'html;h:Headers;o:Objects(ID);c:Classes',我加到vim的配置文件上,就可以用了。。。原来我的html文件类型都是xhtml....

@donson
Copy link

donson commented Jul 16, 2010

谢谢了,呵呵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment