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

How do I use Neovim 0.11's unified diagnostic jump API to navigate to the next or previous diagnostic?

Answer

vim.diagnostic.jump({count=1})

Explanation

Neovim 0.11 introduced vim.diagnostic.jump() as a single, unified function replacing the older vim.diagnostic.goto_next() and vim.diagnostic.goto_prev() pair. It gives you finer control over diagnostic navigation through a single, consistent API with support for direction, severity filtering, and floating window display.

How it works

  • count controls direction and distance: positive values move forward, negative values move backward
  • severity restricts jumps to a specific diagnostic level
  • wrap (default true) controls whether navigation wraps around the end of the file
  • float controls whether a floating window with the diagnostic message is shown on jump
-- Jump to next diagnostic (any severity)
vim.diagnostic.jump({ count = 1 })

-- Jump to previous diagnostic
vim.diagnostic.jump({ count = -1 })

-- Jump forward, errors only, show float
vim.diagnostic.jump({ count = 1, severity = vim.diagnostic.severity.ERROR, float = true })

Example

A typical keybinding setup in your Neovim config:

vim.keymap.set('n', ']d', function()
  vim.diagnostic.jump({ count = 1, float = true })
end)
vim.keymap.set('n', '[d', function()
  vim.diagnostic.jump({ count = -1, float = true })
end)
vim.keymap.set('n', ']e', function()
  vim.diagnostic.jump({ count = 1, severity = vim.diagnostic.severity.ERROR })
end)

Tips

  • vim.diagnostic.goto_next() and vim.diagnostic.goto_prev() are deprecated in Neovim 0.11 — migrate to jump()
  • Passing count = 2 skips ahead two diagnostics in a single call
  • The float option accepts either a boolean or a table of options passed to vim.diagnostic.open_float()

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?