From b45296765a454e72ebec4f0637f65690d94285d4 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 15 Nov 2023 13:28:35 +0100 Subject: [PATCH] nvim: Hide virtual-text diagnostics on insert When writing something we often want to ideally hide the long comments added to the end of any line in-progress as virtual text currently. This simply adds an auto-command to hide when entering and show again when exiting insert mode, simple but hopefully useful. --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index cb75d7d..0670395 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -122,6 +122,11 @@ local function on_attach(client, bufnr) end end +-- Display diagnostics as virtual text only if not in insert mode +-- https://lr.artemislena.eu/r/neovim/comments/12inp4c/disable_diagnostics_virtual_text_when_in_insert/jqqifwk/ +vim.api.nvim_create_autocmd("InsertEnter", { callback = function() vim.diagnostic.config({ virtual_text = false, }) end }) +vim.api.nvim_create_autocmd("InsertLeave", { callback = function() vim.diagnostic.config({ virtual_text = true, }) end }) + lsp.setup({ default_mappings = false, servers = servers, @@ -203,3 +208,4 @@ require("mason-null-ls").setup({ end, }, }) +