Skip to content

Protect against color schemes that don't support changing the background #235

@micampe

Description

@micampe

Some color schemes don't support toggling light/dark background and trying to do it results in a mangled color scheme.

I fixed this by overriding the yob map, but I was wondering if there is interest to merge this here.

This is my function (I'm not good at vimscript so let me know any feedback):

function! s:ToggleBackground() abort
  let oldcolors = g:colors_name

  if &background == 'light'
    set background=dark
  else
    set background=light
  endif

  if !exists("g:colors_name") || oldcolors != g:colors_name
    execute 'colorscheme ' . oldcolors
    redraw | echo 'Color scheme ' . oldcolors . ' does not support changing the background'
  endif
endfunction

if this is interesting for the project I can create a pull request (or just take the function from here, I don't mind).

To integrate properly it would also have to support the enable/disable commands too. I don't use those so I didn't do it here but I can add it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions