vim: add mapping to navigate next/previous diagnostic

This commit is contained in:
Fernando Schauenburg 2023-08-06 19:54:16 +02:00
parent 57de226fcf
commit c7e1f398a7
2 changed files with 21 additions and 0 deletions

View file

@ -63,6 +63,10 @@ nmap('<Up>', '<cmd>cprevious<cr>zz', { silent = true })
nmap('<a-Down>', '<cmd>lnext<cr>zz', { silent = true }) nmap('<a-Down>', '<cmd>lnext<cr>zz', { silent = true })
nmap('<a-Up>', '<cmd>lprevious<cr>zz', { silent = true }) nmap('<a-Up>', '<cmd>lprevious<cr>zz', { silent = true })
-- navigate diagnostics
nmap('<leader>j', require('user.util').goto_next_diagnostic)
nmap('<leader>k', require('user.util').goto_prev_diagnostic)
-- quickly open lazy.nvim plugin manager -- quickly open lazy.nvim plugin manager
nmap('<leader>L', '<cmd>Lazy<cr>') nmap('<leader>L', '<cmd>Lazy<cr>')

View file

@ -56,6 +56,23 @@ M.get_selected_text = function()
end) end)
end end
local diag_opts = {
wrap = false, -- don't wrap around the begin/end of file
float = {
border = 'rounded' -- enable border for the floating window
},
}
-- Move to the next diagnostic.
M.goto_next_diagnostic = function(opts)
vim.diagnostic.goto_next(vim.tbl_extend('keep', opts or {}, diag_opts))
end
-- Move to the previous diagnostic.
M.goto_prev_diagnostic = function(opts)
vim.diagnostic.goto_prev(vim.tbl_extend('keep', opts or {}, diag_opts))
end
M.use_local = function() M.use_local = function()
end end