I like the ability to show trailing whitespaces, so I have this setting.

set list listchars=tab:\ \ ,trail:·

I never use tabs (although I don't think tabs are bad, it's just a convention), but sometimes I'm reading someone else code and they use tabs. I don't want to see tabs as some special characters in that cases.

But with the settings above vim would show tabs with different background colour. I don't want this. Can it just show trailing whitespaces and leave everything else alone?

  • 3
    AFAIK, 'listchars' isn't supposed to change background. You can for sure try to drop tab:\ \ part, but I wouldn't expect it to change anything (that's the default). Highlighting of tabulation might come from a different source. You can run :for id in synstack(line('.'), col('.')) | echo synIDattr(id, 'name') | endfor with cursor on a tab to see if there is any extra highlight group defined.
    – xaizek
    Commented Dec 4, 2016 at 17:14

1 Answer 1


You can omit tab from listchars, but that will cause vim to fall back on the default (showing tabs as ^I). So using tab:\ \ as you have is a reasonable way to keep them "invisible" when list is set.

The characters shown with list are highlighted with the SpecialKey or NonText groups, depending. Tabs, in particular, use SpecialKey, so it sounds like your color scheme has a background color for that particular group (see: :help listchars for more).

Unfortunately SpecialKey is used for trail as well, so whatever changes you make there for tab will apply to trail as well. If you go this route, you will only be able to change the foreground color of SpecialKey, really, without visibly impacting the tabs.

One alternative might be to avoid using list at all; in your .vimrc:

syntax match TrailingSpace /\s\+$/
hi TrailingSpace guibg=red

for example, will highlight trailing whitespace with a red background independent of whatever you have going on with list.

  • Thanks for an idea about syntax match. Can I also display some character instead of space that way? Probably not... Commented Dec 7, 2016 at 22:30
  • You might be able to abuse concealment (:help syn-conceal) but I don't think that will end up working well.
    – user72
    Commented Dec 7, 2016 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.