Nvim: add ability to switch between dark and light theme

This commit is contained in:
Marko Korhonen 2024-01-25 15:30:12 +02:00
parent 80d983447c
commit d764006143
Signed by: FunctionalHacker
GPG key ID: A7F78BCB859CD890
3 changed files with 14 additions and 1 deletions

View file

@ -1,6 +1,7 @@
{
"LuaSnip": { "branch": "master", "commit": "2dbef19461198630b3d7c39f414d09fb07d1fdd2" },
"alpha-nvim": { "branch": "main", "commit": "4b36c1ca9ea475bdc006896657cf1ccc486aeffa" },
"auto-dark-mode.nvim": { "branch": "master", "commit": "76e8d40d1e1544bae430f739d827391cbcb42fcc" },
"bufferline.nvim": { "branch": "main", "commit": "6c456b888823d9e4832aa91c482bccd19445c009" },
"cder.nvim": { "branch": "main", "commit": "07c9e3e8324ee7c3ffde493c1612aca0be5255d0" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
@ -62,4 +63,4 @@
"vim-fugitive": { "branch": "master", "commit": "854a8df0d06b8d3fcb30fa7f2b08c62b553eee3b" },
"vim-gnupg": { "branch": "main", "commit": "f9b608f29003dfde6450931dc0f495a912973a88" },
"which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }
}
}

View file

@ -2,6 +2,7 @@
--- @type LazyPluginSpec
return {
"rebelot/kanagawa.nvim",
dependencies = { { "f-person/auto-dark-mode.nvim", config = true } },
--- @type KanagawaConfig
opts = {
compile = true,

View file

@ -1,6 +1,16 @@
-- Display possible keybinds
-- Here I have also defined some generic keybinds
-- Plugin specific keybinds are set up in plugin configuration file
local function toggle_theme()
local current_theme = vim.fn.eval("&background")
if current_theme == "dark" then
vim.cmd("set background=light")
else
vim.cmd("set background=dark")
end
end
--- @type LazyPluginSpec
return {
"folke/which-key.nvim",
@ -10,6 +20,7 @@ return {
wk.register({
h = { "<cmd>nohlsearch<cr>", "Turn off search highlight" },
b = { toggle_theme, "Toggle background between dark and light" },
}, { prefix = "<leader>" })
wk.register({