+3  A: 

The trail, tab and nbsp listchars use the SpecialKey highlight group, so you can use this:

highlight SpecialKey ctermfg=8

to make the $ symbol grey. If you have 256 colors enabled, you can use a different shade of grey, like 243, etc.

sykora
The code makes no change for the color of my trailing character. I am not sure why. --debugging-- I added a small code to my original post. I have tried to get your code work with it and without it unsuccessfully.
Masi
I tried it again, works perfectly. Are you sure you're using as many spaces as you have put in your post? eg. Space before , is illegal, etc. At least it's erroring out here.
sykora
+2  A: 

There are two highlighting groups: SpecialKey and NonText. The trailing characters you mention belong to the NonText one.

Try something like this (y/pasted):

set list
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
hi NonText ctermfg=7 guifg=gray

Does that work for you, or did I understand the question wrong (quite possible).

ldigas
I found that "The "NonText" highlighting will be used for "eol", "extends" and "precedes". "SpecialKey" for "nbsp", "tab" and "trail"."
Masi
@Masi - I don't understand what is it you want exactly. Do you wish to change the color of eol char, or do you wish to set "$" as a trailing character, and change its color ? In your picture in your question, the character in line 27 is not a trailing character, it is an eol char.
ldigas
But in that picture you also have trailing characters set to $, so that could be one source of errors.
ldigas
Try it like this. First, set "set list" and "set listchars=". Btw, you can always see your listchars with "set listchars?". Now we got it resetted. Now, set your listchars options to something, just make sure every char is different (see my example above), and then set "hi SpecialKey" and "hi NonText" options. That should work. If it starts acting weird, post the results. But it should work.
ldigas
@Idigas: You are completely correct. I confused trailing character with eol character. I want the eol character to be in gray. Thank you for pointing that out! -- I set "hi SpecialKey guifg=gray" unsuccessfully.
Masi
@Masi - ok, then you just set "hi NonText guifg=gray" and you're done. (or ctermfg, ... depends on what version of vim you're using, but you probably know that part). Cheers!
ldigas
@Idigas: It seems that something in my .vimrc affects the eol character, since the color of eol does not change at all, when I change colors. -- Please, see the following screenshot in iTerm and in Mac's default terminal: http://dl.getdropbox.com/u/175564/eolProblem.png
Masi
@Idigas: I commented out everything else in my .vimrc. The bug cannot be in it.
Masi
@Masi - sorry, took me a while. I was away. I admit, you got me confused a little. Do you perchance load another vimrc from somewhere else (after loading this one) ? What platform are you on anyway ?
ldigas
How much colors does your terminal support ?
ldigas
@Idigas: I use OS/X and my terminal supports 16 colors.
Masi
@Masi - I've been experimenting a little and I can't reproduce your behaviour. If you try to start vim with an empty vimrc (be careful you don't load some other vimrc in the background), does it show the same behaviour after modifying "set list", "listchars" and "hi NonText" options ? Unfortunatelly, I use WinXP and *nix, and don't have OS/X to exactly try it on that.
ldigas
Vim with an empty vimrc can be started (on my platform anyway) with an "-u" parameter.
ldigas
@Idigas: You made a crux move. :hi NonText ctermfg=7 works when set inside Vim. It seems that my Vim does not read the line at the startup.
Masi
@Idigas: I found the bug. I had the following command in my .vimrc: hi clear. -- Thank you for your answers!
Masi
+1  A: 

If you want the eol to be gray, specify the eol suboption of listchars instead of trail:

set list listchars=tab:>>,eol:$

trail shows the unnecessary whitespace characters at the end of the lines, not the end of lines themselves.

If you want to set the color of eol, you have to set the highlighting of the NonText group:

highlight NonText ctermfg=8 guifg=gray

If you specify both ctermfg and guifg, the highlighting will work both in the GUI and in a terminal.

I have to point out though some shortcomings:

  • The highlighting of the tilde characters after the end of the buffer are the same as the highlighting of the eol-signs. I think it is not possible to separate those; their highlightings are both determined by the highlighting of NonText. So if you set gray eols, you will be gray tildes.
  • On my terminal, ctermfg=8 makes red and not gray text.
hcs42