$ echo $TERM
xterm-16color
$ vim
:set t_Co?
t_Co=256
I first suspected that something is wrong with my vimrc, but starting without
a vimrc behaves the same:
$ vim -Nu NONE
:set t_Co?
t_Co=256
What's really wierd is, that if I start Vim without 'nocompatible' then 't_Co'
is set to the correct value:
$ vim -u NONE
:set t_Co?
t_Co=16
This was definitely *not* happening with older versions of Vim. Now, is this
a bug or somehow intended? Can anybody reproduce this?
Thanks,
Dustin
Yes, the xterm I'm using supports 256 colors. I actually switched my
operating system recently, so thats probably the reason I didn't experienced
this before (can't remember how many colors xterm supported there).
I set TERM to 'xterm-16color' because I want all programs (and especially Vim)
to use only 16 colors.
Anyway, it seems like I have to hardcode 't_Co' in my vimrc which is quite ugly.
Or can I somehow force Vim to use the appropriate terminfo entry instead?
Hey,
first of all, thanks for your detailed and very helpful post :)
On Monday, November 4, 2013 2:14:24 AM UTC+1, Tony Mechelynck wrote:
> The colours Vim uses depend on its colorscheme. If you don't set any,
> you get the default colours, which use only the 16 color codes
> compatible with any color depth (or maybe even 16 foreground and 8
> background colours; there are still some consoles in use today which
> don't go higher than that).
Hmm, are you sure about this? At least on my system the default colorscheme
uses more than 16 colors if t_Co is set high enough:
:colorscheme
default
:set t_Co?
t_Co=256
:highlight
SpecialKey xxx term=bold ctermfg=81 guifg=Cyan
Directory xxx term=bold ctermfg=159 guifg=Cyan
Visual xxx term=reverse ctermbg=242 guibg=DarkGrey
(only a few examples)
The funny thing is, that if TERM is 'xterm-16color' then all of these
"higher" color definitions are actually shown just as normal text (without
color), which for example breaks visual mode.
If on the other side TERM is just 'xterm' Vim can display 256 colors.
Really weird.
> To display more than 16 colours on a console in Vim, you need a
> colorscheme which defines highlights with ctermfg= and/or ctermbg=
> values higher than 15, and those who do may assume that the user knows
> hat he's doing, and not check that t_Co is high enough (they could test
> if they wanted to).
Like stated above, the default colorscheme also does this.
> So I think your fears are unfounded. If you don't set any colorscheme,
> or if you choose one that supports 16-color consoles, Vim won't use
> more.
Well, for me the default colorscheme is totally broken if I set TERM to
'xterm-16color', so I wouldn't say that my "fears are unfounded" :)
> However, even so, you can force Vim to ignore the t_Co value returned by
> the xterm, as follows (untested):
>
> :autocmd TermResponse * set t_Co=16
>
> or even
>
> :au TermResponse * if &term ~= '^xterm-\=16'
> \ | set t_Co=16 | endif
Thanks, I will try that. This seems to be the best solution for now.
Regards,
Dustin
I now actually tried your suggestion and it didn't work. I think the
TermResponse event gets triggered before Vim interprets the response
from xterm, so the change of t_Co is overwritten later by Vim.
I also tried countless other things in my vimrc to force t_Co to 16, but
nothing worked.
Finally, I found out that xterm has an option called 'allowTcapOps'.
After setting it to false Vim is no longer able to query xterm, and t_Co
is set to the correct value now.