Search code examples
neovimlazyvim

How to jump into diagnostic buffer in LazyVim/Neovim?


In Neovim with the LazyVim configuration, when I press ] w (next warning) or ] e (next error) there is a box with the diagnostic information. How do I move into it so that I can then yank the diagnostic content to easily search for related information on the internet?

I tried to see the possible commands after pressing ] e, but the suggested are not related to what I'm looking for. I'm not sure if there is a built-in command to achieve this in LazyVim, or if I need to set it up in my config.

diagnostic message example


Solution

  • Per the default LazyVim mappings file located in your Neovim configuration folder under lua/lazyvim/config/keymaps.lua, you can:

    1. Open a floating window with the full diagnostic (error, warning etc.) message by pressing <leader>cd (when your cursor is over the line with the error).
    2. Jump into that window by repeating the same key combination again.
    3. Copy the error message as you normally would copy text in any other window.
    4. Exit the floating diagnostic window via :q just like you would exit any other window.

    Alternatively, you can add another mapping that opens a split window with the full diagnostic list. It seems LazyVim does not have this by default. For example, add the following line to your keymaps.lua file:

    vim.keymap.set("n", "<leader>d", vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
    

    After opening this window split with the diagnostic list, you can navigate the content as you would normally, copy content as you'd like, and also jump to a particular error by pressing <Enter> when your cursor is over a particular diagnostic message in the diagnostic list. To jump back to the diagnostic list window, use your normal window navigation keys. To close the diagnostic list, ensure it is the active window, then you can either press the same key combination you used to open it, or use :q.