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.