Avoid navigating in show_line_diagnostics window

Currently I have an autocmd with CursorHold that calls lua vim.lsp.diagnostic.show_line_diagnostics(). However, since repeating “show_line_diagnostics()” will take me inside of the floating window, it seems that there is a lot of situations where my cursor will end up hijacked and go into the diagnostics floating window.

I have removed some scenarios where that would happen, like going to the next or previous diagnostic using :

map('n', '<leader>ln', '<cmd>lua vim.lsp.diagnostic.goto_next({enable_popup= false})<CR>')

But there are still various scenarios where it can happen. For example, having an error at the end of the line and pressing “l” will take me inside the popup.

Is there any way to prevent navigation into the diagnostics floating window when using such an autocmd? Or perhaps a better way to get the same behavior as the current autocmd, but without the navigation troubles?

I think I had the same issue in the past, and used this autocmd to solve the issue. Maybe it’ll work for you as well…

The focusable = false is the interesting part here.

vim.cmd("autocmd CursorHold <buffer> lua vim.lsp.diagnostic.show_line_diagnostics({ focusable = false })")
1 Like

Thanks a lot! That does seem to work. I didn’t see any mention of focusable in the show_line_diagnostics doc, just curious how you found out about it?

I think I saw someone asking this same question on the neovim subreddit at some point and I just copied it from there haha. Happy to pass it on.

I guess it’s my fault for not documenting it properly when I added it. It’s been fixed today though :smiley: . Basically it was an option for open_floating_preview() that could be used from show_line_diagnostics()

1 Like