diff --git a/lua/lazyvim/config/keymaps.lua b/lua/lazyvim/config/keymaps.lua index 285518ba..fb35423d 100644 --- a/lua/lazyvim/config/keymaps.lua +++ b/lua/lazyvim/config/keymaps.lua @@ -75,6 +75,9 @@ vim.keymap.set("n", "tf", require("lazyvim.plugins.lsp.format").toggle, vim.keymap.set("n", "ts", function() util.toggle("spell") end, { desc = "Spelling" }) vim.keymap.set("n", "tw", function() util.toggle("wrap") end, { desc = "Word Wrap" }) vim.keymap.set("n", "tn", function() util.toggle("relativenumber", true) util.toggle("number") end, { desc = "Line Numbers" }) +vim.keymap.set("n", "td", util.toggle_diagnostics, { desc = "Diagnostics" }) +local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 +vim.keymap.set("n", "tc", function() util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Conceal" }) -- lazygit vim.keymap.set("n", "gg", function() require("lazyvim.util").float_term({ "lazygit" }) end, { desc = "Lazygit (cwd)" }) diff --git a/lua/lazyvim/util.lua b/lua/lazyvim/util.lua index 36830ad8..4ebebe4a 100644 --- a/lua/lazyvim/util.lua +++ b/lua/lazyvim/util.lua @@ -71,7 +71,20 @@ function M.float_term(cmd, opts) end ---@param silent boolean? -function M.toggle(option, silent) +---@param values? {[1]:any, [2]:any} +function M.toggle(option, silent, values) + if values then + if vim.opt_local[option]:get() == values[1] then + vim.opt_local[option] = values[2] + else + vim.opt_local[option] = values[1] + end + return vim.notify( + "Set " .. option .. " to " .. vim.opt_local[option]:get(), + vim.log.levels.INFO, + { title = "Option" } + ) + end vim.opt_local[option] = not vim.opt_local[option]:get() if not silent then vim.notify( @@ -82,4 +95,16 @@ function M.toggle(option, silent) end end +local enabled = true +function M.toggle_diagnostics() + enabled = not enabled + if enabled then + vim.diagnostic.enable() + vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) + else + vim.diagnostic.disable() + vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) + end +end + return M