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

How do I display LSP diagnostic messages inline below each affected line in Neovim 0.11?

Answer

vim.diagnostic.config({virtual_lines = true})

Explanation

Neovim 0.11 added support for virtual_lines in vim.diagnostic.config(), which renders diagnostic messages as dedicated virtual lines directly below the affected code rather than as cramped virtual text appended to the end of each line. This makes long error messages and multi-diagnostic situations much easier to read.

How it works

  • virtual_lines = true renders each diagnostic on its own line below the offending code, with a leading arrow pointing back to the source
  • virtual_lines = { current_line = true } shows virtual lines only for the diagnostic on the cursor's current line, reducing noise
  • This replaces the default virtual_text rendering for diagnostics

Example

-- In init.lua:
vim.diagnostic.config({
  virtual_lines = { current_line = true },
  virtual_text = false,  -- disable default inline virtual text
  signs = true,
  underline = true,
})

With current_line = true, the diagnostic detail appears only when your cursor is on the affected line, keeping the buffer readable while still giving full diagnostic context on demand.

Tips

  • Combine virtual_lines = { current_line = true } with virtual_text = false for a clean look: no clutter on most lines, full detail when needed
  • Toggle at runtime: vim.diagnostic.config({ virtual_lines = not vim.diagnostic.config().virtual_lines })
  • Requires Neovim 0.11 or later — earlier versions only support virtual_text

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?