flicker if plugin sets 'background' during startup
Neovim version (nvim -v)
v0.7.2
Vim (not Nvim) behaves the same?
no, vim 9.0.0
Operating system/version
Arch Linux
Terminal name/version
wezterm nightly
$TERM environment variable
xterm-256color
Installation
Arch Linux community repo
How to reproduce the issue
- Have a terminal emulator with light colorscheme
- Source a plugin that sets
background=lightas soon as theplugin/pluginname.vimis sourced - Once nvim is started, the screen flickers briefly because neovim assumes
background=darkand renders the UI before the plugin is sourced.
If we set background=light in init.vim, then we set it early enough before nvim renders anything. But it's not possible to do that from a plugin (without calling the plugin from init.vim), because the plugin is sourced too late in the startup process: nvim already shows the UI before sourcing it, while normal vim does not (so the problem does not occur with normal vim).
See the attached video for a visual explanation:
- neovim is on the left: Flickers visibly
- vim is on the right: Does not flicker
https://user-images.githubusercontent.com/21310755/178955503-66796c13-79ac-4e4b-8399-fd17b177194b.mp4
Minimal example myplugin/plugin/myplugin.vim (myplugin needs to be in rtp):
" myplugin.vim
set background=light
Expected behavior
neovim renders with background=light immediately, like vim does
Actual behavior
neovim renders with background=dark, then sources the plugin, rerenders with background=light causing a visible flickering
Unfortunately it looks like there is no way to execute something earlier than from plugin/ directories, is there?
List of directories to be searched for these runtime files:
filetype.vim filetypes by file name |new-filetype|
scripts.vim filetypes by file contents |new-filetype-scripts|
autoload/ automatically loaded scripts |autoload-functions|
colors/ color scheme files |:colorscheme|
compiler/ compiler files |:compiler|
doc/ documentation |write-local-help|
ftplugin/ filetype plugins |write-filetype-plugin|
indent/ indent scripts |indent-expression|
keymap/ key mapping files |mbyte-keymap|
lang/ menu translations |:menutrans|
menu.vim GUI menus |menu.vim|
pack/ packages |:packadd|
plugin/ plugin scripts |write-plugin|
print/ files for printing |postscript-print-encoding|
rplugin/ |remote-plugin| scripts
spell/ spell checking files |spell|
syntax/ syntax files |mysyntaxfile|
tutor/ tutorial files |:Tutor|
Unfortunately it looks like there is no way to execute something earlier than from
plugin/directories, is there?
Only with --cmd. Can you try that , just for troubleshooting ?
neovim renders with
background=lightimmediately, like vim does
Vim assumes bg=light on many environments. Does the opposite problem happen in Vim, with a dark terminal?
Only with
--cmd. Can you try that , just for troubleshooting ?
nvim --cmd "set background=light" works (it does not flicker), but obviously I can't use that in a plugin.
Vim assumes bg=light on many environments. Does the opposite problem happen in Vim, with a dark terminal?
No, it does not happen in vim in any case, because vim sources the plugin file before rendering anything.
I cannot reproduce this v0.9.5 or v0.10.0-dev. Does this bug still exist?
Yes I can still reproduce this with v0.9.5 following the steps from the description (using a plugin that sets background from the plugin/ directory, e.g. vim-lumen).
I'm still reproducing this on v0.10.0-dev-78b000c, with the nord.nvim colorscheme. My current "fix" is to run echo " " right after setting the colorscheme