5

Problem

Anytime I switch to a colorscheme the background turns this ugly gray that gives everything a washed out look. Why does this happen, and how can I prevent it?

Example screenshot—

Dracula scheme

More details

This does not appear to happen when using agude/vim-eldar.

The :hi reports are below for vim-eldar—

:verbose hi Normal Normal xxx guifg=White guibg=Black Last set from ~/.local/share/nvim/plugged/vim-eldar/colors/eldar.vim 

and Dracula—

:verbose hi Normal Normal xxx ctermfg=255 ctermbg=236 guifg=#F8F8F2 guibg=#282A36 Last set from ~/.local/share/nvim/plugged/vim/colors/Dracula.vim 

Attempts

I've tried the following two things but no luck:

  1. make sure terminal color is set to xterm-256 color
  2. :set background=dark

My iTerm2 color preset is dark background

iTerm2 prefs

10
  • That looks like Dracula in the screenshot. Is it only happening then, or with other colorschemes as well? What is the background color of your terminal emulator ? Commented May 2, 2018 at 2:55
  • Other schemes as well Commented May 2, 2018 at 3:13
  • That looks like macOS terminal, am i correct? Ive not had this problem recently. Have you tried debugging your vimrc ? Commented May 2, 2018 at 8:00
  • 1
    What is the output of :verbose hi Normal before and after the switch? Commented May 2, 2018 at 8:01
  • Another possibly important clue: I found a schema where this is not taking effect. ` Plug 'agude/vim-eldar'` Specifically looked for a high contrast theme to test this. Commented May 2, 2018 at 16:03

2 Answers 2

10

A quick rundown on colorschemes

See :help :colorscheme. Essentially it sources a file containing :highlight commands.

What are highlight commands?

Statements of the form

:hi[ghlight] [default] {group-name} {key}={arg} .. 

that highlight sections of code (when syntax highlighting is enabled with syntax enable) and sections of the UI.

They can set special attributes like italics, colors, and even the foreground and background.

What is this background stuff ?

More than likely, it comes from a colorscheme using the Normal highlighting group (:help :hi-normal-cterm).

Essentially, as mentioned in the chat conversation, some colorschemes do something like :hi Normal ctermbg=... to change the color of the background of the terminal inside vim. This was happening for Dracula (and, as you noticed, it's not pretty. More on that in a second), and Molokai as well.

How do I fix it?

I'm going to address this on a case-by-case basis, then give some broader options.

Dracula

It came up in the chat that the OP was using Dracula. As I mentioned here, during a theme overhaul some issues were raised about the theme background.

It was using a 256-color approximation of the right color when it couldn't use truecolor (like a GUI hexcode). We added in a way to disable this, restoring the terminal background color.

Put this

let g:dracula_colorterm = 1 

before colorscheme dracula to use your own terminal background.

Molokai

The OP also wanted to adjust molokai. After discussing a bit, it was decided that molokai too looked good with no colored background. The solution is to use an autocommand to modify the colorscheme, like so:

au ColorScheme molokai hi Normal ctermbg=None 

(As always, I suggest wrapping autocommands in an augroup—see :help augroup).

General Case

The next piece of discussion was, "Can this be done for every colorscheme?"

The answer is, yes. Furthermore, you can customize any colorscheme, with any highlighting group, using this technique.

For example, to disable background highlighting on all colorschemes, use

au ColorScheme * hi Normal ctermbg=None 

Conclusion

Colorschemes are hard. But like everything else, they are customizable. Sometimes it helps to see if they have documentation; other times, check the GitHub repos and consider filing an issue. Further recourse includes customizing the scheme using autocommands.

At the end of the day, the colors we stare at while we code matter! Don't let them hurt your eyes.

0
3

This happened to me, and it was because I configured my colorscheme colors after I actually set the colorscheme. Moving my colorscheme command to a line after the actual color configuration solved my problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.