feat(keymaps): added toggle for diagnostics and conceal

This commit is contained in:
Folke Lemaitre 2023-01-06 23:51:22 +01:00
parent 8174821b71
commit 77672ba3fd
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 29 additions and 1 deletions

View file

@ -75,6 +75,9 @@ vim.keymap.set("n", "<leader>tf", require("lazyvim.plugins.lsp.format").toggle,
vim.keymap.set("n", "<leader>ts", function() util.toggle("spell") end, { desc = "Spelling" }) vim.keymap.set("n", "<leader>ts", function() util.toggle("spell") end, { desc = "Spelling" })
vim.keymap.set("n", "<leader>tw", function() util.toggle("wrap") end, { desc = "Word Wrap" }) vim.keymap.set("n", "<leader>tw", function() util.toggle("wrap") end, { desc = "Word Wrap" })
vim.keymap.set("n", "<leader>tn", function() util.toggle("relativenumber", true) util.toggle("number") end, { desc = "Line Numbers" }) vim.keymap.set("n", "<leader>tn", function() util.toggle("relativenumber", true) util.toggle("number") end, { desc = "Line Numbers" })
vim.keymap.set("n", "<leader>td", util.toggle_diagnostics, { desc = "Diagnostics" })
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
vim.keymap.set("n", "<leader>tc", function() util.toggle("conceallevel", false, {0, conceallevel}) end, { desc = "Conceal" })
-- lazygit -- lazygit
vim.keymap.set("n", "<leader>gg", function() require("lazyvim.util").float_term({ "lazygit" }) end, { desc = "Lazygit (cwd)" }) vim.keymap.set("n", "<leader>gg", function() require("lazyvim.util").float_term({ "lazygit" }) end, { desc = "Lazygit (cwd)" })

View file

@ -71,7 +71,20 @@ function M.float_term(cmd, opts)
end end
---@param silent boolean? ---@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() vim.opt_local[option] = not vim.opt_local[option]:get()
if not silent then if not silent then
vim.notify( vim.notify(
@ -82,4 +95,16 @@ function M.toggle(option, silent)
end end
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 return M