vimtricks.wiki Concise Vim tricks, one at a time.

How do I jump only to error-level diagnostics and skip warnings and hints in Neovim?

Answer

:lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})

Explanation

Neovim's built-in diagnostic system (vim.diagnostic) provides goto_next() and goto_prev() functions for jumping between diagnostics — but by default they cycle through all severities: errors, warnings, informational, and hints. Passing a severity filter lets you jump only to the diagnostics you care about most, cutting through the noise when a file has many low-severity hints.

How it works

  • vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR}) — jump to the next ERROR diagnostic only
  • vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR}) — jump to the previous error
  • vim.diagnostic.severity has four levels: ERROR, WARN, INFO, HINT
  • You can also pass a list to match multiple severities: {severity = {min = vim.diagnostic.severity.WARN}} — jumps to WARN and ERROR but not INFO/HINT

Example

Add severity-filtered jumps to your Neovim config:

noremap ]e <Cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<CR>
noremap [e <Cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<CR>
noremap ]d <Cmd>lua vim.diagnostic.goto_next()<CR>
noremap [d <Cmd>lua vim.diagnostic.goto_prev()<CR>

Now ]e/[e jump between errors only, while ]d/[d cycle through all diagnostics.

Tips

  • Use {severity = {min = vim.diagnostic.severity.WARN}} to jump to warnings and errors while ignoring hints
  • vim.diagnostic.get(0, {severity = vim.diagnostic.severity.ERROR}) returns a list of errors in the current buffer — useful for counting or checking programmatically
  • When using lazy-loading, these mappings are safe to define globally since vim.diagnostic is always available in Neovim 0.6+

Next

How do I make Neovim restore the scroll position when navigating back through the jump list?