folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.63k stars 177 forks source link

bug: Trouble windows should set `winfixbuf` #593

Open dlyongemallo opened 1 month ago

dlyongemallo commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

Ubuntu 22.04

Describe the bug

Trouble's special windows do not set winfixbuf. In particular, when in the qflist window, using :cnext or :cprev results in a Cursor position outside buffer error (whereas neovim's own copen/cfile window handles this perfectly fine).

Steps To Reproduce

  1. nvim -u repro.lua
  2. :cfile cfile.txt (attached cfile.txt)
  3. :copen, switch to this window
  4. :cnext, works perfectly fine
  5. :Trouble qflist toggle, switch to the Trouble window
  6. :cnext, results in error

Expected Behavior

:cnext and :cprev should work as if in the native copen window.

Note: If :set winfixbuf is used inside the Trouble window, then :cnext and :cprev work as expected.

Repro

-- use vim-plug
local vim = vim
local Plug = vim.fn['plug#']

vim.call('plug#begin')
Plug('folke/trouble.nvim')
vim.call('plug#end')
require("trouble").setup()
jonsmithers commented 4 weeks ago

I also encounter this issue (Cursor position outside buffer errors) when I mess with the windows while Trouble is open. Specifically if I close every window except the trouble window using <c-w>o, and then press enter to jump to the selected diagnostic.

If I set winfixbuf in the Trouble window as suggested above, I instead see a single error Cannot switch buffer. 'winfixbuf' is enabled.

dlyongemallo commented 3 weeks ago

If anyone else has the same problem, I worked around this by putting the following in my ~/.config/nvim/after/ftplugin/trouble.lua:

vim.keymap.set('n', ']q', 'j', { buffer = 0, noremap = true, silent = true })
vim.keymap.set('n', '[q', 'k', { buffer = 0, noremap = true, silent = true })