Showing some whitespace chars, but not all, in vim?

3

I'm using the set list and set listchars options in vim. I'd like to customize set listchars to display trailing spaces, etc., but not tabs. Is it possible to specify that I don't want a particular type of whitespace displayed?

I've tried this:

set listchars=tab:,trail:·,extends:>,precedes:<,nbsp:%

But I got a syntax error when loading my .vimrc.

Andrew Ferrier

Posted 2013-07-04T15:30:29.460

Reputation: 1 604

Answers

4

I just discovered that although this is technically not possible, one can cheat and enter special Unicode whitespace characters (not the regular space character) as the character to display for a tab. Although this still uses vim's hl-NonText highlighting color, it's certainly less obtrusive.

In other words, do this (or similar):

set listchars=tab:  ,trail:·,extends:>,precedes:<,nbsp:%

The two characters after tab: are not regular space characters - they are U+2002. You can enter them in vim itself with Ctrl-V u 2 0 0 2 (in insert mode).

So far, I haven't noticed any nasty side-effects.

Andrew Ferrier

Posted 2013-07-04T15:30:29.460

Reputation: 1 604

5Why not simply use spaces? set listchars+=tab:\ \ – Nikita Kouevda – 2013-07-05T00:07:04.730

1@NikitaKouevda, I didn't know you could escape spaces like that. That works too. If you state that as answer, I'll mark it correct. – Andrew Ferrier – 2013-07-07T23:17:37.383

4

That's not possible, unfortunately. You can only :set list on or off, and for those elements you don't define in 'listchars', the defaults will be used.

I would not recommend to always operate under :set list, as it has some side effects (e.g. affecting soft wrapping).

If you're just concerned about highlighting trailing whitespaces, there are plugins that do this through other means. Actually, I have written the ShowTrailingWhitespace plugin for that; the page has links to alternatives.

Ingo Karkat

Posted 2013-07-04T15:30:29.460

Reputation: 19 513