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.
This commit is contained in:
Marty Oehme 2023-11-15 13:28:35 +01:00
parent c3fe4cdc58
commit b45296765a
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -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,
},
})