Show nvim diagnostics using virtual lines

#20 Formatting via LSP hides the virtual text

~whynothugo commented on lsp_lines.nvim todo

an hour ago

#20 Formatting via LSP hides the virtual text

~paveloom commented on lsp_lines.nvim todo

14 hours ago


lsp_lines is a simple neovim plugin that renders diagnostics using virtual lines on top of the real line of code.

A screenshot of the plugin in action

Font is Fira Code, a classic. Theme is tokyonight.nvim.


LSPs provide lots of useful diagnostics for code (typically: errors, warnings, linting). By default they're displayed using virtual text at the end of the line which is in many cases good enough, but often there's more than one diagnostic per line. It's also quite common to have more than one diagnostic per line, but again, there's no handy way to read the whole thing.

lsp_lines solves this issue.


#With packer.nvim

Using packer.nvim (this should probably be registered after lspconfig):

  config = function()

#With git

You can algo just clone the repo into neovim's plug-in directory:

mkdir -p $HOME/.local/share/nvim/site/pack/plugins/start/
cd $HOME/.local/share/nvim/site/pack/plugins/start/
git clone git@git.sr.ht:~whynothugo/lsp_lines.nvim

And then in init.lua:



It's recommended to also remove the regular virtual text diagnostics to avoid pointless duplication:

-- Disable virtual_text since it's redundant due to lsp_lines.
  virtual_text = false,


This plugin's functionality can be disabled with:

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

And it can be re-enabled via:

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

To show virtual lines only for the current line's diagnostics:

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

A helper is also provided to toggle, which is convenient for mappings:

  { desc = "Toggle lsp_lines" }



It would be nice to show connecting lines when there's relationship between diagnostics (as is the case with rust_analyzer). Oh perhaps surface them via hover().


This project is licensed under the ISC licence. See LICENCE for more details.