在Vim中设置一个标记以仅突出显示文本而不是整行

时间:2016-12-11 15:33:54

标签: vim highlight syntastic

定义:符号时,您可以使用linehl参数为放置符号的整行指定高亮组。

这会突出显示整行直到结束,但我该如何突出显示该行的文字?

编辑:想法是使用Syntastic来显示错误和警告,但我无法重新定义SyntasticStyleError符号来执行我想要的操作。它突出显示所有行,而不仅仅是该行的文本。

1 个答案:

答案 0 :(得分:1)

据我所知,这是不可能的。查看:h sign-define

:sign define {name} {argument}...
        Define a new sign or set attributes for an existing sign.
        The {name} can either be a number (all digits) or a name
        starting with a non-digit.  Leading digits are ignored, thus
        "0012", "012" and "12" are considered the same name.
        About 120 different signs can be defined.

        Accepted arguments:

    icon={bitmap}
        Define the file name where the bitmap can be found.  Should be
        a full path.  The bitmap should fit in the place of two
        characters.  This is not checked.  If the bitmap is too big it
        will cause redraw problems.  Only GTK 2 can scale the bitmap
        to fit the space available.
            toolkit     supports ~
            GTK 1       pixmap (.xpm)
            GTK 2       many
            Motif       pixmap (.xpm)
            Win32       .bmp, .ico, .cur
                    pixmap (.xpm) |+xpm_w32|

    linehl={group}
        Highlighting group used for the whole line the sign is placed
        in.  Most useful is defining a background color.

    text={text}                     *E239*
        Define the text that is displayed when there is no icon or the
        GUI is not being used.  Only printable characters are allowed
        and they must occupy one or two display cells.

    texthl={group}
        Highlighting group used for the text item.

它没有为您提供区分文本背景颜色和线条背景颜色的直接方法 - 事实上,您只能设置linehl参数。

也许有一种hacky方式来做你想要的。我偶然发现了您可能觉得有用的链接:https://sunaku.github.io/vim-256color-bce.html

另一个有趣的想法是在{em>突出显示光标移动部分后的vim.wikia.com (link)中解释。它建议使用以下命令:

:nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR>

通过这种方式,您可以将其与:sign place中提供的信息混合,并使用我在上面发布的自定义突出显示方法替换符号。它需要一些脚本。