Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Don't underline leading whitespace in HTML links [duplicate]

Tags:

vim

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?

like image 887
dotancohen Avatar asked Apr 14 '12 03:04

dotancohen


2 Answers

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.

like image 187
Ingo Karkat Avatar answered Sep 28 '22 18:09

Ingo Karkat


You can do this:

:hi link htmlLink NONE
like image 44
kev Avatar answered Sep 28 '22 18:09

kev