为什么Vim在制表符的位置上画下划线,如何避免这种情况发生?

16

我的vim显示制表符时没有特定的规律会出现下划线(见下图)。

有时它也会发生在文本上:我键入文本时会出现下划线。

可能的原因是什么?

enter image description here

3个回答

26

这可能是因为您正在编辑一个html文件,而下划线附近的文本位于<a>标签内。

要禁用此功能,您可以在~/.vimrc中添加 let html_no_rendering=1。但是,这个设置也会禁用html文件的加粗和斜体样式。

如果您只想禁用下划线,请参见:help html.vim。在那里,它会给出有关重新定义不带underline的高亮组的说明。


9

这种方法(从其他答案中拼凑)将仅在链接的文本部分下划线,并且不修改完整的html.vim语法文件。

  1. Create the file ~/.vim/after/syntax/html.vim
  2. Paste the following into that file:

    " disable the current htmlLink syntax
    highlight link htmlLink text
    
    " enable a new htmlLink syntax
    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*$"
    
    " enable the new syntax
    hi def link htmlLinkText                Underlined
    

5
这个答案完美地解决了问题,而不会影响其他功能,比被采纳的答案要好得多。 - Christopher Camps

2

这可能是以下两种情况之一:

  • 您设置了'list'(尝试:set list?,如果显示list,请尝试:set nolist
  • 您有一些语法高亮配置,将制表符突出显示为下划线。添加以下映射,然后将光标放在制表符上并按<F3>。如果显示一个突出显示组,请键入hi GROUPNAME以确认突出显示(用尖括号括起来的最后一个命名组替换GROUPNAME)。然后调整您的颜色方案以去除下划线。

映射以识别突出显示组:

map <F3> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#") . " BG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"bg#")<CR>

是的,我在 .vimrc 中有 :set list,只是为了发现那些使用制表符的人,尽管我们都同意使用空格 :D - lyuba
@lyuba :ret/:retab 将把文件中的所有制表符转换为空格。此外,它应该很容易编写脚本来将所有制表符替换为空格。如果你这样做了,他们会讨厌你的。如果同事们只使用一个能够处理空格的像样编辑器就好了... ;) - sjas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接