vim/keymap: add mappings to toggle and hide diagnostics

This commit is contained in:
Fernando Schauenburg 2023-08-08 03:44:44 +02:00
parent dc0516f38f
commit 9906368e50
2 changed files with 20 additions and 0 deletions

View file

@ -67,6 +67,9 @@ nmap('<localleader>k', '<cmd>lprevious<cr>zz', { silent = true })
-- navigate diagnostics
nmap('<leader>dj', require('fschauen.util').goto_next_diagnostic)
nmap('<leader>dk', require('fschauen.util').goto_prev_diagnostic)
nmap('<leader>dd', require('fschauen.util').toggle_diagnostics)
nmap('<leader>do', require('fschauen.util').open_float_diagnostic)
nmap('<leader>dh', require('fschauen.util').hide_diagnostics)
-- toggle quickfix and loclist
nmap('<leader>ll', util.toggle_quickfix, { desc = 'Toggle quickfix' } )

View file

@ -98,6 +98,23 @@ M.goto_prev_diagnostic = function(opts)
vim.cmd 'normal zz'
end
M.open_float_diagnostic = function(opts)
vim.diagnostic.open_float(vim.tbl_extend('keep', opts or {}, { border = 'rounded' }))
end
M.toggle_diagnostics = function(bufnr)
bufnr = bufnr or 0
if vim.diagnostic.is_disabled(bufnr) then
vim.diagnostic.enable(bufnr)
else
vim.diagnostic.disable(bufnr)
end
end
M.hide_diagnostics = function(bufnr)
vim.diagnostic.hide(nil, bufnr or 0)
end
--- Whether the current window is the last in a given direction.
---@param direction string: one of 'h', 'j', 'k', or 'l'
local win_is_last = function(direction)