feat: add keymap for copying diagnostics for buffer

This commit is contained in:
Stevan Freeborn
2026-07-21 09:31:54 -05:00
parent 6cdef2244d
commit b11cf10e31
+23
View File
@@ -452,6 +452,29 @@ return {
{ desc = "Display errors for current buffer", buffer = ev.buf }
)
vim.keymap.set("n", "<leader>eca", function()
local diagnostics = vim.diagnostic.get(0)
if #diagnostics == 0 then
vim.notify("No diagnostics in buffer", vim.log.levels.INFO)
return
end
local lines = vim.tbl_map(function(d)
return string.format(
"%s:%d %s",
vim.fs.basename(vim.api.nvim_buf_get_name(d.bufnr)),
d.lnum + 1,
d.message
)
end, diagnostics)
vim.fn.setreg("+", table.concat(lines, "\n"))
vim.notify(string.format("Copied %d diagnostics to clipboard", #diagnostics))
end, { desc = "Copy buffer diagnostics to clipboard", buffer = ev.buf })
vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Display symbol info", buffer = ev.buf })
end,
})