vimtricks.wiki Concise Vim tricks, one at a time.

How do I disable or customize virtual text diagnostic messages in Neovim's built-in LSP?

Answer

:lua vim.diagnostic.config({virtual_text = false})

Explanation

Neovim's built-in diagnostic system (vim.diagnostic) shows LSP errors, warnings, hints, and info as virtual text inline with your code by default. For large codebases or noisy linters this can clutter the view. vim.diagnostic.config() gives you fine-grained control over all diagnostic display options.

How it works

Call vim.diagnostic.config() with a table of options to override the defaults:

" Disable virtual text entirely
:lua vim.diagnostic.config({virtual_text = false})

" Show only errors as virtual text, not warnings
:lua vim.diagnostic.config({virtual_text = {severity = vim.diagnostic.severity.ERROR}})

" Customize the virtual text prefix
:lua vim.diagnostic.config({virtual_text = {prefix = '●'}})

" Disable signs in the gutter
:lua vim.diagnostic.config({signs = false})

" Disable underline for diagnostics
:lua vim.diagnostic.config({underline = false})

Example

Before (distracting inline error text):

let x = undefined_var;  -- E: undefined variable 'undefined_var'

After vim.diagnostic.config({virtual_text = false}):

let x = undefined_var;  (underline only, no inline text)

Tips

  • Place vim.diagnostic.config({...}) in your init.lua or in an LspAttach autocommand to apply it on startup
  • Use :lua vim.diagnostic.open_float() to see the full diagnostic message in a popup when virtual text is disabled
  • Toggle virtual text interactively: :lua vim.diagnostic.config({virtual_text = not vim.diagnostic.config().virtual_text})
  • The update_in_insert option controls whether diagnostics update while you are typing in insert mode (defaults to false)

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?