I am writing a plugin that highlights buffer settings violations.

I use matchadd() function. In addition I need to add patterns that are force ignored. In order to achieve that I use priorities in matchadd().

I use the following highlight group to highlight trailing spaces:

highligh FileStyleTrailngSpacesError ctermbg=Cyan guibg=Cyan

Matching trailing spaces code:

matchadd('FileStyleTrailngSpacesError', '\s\+$', 1)

Force highlight disabling supposed to be (e.g. pattern >\s\+$):

matchadd('Normal', '>\s\+$', 1)

The problem is that this line of code does not disable highlight, but it "works" with other highlight groups e.g. Todo

I also tried to use the following groups:

" Has the same result as 'Normal'
highligh FileStyleIgnorePattern cterm=NONE guibg=NONE

" E420: BG color unknown
highligh FileStyleIgnorePattern ctermbg=bg guibg=bg

UPDATE: OS - Ubuntu 14.04

  • Beware that there's a (small but non-zero) runtime price to each matchadd(). Perhaps a better approach might be to keep a list of IDs and delete the relevant ones rather than make them do nothing.
    – lcd047
    Apr 25 '15 at 4:47
  • @lcd047 I would like to do it this way, but the issue is that pattern, that should be ignored actually have a subpattern that should be highlighted in all other places except matching ignored one (e.g. \s\+$ and >\s\+\$ that should be ignored).
    – Alex
    Apr 25 '15 at 5:44

With guibg=NONE, you actually say "this has no background color", i.e. it is transparent. The bg value is the right approach, but that only works for guibg; for ctermbg, you indeed get the E420 error (from the :help E420: This only works after setting the colors for the Normal group and for the MS-DOS console.) . So, you need to specify the actual background color for color terminals:

highlight FileStyleIgnorePattern ctermbg=White guibg=bg

You could use synIDattr() to query the color terminal background color, but I guess that will only work if a color has been set explicitly, too.

  • Well, you a right about synIDattr(). I tried the following example: :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "bg"). It returns nothing on regular text.
    – Alex
    Apr 24 '15 at 19:26

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .