Werewolf is a handy neovim plugin that automatically changes the theme, applies configs or runs other custom code depending on the system theme or the time of day. It actively listens for changes, so it can do this at runtime when the system theme changes from light to dark or vice versa, without needing to restart Neovim.
Packer:
use 'sheharyarn/werewolf.nvim'
Lazy:
{ 'sheharyarn/werewolf.nvim', lazy = false }
By default, werewolf
does not apply any custom code/theme on
system theme change or other events. Any options passed to
setup()
will be merged with these default options before being
applied.
{
system_theme = {
get = require('werewolf.utils').get_theme,
on_change = nil,
run_on_start = true,
period = 500,
},
}
In your init.lua
, add the following:
-- Example assumes material.nvim plugin is installed
require('werewolf').setup({
system_theme = {
on_change = function(theme)
-- Apply custom config based on new `theme` value
if theme == 'Dark' then
vim.g.material_style = 'deep ocean'
vim.o.background = 'dark'
vim.cmd('colorscheme material')
else
vim.g.material_style = 'lighter'
vim.o.background = 'light'
vim.cmd('colorscheme material')
end
end,
-- Change the check interval (optional)
period = 200,
},
})
If you have a more complex theme/styling configuration or want to
run additional code on system theme change events, it's better to
move that code out into separate functions and call them inside
on_change
:
if theme == 'Dark' then
MyUtils.dark_theme()
else
MyUtils.light_theme()
end
Also see this example from my dotfiles.
- Fork, Enhance, Send PR
- Lock issues with any bugs or feature requests
- Implement something from Roadmap
- Spread the word β€οΈ
This package is available as open source under the terms of the MIT License.
The Werewolf logo/image has been generated using OpenAI's DALL-E and does not have any copyrights, effectively being CC0.