Skip to content

Commit

Permalink
feat(diagnostic): add default mappings for diagnostics
Browse files Browse the repository at this point in the history
Add mappings for goto_next, goto_prev, and open_float.
  • Loading branch information
gpanders committed Apr 24, 2024
1 parent a1550db commit c79cd15
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions runtime/doc/diagnostic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ Example: >lua
end,
})
<
==============================================================================
MAPS *diagnostic-maps*

*]d-default*
]d Goto the next diagnostic in the buffer.
|vim.diagnostic.goto_next()|
*[d-default*
[d Goto the previous diagnostic in the buffer.
|vim.diagnostic.goto_prev()|

CTRL-W CTRL-D *CTRL-W_d-default*
CTRL-W d Open a floating window for diagnostics under
the cursor. |vim.diagnostic.open_float()|.

==============================================================================
Lua module: vim.diagnostic *diagnostic-api*

Expand Down
3 changes: 3 additions & 0 deletions runtime/doc/vim_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y".
- * |v_star-default|
- gc |gc-default| |v_gc-default| |o_gc-default|
- gcc |gcc-default|
- ]d |]d-default|
- [d |[d-default|
- <C-W>d |CTRL-W_d-default|
- Nvim LSP client defaults |lsp-defaults|
- K |K-lsp-default|

Expand Down
33 changes: 32 additions & 1 deletion runtime/lua/vim/_defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ do
end, { desc = gx_desc })
end

--- Default maps for built-in commenting
--- Default maps for built-in commenting.
---
--- See |gc-default| and |gcc-default|.
do
local operator_rhs = function()
return require('vim._comment').operator()
Expand All @@ -143,6 +145,35 @@ do
end
vim.keymap.set({ 'o' }, 'gc', textobject_rhs, { desc = 'Comment textobject' })
end

--- Map [d and ]d to move to the previous/next diagnostic. Map <C-W>d to open a floating window
--- for the diagnostic under the cursor.
---
--- See |[d-default|, |]d-default|, and |CTRL-W_d-default|.
do
vim.keymap.set('n', ']d', function()
vim.diagnostic.goto_next({ severity = 'auto', float = false })
end, {
desc = 'Jump to the next diagnostic with the highest severity',
})

vim.keymap.set('n', '[d', function()
vim.diagnostic.goto_prev({ severity = 'auto', float = false })
end, {
desc = 'Jump to the previous diagnostic with the highest severity',
})

vim.keymap.set('n', '<C-W>d', function()
vim.diagnostic.open_float({ border = 'rounded' })
end, {
desc = 'Open a floating window showing diagnostics under the cursor',
})

vim.keymap.set('n', '<C-W><C-D>', '<C-W>d', {
remap = true,
desc = 'Open a floating window showing diagnostics under the cursor',
})
end
end

--- Default menus
Expand Down

0 comments on commit c79cd15

Please sign in to comment.