2

When defining a :sign you can use the linehl argument to assign a highlight group for the whole line the sign is placed in.

This highlights the whole line until the end, but how I do to highlight only the text of that line?

Edit: The idea is to use Syntastic to show the errors and warnings, but I can't redefine the SyntasticStyleError sign to do what I want. It highlights all the line instead of only the text of that line.

lcd047
  • 5,731
  • 2
  • 28
  • 38
nvaras
  • 21
  • 2
  • Syntastic can already highlight errors, what more do you want? – romainl Dec 11 '16 at 20:43
  • Syntastic highlights errors and warnings by default, if (1) the checkers involved provide enough information about column numbers, and (2) code has been written to use said information. This has nothing to do with signs. You can also redefine highlighting groups `SyntasticErrorLine` and `SyntasticWarningLine` to highlight entire lines. This is, actually, related to signs, and overrides normal highlighting. You can't have both working at the same time. – lcd047 Dec 12 '16 at 04:42

1 Answers1

1

It is not possible as far as I know. Look at the :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.

It does not offer you a straight-forward way to distinguish between the text background colour and the background colour of the line - in fact, you can only set the linehl parameter.


Maybe there is a hacky way to do what you want. I've stumbled upon this link you might find useful: https://sunaku.github.io/vim-256color-bce.html

Another interesting idea is explained on vim.wikia.com (link) in the Highlighting that stays after cursor moves section. It suggests using the following command:

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

This way you might mix it with the information you get from :sign place and replace signs with your custom highlighting method I posted above. It requires some scripting though.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79