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.
:verbose hi Normal
before and after the switch? – D. Ben Knoble♦ May 2 '18 at 8:01