2012-04-14 16 views
8

可能重複:
Why is vim drawing underlines on the place of tabs and how to avoid this?VIM:不要在HTML強調前導空格鏈接

當VIM 7.0在CentOS 5.x的縮進PHP代碼,HTML鏈接顯示下劃線。這是非常方便的,但在某些地方我已經在HTML縮進PHP代碼,整個縮進強調:

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

有沒有辦法告訴語法高亮忽略HTML鏈接線前導空格?

回答

10

我設法通過修改$VIMRUNTIME/syntax/html.vim實現這一目標。一份文件,以~/.vim/syntax/html.vim.vim被命名爲Windows上vimfiles),並用以下替換原來的語法定義

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

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

再往下,改變

HtmlHiLink htmlLink     Underlined 

HtmlHiLink htmlLinkText    Underlined 

瞧!基本上,這引入了另一個包含的語法組htmlLinkText,它不匹配前導和尾隨空白,並將突出顯示應用於該語法。

+0

謝謝。出於某種原因,現在沒有任何鏈接被突出顯示,但H2和P標籤被突出顯示!我仔細地審視了這些變化,我似乎無法找到它們。編輯內容在150行和253行左右[如果你想看看](http://pastebin.com/kDPAH7g7)。謝謝Ingo! – dotancohen 2012-04-18 03:43:03

+0

你的編輯很好,你的文件適合我。你還有其他的定義嗎,也許在〜/ .vim/after/syntax /文件中? – 2012-04-18 06:46:01

+0

不,沒有其他文件或定義,我甚至嘗試使用空白的〜/ .vimrc(所以沒有其他系統範圍的.vimrc會妨礙)。這是在一個Cygwin終端進入一個CentOS 5.x盒VIM 7.0中。 – dotancohen 2012-04-18 16:37:33

7

你可以這樣做:

:hi link htmlLink NONE 
+0

謝謝,但是禁用了所有鏈接高亮,我碰巧發現它很有用。我正在尋找禁用突出顯示只在行領先的空白。 – dotancohen 2012-04-14 16:12:20