wincent / command-t

⌨️ Fast file navigation for Neovim and Vim
BSD 2-Clause "Simplified" License
2.74k stars 317 forks source link

Opening multiple files from command-line `:CommandTBuffer` only sees the first #418

Closed wincent closed 1 year ago

wincent commented 1 year ago

When multiple files are opened when invoking nvim from the command line, :CommandTBuffer doesn't know about all the buffers. I am not sure if that is by design or not. This makes switching buffers with command-t impossible until all the buffers are cycled through with :bnext or similar. Once that is done, :CommandTBuffer knows about all the buffers.

Originally posted by @jaapie in https://github.com/wincent/command-t/issues/394#issuecomment-1635253772

wincent commented 1 year ago

Thanks for the report!

Definitely not by design, but it's a consequence of this logic in the buffer finder:

So, the intent of the nvim_buf_is_loaded check is to skip over "unloaded" buffers, which can cause problems. The api-buffer docs say this about unloaded buffers:

Unloaded Buffers: ~

Buffers may be unloaded by the |:bunload| command or the buffer's
|'bufhidden'| option. When a buffer is unloaded its file contents are
freed from memory and vim cannot operate on the buffer lines until it is
reloaded (usually by opening the buffer again in a new window). API
methods such as |nvim_buf_get_lines()| and |nvim_buf_line_count()| will be
affected.

I'm concerned that if I remove the nvim_buf_is_loaded check I'll wind up introducing a regression; but I didn't have this kind of thing in the Ruby version (the scanner was just parsing :ls output), so this code is pretty new (added in 0b8c9ed39c1352e3ed00798c7269385a69b7748a, "feat(lua): continue sketching out UI", July 20, 2022).

I can certainly play around with removing it, and if I can't do that, I might be able to do some special-casing to detect when Neovim has just launched and skip the check in that case...

jaapie commented 1 year ago

Thanks @wincent that's fixed it for me! I appreciate your efforts.