vim / colorschemes

colorschemes for Vim
276 stars 23 forks source link

No Visual highlight with new themes on tty (t_Co=8) #172

Closed sandwm closed 2 years ago

sandwm commented 2 years ago

When using vim on a Linux tty and pressing V (or its variants) I noticed there is no visual indication of which parts of the text are selected. My colorscheme is elflord, but other themes are affected too (see first comment below). The issue started about a week ago, when Arch Linux shipped the new vim version (8.2.4981) which replaced the legacy themes with the new ones.

Here is the output of source /usr/share/vim/vim82/syntax/hitest.vim with legacy elflord.vim: old

And here it is with the current elflord.vim: new

You see that Visual as well as some other highlighting groups which previously had some highlighting applied are now missing it.

For better reproducibility and to make sure it's not related to my personal setup, I reproduced the issue with a fresh Arch Linux virtual machine: Get the iso image from https://archlinux.org/download/, start the VM from the iso and run:

pacman -Sy vim vim-runtime  # update vim packages
vim /etc/vimrc # add 'colorscheme elflord'
mkdir -p ~/.vim/colors/
cd ~/.vim/colors/
curl -o elflord.vim https://raw.githubusercontent.com/vim/colorschemes/master/legacy_colors/elflord.vim
# first image above produced by these two commands
vim -c 'source /usr/share/vim/vim82/syntax/hitest.vim'
vim -u NONE -c 'colorscheme elflord' -c 'source /usr/share/vim/vim82/syntax/hitest.vim'
rm elflord.vim
# second image above produced by these two commands
vim -c 'source /usr/share/vim/vim82/syntax/hitest.vim'
vim -u NONE -c 'colorscheme elflord' -c 'source /usr/share/vim/vim82/syntax/hitest.vim'

There was no relevant difference in the output between including -u NONE -c 'colorscheme elflord' or just using the /etc/vimrc (apart from having a minimal status line or not).

The first command (pacman) updates the vim packages so they contain the new themes. This won't be necessary once the 2022.06.01 image is released, which will already contain a newer vim version. If you want to see the very minimal /etc/vimrc and archlinux.vim, which is sourced by the former, you can find them here: https://github.com/archlinux/svntogit-packages/tree/packages/vim/trunk

Of course apart from the pacman command all other steps should also work on any other distro and a recent vim.

sandwm commented 2 years ago

Additional info:

Note that I didn't do a full comparison for the non-elflord themes of legacy vs. new version, but just ran this in /usr/share/vim/vim82/colors/:

for file in *.vim; do vim -u NONE -c "colorscheme ${file%.vim}" -c "source /usr/share/vim/vim82/syntax/hitest.vim"; done
habamax commented 2 years ago

Thanks for the report, @sandwm

We aimed for GUI > 256 > 16 > 0 and for some reason missed 8.

I believe, this has to be fixed

brammool commented 2 years ago

Can you set it to use 16 colors? What do you mean with "Linux tty", what is 'term' set to?

romainl commented 2 years ago

Can you set it to use 16 colors?

If memory serves, doing set t_Co=16 in Vim does the job.

What do you mean with "Linux tty", what is 'term' set to?

Another name for what OP is talking about is "virtual console" or "virtual terminal" or "VT". You can get there from your desktop environment with Ctrl+Alt+F7, Ctrl+Alt+F8, etc. $TERM is usually linux, there.

sandwm commented 2 years ago

Yes, like @romainl said, I meant a virtual console like tty1, tty2, ... accessible via Ctrl+Alt+F1, Ctrl+Alt+F2, ... $TERM is linux. :set t_Co=16 works.

brammool commented 2 years ago

Well, you can set it to 16 colors, but it looks like it really only supports 8. With the default colors Visual uses background 8, which is just black and not grey. With 8 colors it uses reverse, which does work. Thus 16 colors is wrong.

Looks like the color schemes should support 8 colors, there is no workaround.

romainl commented 2 years ago

In the virtual console, we can…

and we can't…

which means that…

Anything else I missed?

habamax commented 2 years ago

have a white bg.

What would we do with delek, peachpuff, morning, shine, zellner?

romainl commented 2 years ago

What would we do with delek, peachpuff, morning, shine, zellner?

Either accept to have it light grey instead of white or (╯°□°)╯︵ ┻━┻.

habamax commented 2 years ago

Either accept to have it light grey

Ah, light grey is available, this might work

habamax commented 2 years ago

To track status:

habamax commented 2 years ago

@romainl pls check light bg colorschemes

PS, I have to do other things so the last one is on you :)

romainl commented 2 years ago

@habamax thank you for all that great work.

sandwm commented 2 years ago

Thanks to both of you! That looks much better in several places. :)

Unfortunately there's also a regression: SpellBad, SpellCap, SpellRare, SpellLocal lost all highlighting, compared to what's in vim 8.2.5046. (Actually, for SpellLocal that's not really a regression, since previously it had fg color = bg color.) I don't really mind, since I don't do spell checking in a tty, but wanted to note it nonetheless. Checked with elflord and pablo.

habamax commented 2 years ago

@sandwm it actually shouldn't. Any exact colorscheme or all of them?

habamax commented 2 years ago

This is shine: image

desert: image

evening image

etc

habamax commented 2 years ago

Ah, elflord and pablo:

elflord: image

pablo: image

habamax commented 2 years ago

Aha, if it is in tty (or whatever it is called in Ctrl+Alt+F3) it is indeed have no highlighting.

Not sure how to tackle it...

habamax commented 2 years ago

I can't make screenshots there :)

But having those 3 lines I have nothing only for "Normal" (first line), everything else is highlighted.

habamax commented 2 years ago

underline makes it all the same color and for elflord it is the same as normal text.

We could remove it for 8c completely... @romainl what do you think?

sandwm commented 2 years ago

Yes, my comment was about vim in a tty with t_Co=8. I made screenshots from a virtual machine (vim with source /usr/..../syntax/hitest.vim).

Before: elflord_packaged_crop

After: elflord_upstream_crop

I think underline isn't supported there anyhow, so that could be removed. I'm gonna check.

habamax commented 2 years ago

@sandwm could you pls check if

Make it properly highlighted?

habamax commented 2 years ago

I think underline isn't supported there anyhow, so that could be removed. I'm gonna check.

We can't probably detect if it is tty or xterm with 8c support, so if we are to remove it -> it would be for all terminals.

habamax commented 2 years ago

And we can make it reverse though...

sandwm commented 2 years ago

@sandwm could you pls check if

* `:hi SpellRare cterm=NONE`

* `:hi SpellLocal cterm=NONE`

* `:hi SpellBad cterm=NONE`

* `:hi SpellCap cterm=NONE`

Make it properly highlighted?

Yes, that works.

We can't probably detect if it is tty or xterm with 8c support, so if we are to remove it -> it would be for all terminals.

Shouldn't xterm have more colors? For me :set t_Co? in an actual xterm gives 256 (and underlines work).

sandwm commented 2 years ago

I think underline isn't supported there anyhow, so that could be removed. I'm gonna check.

Yes, no underline in tty (on a color display – so any display relevant here).

cterm=reverse works, although I think personally I would prefer just changing the color. That's more readable and a word which is supposedly spelled wrong (even if it's just a term the dictionary doesn't know) doesn't need the highlighting of e.g. an ErrorMsg.

sandwm commented 2 years ago

We can't probably detect if it is tty or xterm with 8c support, so if we are to remove it -> it would be for all terminals.

Shouldn't xterm have more colors? For me :set t_Co? in an actual xterm gives 256 (and underlines work).

Ah, looks like some older xterms indeed only supported 8 colors: https://stackoverflow.com/questions/10003136/what-is-the-difference-between-xterm-color-xterm-256color/10039347#10039347 I don't know whether they supported underline.

Side note: Even with export TERM=xterm-color (for 8 color xterm) which also leads to tput colors reporting 8, in vim I get t_Co=256 (which is indeed what this xterm supports).

habamax commented 2 years ago

I will have a look into this once everything is merged in

habamax commented 2 years ago

I couldn't find the way in templates how to clear the default reverse, e.g. if I remove underline then spell highllghts are reverse by default (at 8c).

So I made them reverse explicitly.

habamax commented 2 years ago

All of the colorschemes have 8c support now.

@romainl please check the latest darkblue and it might be a good idea to create PR against main vim repo to include them before vim9 is out

habamax commented 2 years ago

https://github.com/vim/vim/pull/10563