feat(defaults): use vim.diagnostic.jump() for default mappings (#29066)

This allows the mappings to work with a count and also enables new ]D
and [D mappings to go to the last/first diagnostic in the buffer.
This commit is contained in:
Gregory Anders
2024-05-28 13:24:16 -05:00
committed by GitHub
parent fc2429962a
commit 1c6d920052
5 changed files with 39 additions and 18 deletions

View File

@@ -180,12 +180,20 @@ do
--- See |[d-default|, |]d-default|, and |CTRL-W_d-default|.
do
vim.keymap.set('n', ']d', function()
vim.diagnostic.goto_next({ float = false })
end, { desc = 'Jump to the next diagnostic' })
vim.diagnostic.jump({ count = vim.v.count1, float = false })
end, { desc = 'Jump to the next diagnostic in the current buffer' })
vim.keymap.set('n', '[d', function()
vim.diagnostic.goto_prev({ float = false })
end, { desc = 'Jump to the previous diagnostic' })
vim.diagnostic.jump({ count = -vim.v.count1, float = false })
end, { desc = 'Jump to the previous diagnostic in the current buffer' })
vim.keymap.set('n', ']D', function()
vim.diagnostic.jump({ count = math.huge, wrap = false, float = false })
end, { desc = 'Jump to the last diagnostic in the current buffer' })
vim.keymap.set('n', '[D', function()
vim.diagnostic.jump({ count = -math.huge, wrap = false, float = false })
end, { desc = 'Jump to the first diagnostic in the current buffer' })
vim.keymap.set('n', '<C-W>d', function()
vim.diagnostic.open_float()