-
Personally I used to make my editors and other softwares' colorscheme(background) to follow system. So do I hope to implement this in neovim. Currently I'm using vim-lumen to fix correct background on startup, and subscribe to the system colorscheme change. It works well until I found it costs about 30ms each time to startup. I want make it lazy loaded, but found many problems that I cannot solve by myself, so I want to discuss and get help from the community: At first, I try to make
This is normal: local colorscheme = require("core.settings").colorscheme
vim.api.nvim_command("colorscheme " .. colorscheme)
vim.cmd("set background=light") But this is abnormal(You will see the bufferline and lualine become abnormal from normal suddenly: local colorscheme = require("core.settings").colorscheme
vim.api.nvim_command("colorscheme " .. colorscheme)
vim.api.nvim_create_autocmd("CursorHold", {
once = true,
callback = function(ev)
vim.cmd("set background=light")
end,
}) And this is normal again: local colorscheme = require("core.settings").colorscheme
vim.api.nvim_command("colorscheme " .. colorscheme)
vim.api.nvim_create_autocmd("CursorHold", {
once = true,
callback = function(ev)
vim.defer_fn(function()
vim.cmd("set background=light")
end, 1)
end,
}) It's quite odd and I really don't have any ideas of how this happened and how can we avoid it.
I tried start vim (with or without --clean) and nvim with --clean in system light or dark mode in Warp or iTerm2, it can set background correctly since I asked it with So I think, okay, I'll use the vim's builtin startup detection and I added
The color is quite odd and I found
In the Warp case, two messages will print, first In the lazygit case and iTerm2 case, one message will print, only Now I doubt maybe some plugin in this repo's config cause this problem. But I'm not really familiar with them and want to ask for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
For the lazygit part, did u set |
Beta Was this translation helpful? Give feedback.
-
Why set background? just use |
Beta Was this translation helpful? Give feedback.
-
@Saafo There're a few somehow unrelated confusions in your question, so I'll start with the terminal emulators (the "parent" programs), and move out from there: First let's take a look at the description of *'background'* *'bg'*
'background' 'bg' string ~~~ (default "dark") ~~~
global
When set to "dark" or "light", adjusts the default color groups for
that background type. The ~~~ |TUI| or other UI ~~~ sets this on startup
(triggering |OptionSet|) ~~~ if it can detect the background color. ~~~
This option does NOT change the background color, it tells Nvim what
the ~~~ "inherited" (terminal/GUI) background ~~~ looks like.
See |:hi-normal| if you want to set the background color explicitly.
....... Personally don't want this reply to become a technical summary, so the following descriptions only provide summaries for those implementations. For the "dirty" implementation details, please refer to the As described in the doc, whether
Next, you must not lazy-load vim-lumen, or it must be loaded before all plugins (well, except itself and The simplest fix is to not lazy-load vim-lumen and let vim-lumen hijack your environment - in fact, 30ms is extremely difficult to perceive. No need to spend so much time on this trivial timing improvement :) You can also adjust the configs of (and options related to) auto-session, but it's up to you to decide what auto-session should store to achieve the desired effect. I personally prefer the former b/c writing more efficient code is far more advantageous than saving a few milliseconds per startup 😄 |
Beta Was this translation helpful? Give feedback.
@Saafo There're a few somehow unrelated confusions in your question, so I'll start with the terminal emulators (the "parent" programs), and move out from there:
First let's take a look at the description of
'background'
inoptions.txt
(note the sections surrounded by~~~
)