A minimal, good looking diagnostic float window for Neovim.
require('zendiagram').setup({
-- Below are the default values
header = "Diagnostics", -- Float window title
source = true, -- Whether to display diagnostic source
relative = "line", -- "line"|"win" - What the float window's position is relative to
anchor = "NE", -- "NE"|"SE"|"SW"|"NW" - When 'relative' is set to "win" this sets the position of the floating window
})zendiagram exposes a few ways to configure and use the plugin.
As the underlying api used is the vim.diagnostic.open_float the most convenient solution is to override the default function.
As the vim.diagnostic.open_float api is used, all the expected behaviours around focusing the window remain constant here.
require("zendiagram").setup()
vim.diagnostic.open_float = Zendiagram.open
-- or: vim.diagnostic.open_float = require("zendiagram").open()
-- or: vim.diagnostic.open_float = vim.cmd.Zendiagram('open')
vim.keymap.set(
"n",
"<Leader>e",
vim.diagnostic.open_float,
{ silent = true, desc = "Open diagnostics float" }
)The open command is the entry point, there are a few ways of accessing it:
- A user command:
:Zendiagram open
vim.cmd.Zendiagram('open')- A lua function:
require("zendiagram").open()- The Zendiagram global:
Zendiagram.open()If you don't want to override the default vim.diagnostic.open_float you can use these functions in your keymaps or autocmds.
vim.keymap.set(
"n",
"<Leader>e",
function()
require('zendiagram').open()
-- or: vim.cmd.Zendiagram('open')
-- or: Zendiagram.open()
-- or: vim.diagnostic.open_float() if you have overridden the default function
end,
{ silent = true, desc = "Open diagnostics float" }
)Similarly, you can use an autocmd to automatically open the diagnostics float when the cursor moves.
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
callback = function()
require("zendiagram").open()
-- or: vim.cmd.Zendiagram('open')
-- or: Zendiagram.open()
-- or: vim.diagnostic.open_float() if you have overridden the default function
end,
})Another option would be to override the default vim.diagnostic.jump keymaps like so:
vim.keymap.set({"n", "x"}, "]d", function ()
vim.diagnostic.jump({ count = 1 })
vim.schedule(function()
require("zendiagram").open()
-- or: vim.cmd.Zendiagram('open')
-- or: Zendiagram.open()
-- or: vim.diagnostic.open_float() if you have overridden the default function
end)
end, { desc = "Jump to next diagnostic" })
vim.keymap.set({"n", "x"}, "[d", function ()
vim.diagnostic.jump({ count = -1 })
vim.schedule(function()
require("zendiagram").open()
-- or: vim.cmd.Zendiagram('open')
-- or: Zendiagram.open()
-- or: vim.diagnostic.open_float() if you have overridden the default function
end)
end, { desc = "Jump to prev diagnostic" })There are highlight groups exposed if you wish to customise the appearance of the float and it's contents.
- "ZendiagramText",
- "ZendiagramKeyword"
- "ZendiagramSeparator"
- "ZendiagramHeader"