VIM:不要在 HTML 链接中给前导空格加下划线 [英] VIM: Don't underline leading whitespace in HTML links

查看:30
本文介绍了VIM:不要在 HTML 链接中给前导空格加下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么是vim 在标签的位置画下划线以及如何避免这种情况?

在 CentOS 5.x 上的 VIM 7.0 中缩进 PHP 代码时,HTML 链接显示为下划线.这非常方便,但在某些地方,我在该 HTML 中缩进了 PHP 代码,并且整个缩进都带有下划线:

When indenting PHP code in VIM 7.0 on CentOS 5.x, HTML links are shown underlined. This is very handy, but in some places I have indented PHP code in that HTML, and the whole indentation is underlined:

            <li class="picture">
________________<a href="<?=$linkUrl?>">
____________________<img src="/<?=$img['source']?>" alt="Picture"/>
____________________<? if ($someCondition): ?><span class="info"><?=$img['info']?></span><? endif; ?>
________________</a>
            </li>

有没有办法告诉语法高亮器忽略 HTML 链接中的行前空白?

Is there any way to tell the syntax highlighter to ignore line-leading whitespace in HTML links?

推荐答案

我通过修改 $VIMRUNTIME/syntax/html.vim 设法实现了这一点.复制到~/.vim/syntax/html.vim(.vim 在Windows 上被命名为vimfiles),并替换原来的语法定义

I managed to achieve this through modifying $VIMRUNTIME/syntax/html.vim. Make a copy to ~/.vim/syntax/html.vim (.vim is named vimfiles on Windows), and replace the original syntax definition

syn region htmlLink start="<a\>\_[^>]*\<href\>" end="</a>"me=e-4 contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,javaScript,@htmlPreproc

具有以下内容:

syn region htmlLink start="<a\>\_[^>]*\<href\>" end="</a>"me=e-4 keepend contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLinkText,javaScript,@htmlPreproc
syn match htmlLinkText contained contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLinkText,javaScript,@htmlPreproc "^\s*\zs.\{-}\ze\s*$"
syn match htmlLinkText contained contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLinkText,javaScript,@htmlPreproc "\S.\{-}\ze\s*$"

再往下改

HtmlHiLink htmlLink                    Underlined

HtmlHiLink htmlLinkText                Underlined

瞧!基本上,这引入了另一个包含的语法组 htmlLinkText,它不匹配前导和尾随空格,而是对其应用突出显示.

Voila! Basically, this introduces another contained syntax group htmlLinkText, which does not match leading and trailing whitespace, and applies the highlighting to that instead.

这篇关于VIM:不要在 HTML 链接中给前导空格加下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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