From 87dc719cf0b56f7f15654b797f6c3b6327a3675f Mon Sep 17 00:00:00 2001 From: Tovi Jaeschke-Rogers Date: Thu, 6 Jun 2024 22:06:08 +0930 Subject: [PATCH] feat: add toggle diagnostics command --- .config/nvim/lua/tovi/core/commands.lua | 28 +++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.config/nvim/lua/tovi/core/commands.lua b/.config/nvim/lua/tovi/core/commands.lua index 385032b..eaab2b0 100644 --- a/.config/nvim/lua/tovi/core/commands.lua +++ b/.config/nvim/lua/tovi/core/commands.lua @@ -1,15 +1,21 @@ - local function ToggleTabs() - local options = {"tabstop", "softtabstop", "shiftwidth"} + local options = { "tabstop", "softtabstop", "shiftwidth" } - for _, option in ipairs(options) do - local current_value = vim.opt[option]:get() - vim.opt[option] = (current_value == 4) and 2 or 4 - end + for _, option in ipairs(options) do + local current_value = vim.opt[option]:get() + vim.opt[option] = (current_value == 4) and 2 or 4 + end end -vim.api.nvim_create_user_command( - 'ToggleTabs', - ToggleTabs, - { nargs = 0 } -) +vim.api.nvim_create_user_command("ToggleTabs", ToggleTabs, { nargs = 0 }) + +vim.api.nvim_create_user_command("ToggleDiagnostics", function() + if vim.g.diagnostics_enable == nil or vim.g.diagnostics_enable then + vim.g.diagnostics_enable = false + vim.diagnostic.enable(false) + return + end + + vim.g.diagnostics_enable = true + vim.diagnostic.enable(true) +end, {})