Skip to content

caliguIa/zendiagram.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zendiagram.nvim

A minimal, good looking diagnostic float window for Neovim.

Screenshots

Installation

mini.deps

Using mini.deps:

add("caliguIa/zendiagram.nvim")
require('zendiagram').setup()
lazy.nvim

Using lazy.nvim:

return {
    "caliguIa/zendiagram.nvim",
    opts = {},
}

Configuration

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

Usage

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"

About

Minimalistic and good looking Neovim diagnostics float window

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages