Updated to 3.5.0; now ignoring my colors in vim

27 views
Skip to first unread message

Paul J. Lucas

unread,
May 23, 2024, 12:38:05 PMMay 23
to iterm2-...@googlegroups.com
Hi -

I just updated to iTerm2 3.5.0 and now it ignores all my colors for syntax highlighting while in vim (shipped with macOS 13.6.6) and uses default colors (presumably). I haven’t changed any settings. When I uses Apple’s Terminal, everything still looks fine, so the problem must be with iTerm2.

The relevant section of .vimrc file is below. I’ve also attached a side-by-side screenshot: the window on top it iTerm2 in the wrong colors; the window on the bottom is Terminal in the correct colors.

However, colors in zsh for files based on extensions are still correct.

- Paul

" Turn on syntax highlighting.
syn enable

" Turn off pathentheses highlighting.
let loaded_matchparen=1

" Turn off search highlighting when switching buffers.
au BufNewFile,BufReadPost * noh

" Generic programming
hi Boolean cterm=NONE ctermfg=NONE
hi Character cterm=NONE ctermfg=NONE
hi Comment cterm=NONE ctermfg=DarkGreen
hi Conditional cterm=NONE ctermfg=NONE
hi Delimiter cterm=NONE ctermfg=NONE
hi Exception cterm=NONE ctermfg=NONE
hi Float cterm=NONE ctermfg=NONE
hi Function cterm=NONE ctermfg=NONE
hi Identifier cterm=NONE ctermfg=NONE
hi Keyword cterm=NONE ctermfg=NONE
hi Label cterm=NONE ctermfg=NONE
hi Number cterm=NONE ctermfg=NONE
hi Operator cterm=NONE ctermfg=NONE
hi Repeat cterm=NONE ctermfg=NONE
hi Search cterm=NONE ctermfg=White ctermbg=DarkRed
hi Special cterm=NONE ctermfg=NONE
hi SpecialChar cterm=NONE ctermfg=NONE
hi Statement cterm=NONE ctermfg=NONE
hi String cterm=NONE ctermfg=NONE
hi Tag cterm=NONE ctermfg=NONE
hi Type cterm=NONE ctermfg=NONE

" C/C++
hi cCppOut cterm=NONE ctermfg=DarkBlue
hi cppAccess cterm=NONE ctermfg=DarkRed
hi cSpecial cterm=NONE ctermfg=NONE
hi PreProc cterm=NONE ctermfg=DarkMagenta
hi StorageClass cterm=NONE ctermfg=NONE
hi Structure cterm=NONE ctermfg=NONE
hi Typedef cterm=NONE ctermfg=NONE

hi! link cConstant NONE
hi! link cIncluded PreProc
hi! link Define PreProc
hi! link Include PreProc
hi! link Macro PreProc

hi DiffAdd cterm=NONE ctermfg=NONE ctermbg=DarkGreen
hi DiffChange cterm=NONE ctermfg=NONE ctermbg=DarkRed
hi DiffDelete cterm=NONE ctermfg=Black ctermbg=NONE
hi DiffText cterm=NONE ctermfg=NONE ctermbg=DarkRed
hi LineNr cterm=NONE ctermfg=Yellow ctermbg=NONE
hi ModeMsg cterm=NONE ctermfg=Yellow ctermbg=NONE
hi NonText cterm=NONE ctermfg=DarkBlue ctermbg=NONE
hi Pmenu cterm=NONE ctermfg=White ctermbg=DarkBlue
hi PmenuSel cterm=NONE ctermfg=Black ctermbg=Yellow
hi StatusLine cterm=NONE ctermfg=White ctermbg=DarkBlue
hi StatusLineNC cterm=NONE ctermfg=Black ctermbg=White
hi Visual cterm=NONE ctermfg=Black ctermbg=Yellow
hi WildMenu cterm=NONE ctermfg=Black ctermbg=Yellow

" HTML syntax coloring is all messed up, so turn it off.
au! BufNewFile,BufReadPost *.html

iTerm-Terminal.jpg

Paul J. Lucas

unread,
May 23, 2024, 7:23:01 PMMay 23
to iterm2-...@googlegroups.com
After more poking around, I discovered I had this in my .vimrc file:

se t_Co=8

I changed it to:

se t_Co=256

and the colors reverted to being correct (matching vim in Terminal).

But why should that matter? Why should 8 make the colors appear _so_ different? This all worked fine before iTerm 3.5.0.

- Paul
> <iTerm-Terminal.jpg>
>

John Simpson

unread,
May 24, 2024, 8:35:56 AMMay 24
to iterm2-...@googlegroups.com
On 2024-05-23, at 13:25, Paul J. Lucas <pa...@lucasmail.org> wrote:
>
> After more poking around, I discovered I had this in my .vimrc file:
>
> se t_Co=8
>
> I changed it to:
>
> se t_Co=256
>
> and the colors reverted to being correct (matching vim in Terminal).
>
> But why should that matter? Why should 8 make the colors appear _so_ different? This all worked fine before iTerm 3.5.0.

I'm not sure what changed in iTerm2 (I don't recall anything changing with regards to colour when I upgraded) and I *rarely* use vi/vim (I use "nano" or BBEdit), but I have spent some time playing with ANSI colours, which are what vi/vim/nano/etc. use to tell the terminal what colour to draw the characters it sends.

With that said, here are some things you can check on, if you're inclined to continue investigating what happened.

The standard ANSI colour set has 16 colours, not 8. If you were setting it to 8 before, maybe vi/vim was getting confused? Did you upgrade vi/vim anywhere along the way, and maybe that changed how `t_co=8` was being processed?

Something else that comes to mind is, the first 16 "slots" in the 256-colour palette normally contain the same 16 colour values as the ANSI colours. If you customize the ANSI colours in "Settings -> Profiles -> Colors" for the profile you're using, I don't know if that *also* affects the 256-colour palette. iTerm2 isn't open-source so I can't look at the code for myself, if only there were somebody around who knows how this works, or who CAN check the source code ... ;)

Also ... looking at https://vimhelp.org/term.txt.html , it looks like they recommend setting `t_Co` as early as possible in your `.vimrc` file, especially before setting any other options which have anything to do with colours (custom colours, syntax highlighting, etc.) If you're setting `t_Co` at the end of the file, it may be that it's resetting some things back to a default state and un-doing any customizations which came before it in the file. Again, I don't use vi/vim enough to have ever messed around with any kind of custom configuration (especially since I found out about editorconfig) so I could be totally wrong about this - I'm just pointing out things you can check in your own investigation.

If it helps ... years ago I wrote a Perl script called 'colors', as a quick way to see what the various ANSI colour combinations looked like. Since then I added support for the 256-colour palette, then added a quick demo of what 24-bit colour looks like. This is how I know that iTerm2 supports 24-bit colour but not double-high/double-width or blinking text, and that Terminal.app supports double-high/double-width and blinking text but not 24-bit colour (or at least, not very well.)

I just uploaded the script and some screenshots to Keybase, see https://jms1.pub/colors/ if you're curious.

Good luck, and if you do uncover anything more, be sure to let us know.

--
John Simpson - KG4ZOW
https://jms1.net/

Paul Lucas

unread,
May 24, 2024, 4:34:25 PMMay 24
to iterm2-discuss
The original ANSI color specification had only 8 colors, hence my t_Co=8 so my settings should work on any least-common-denominator terminal. (I've been using vim since near its beginning and vi since the late 1980s and I've been carrying my vi/vim config along for decades.) The value of 8 wasn't broke (until iTerm 3.5.0), so I didn't fix it. No, I didn't upgrade anything except iTerm2.

I'm setting t_Co in my .vimrc file before any highlighting option.

— Paul

Adrian Bool

unread,
May 25, 2024, 4:15:43 AMMay 25
to iterm2-discuss


On 24 May 2024, at 13:35, John Simpson <kg4...@gmail.com> wrote:

Something else that comes to mind is, the first 16 "slots" in the 256-colour palette normally contain the same 16 colour values as the ANSI colours. If you customize the ANSI colours in "Settings -> Profiles -> Colors" for the profile you're using, I don't know if that *also* affects the 256-colour palette. iTerm2 isn't open-source so I can't look at the code for myself, if only there were somebody around who knows how this works, or who CAN check the source code ... ;)

FYI: iTerm2 is open source, George's git repository is available at: https://github.com/gnachman/iTerm2

Cheers,

aid

George Nachman

unread,
May 28, 2024, 1:58:54 AMMay 28
to iterm2-...@googlegroups.com
I haven’t had time to look at this yet but it most likely has to do with the version of xterm that iTerm2 pretends to be. Tweaking this setting may yield better results, but it’s probably not the best fix:


I’ll investigate more when I get a bit of time.

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/D4F913FD-058C-420F-BF8B-30C90C0F736A%40lucasmail.org.




--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/D4F913FD-058C-420F-BF8B-30C90C0F736A%40lucasmail.org.
Reply all
Reply to author
Forward
0 new messages