bufdelete.nvim icon indicating copy to clipboard operation
bufdelete.nvim copied to clipboard

[Feature] Restrict closing-by-search-term to only close a buffer if a single buffer matches the term.

Open neandrake opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. When using Bdelete or Bwipe with a text/string parameter to close a buffer, if the term matches multiple buffers one will be closed seemingly at random. This is particularly problematic when a buffer's relative file path matches the term and not the file name.

Example: My neovim config directory has the following files:

  • lua/neandrake/lazy.lua
  • lua/neandrake/lazy_plugins/bufdelete.lua
  • lua/neandrake/lazy_plugins/... .lua

I then run :Bdel lazy with the intent to close lazy.lua but bufdelete.lua ends up closing. This happens because the buffer's name is the relative-to-cwd path + filename of the file, in this case lua/neandrake/lazy_plugins/bufdelete.lua and lazy matched the path element lazy_plugins. Presumably this would happen not at random but first match in order of what buffers were opened first.

Describe the solution you'd like Update matching behavior, or an option to do so, such that if multiple buffers match the search term then no buffers are closed. Alternatively only match on the filename part of the name, if it's reliable to do so.

Describe alternatives you've considered Closing by buffer ID instead of by name matching.

Additional context I use bufferline plugin to show UI-tabs for opened buffers, configured to display only the buffer's filename for each UI-tab. When using :Bd lazy I was confused to what happened as something had closed but not lazy.lua.

neandrake avatar Dec 28 '23 17:12 neandrake

How does :bdelete behave in this situation? Does :Bdelete have the same behavior as :bdelete?

famiu avatar Dec 28 '23 18:12 famiu

Using :bdelete lazy gives an error:

E93: More than one match for lazy
Screenshot 2023-12-28 at 1 43 25 PM

neandrake avatar Dec 28 '23 18:12 neandrake