Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the contrast for Visual mode selection #36

Closed
EdwarDu opened this issue Sep 24, 2021 · 6 comments
Closed

Increase the contrast for Visual mode selection #36

EdwarDu opened this issue Sep 24, 2021 · 6 comments
Labels
enhancement New feature or request workaround The issue can be addressed using a workaround

Comments

@EdwarDu
Copy link

EdwarDu commented Sep 24, 2021

Thank you for the very nice color theme.

For me, the contrast in Vim for Visual mode selection is not very good.
I can manually change it as "call sonokai#highlight('Visual', s:palette.none, s:palette.black)" though.

As this is not a bug, I open this as a blank issue.
If further information is required, please let me know.

@rafgugi
Copy link

rafgugi commented Mar 30, 2023

have the same problem. I don't know how to match color but this gives better contrast.
Also, I change a little bit for the highlight color, because red and green just don't make sense imo

-- Patch color palette for sonokai
local configuration = vim.fn['sonokai#get_configuration']()
local palette = vim.fn['sonokai#get_palette'](configuration.style, configuration.colors_override)
vim.fn['sonokai#highlight']('Visual', palette.none, palette.grey_dim)
vim.fn['sonokai#highlight']('IncSearch', palette.bg0, palette.yellow)
vim.fn['sonokai#highlight']('Search', palette.none, palette.diff_yellow)

@antoineco
Copy link
Collaborator

antoineco commented Apr 22, 2023

To illustrate the changes that were suggested above regarding the visual selections (before/after):

image
image

And the search highlights (before/after):

image
image

I get the point, but it really seems to boil down to personal preferences. For instance, I prefer the current selection to the proposed one.

I do like the suggested search highlights though, but using a low contrast for search results also decreases accessibility, and might overlap with highlighted code and/or LSP diagnostics. Not to mention that every one will have their preference of blue, yellow, green, ...

It's normal for users to enjoy tweaking little things in their favourite color scheme, and for this I always recommend using an autocmd to apply those on a per-colorscheme basis:

-- Apply custom highlights on colorscheme change.
-- Must be declared before executing ':colorscheme'.
local grpid = vim.api.nvim_create_augroup('custom_highlights_sonokai', {})
vim.api.nvim_create_autocmd('ColorScheme', {
  group = grpid,
  pattern = 'sonokai',
  callback = function()
    local config = vim.fn['sonokai#get_configuration']()
    local palette = vim.fn['sonokai#get_palette'](config.style, config.colors_override)
    local set_hl = vim.fn['sonokai#highlight']

    set_hl('Visual', palette.none, palette.black)
    set_hl('IncSearch', palette.bg0, palette.yellow)
    set_hl('Search', palette.none, palette.diff_yellow)
  end
})

edit: this type of customizations is now documented.

@antoineco antoineco changed the title To increase the contrast for Visual mode selection in Vim Increase the contrast for Visual mode selection Apr 22, 2023
@antoineco antoineco added the enhancement New feature or request label Aug 3, 2023
@antoineco antoineco added the workaround The issue can be addressed using a workaround label Jun 5, 2024
@andreihh
Copy link
Contributor

I also struggle with the low contrast of visual selections. I don't mind the search highlights, but the visual selection is troublesome, particularly if it's on a single line. I would propose changing the Visual highlight from bg3 to bg4. The difference is subtle, but it's enough to make the selection stand out more without becoming too intrusive.

The color scheme is advertised as:

High contrast but within acceptable range.

We can tweak things to suit our preferences, but I think this is a case of usability rather than preference, and it would be nice if the defaults would work out of the box as advertised :)

Single line selection before (barely noticeable):
Image

Single line selection after (IMO much better):
Image

Multi-line selection before:
Image

Multi-line selection after:
Image

@antoineco
Copy link
Collaborator

antoineco commented Jan 27, 2025

@sainnhe the change of background for Visual from bg3 to bg4 doesn't seem to conflict with anything notable besides MatchParen and a non-default flavor of CurrentWord:

call sonokai#highlight('MatchParen', s:palette.none, s:palette.bg4)

sonokai/colors/sonokai.vim

Lines 378 to 379 in e1c1491

elseif s:configuration.current_word ==# 'high contrast background'
call sonokai#highlight('CurrentWord', s:palette.none, s:palette.bg4)

I personally don't have a strong opinion against that change. In fact, it would be more subtle than switching to black or grey_dim (what was suggested in the first two messages of this issue).

@sainnhe
Copy link
Owner

sainnhe commented Jan 28, 2025

@antoineco @andreihh bg4 indeed seems better. I've changed this in the latest commit.

@andreihh
Copy link
Contributor

Thank you so much for the quick fix, really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround The issue can be addressed using a workaround
Projects
None yet
Development

No branches or pull requests

5 participants