Possible Duplicate:
Why is vim drawing underlines on the place of tabs and how to avoid this?
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>
Is there any way to tell the syntax highlighter to ignore line-leading whitespace in HTML links?
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
with the following:
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*$"
Further down, change
HtmlHiLink htmlLink Underlined
to
HtmlHiLink htmlLinkText Underlined
Voila! Basically, this introduces another contained syntax group htmlLinkText
, which does not match leading and trailing whitespace, and applies the highlighting to that instead.
You can do this:
:hi link htmlLink NONE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With