There are probably 20 better ways to do what I'm trying to do. Please direct me to them if so - I haven't found them and not quite sure what to terms to search.
I would prefer to set background=dark or background=light depending on what my system theme is, but I haven't been able to figure that out and got tired of trying.
So instead I'm trying something else, that's not quite as good as that but I think will be an improvement over manually toggling background every time I open vim: when I run a custom command to toggle the background, also set the some register equal to "dark" or "light". Then, when Vim starts up, check that register and set the background accordingly.
However, Vim doesn't seem to actually check the contents of the registers on start up, or at least how I'm doing it.
Any advice? Is there some other way to set the value of a variable from within Vim and have that persist after Vim is exited?
Here's the background toggle function:
function! ToggleBackground()
if (&background ==# "dark")
set background=light
let @b = 'light' " set the b register = 'light'
else
set background=dark
let @b = 'dark' " set the b register = 'dark'
endif
endfunction
And here's how I'm trying to set background at startup:
if @b == "dark"
set background=dark
else
set background=light
endif
The if statement never evaluates to true when starting Vim, even though I've checked the value of the register using (:echo @b
) after running the toggle command, and it is indeed being set to 'dark'.