famiu / bufdelete.nvim

Delete Neovim buffers without losing window layout
GNU General Public License v3.0
514 stars 16 forks source link

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

Open neandrake opened 10 months ago

neandrake commented 10 months ago

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:

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.

famiu commented 10 months ago

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

neandrake commented 10 months ago

Using :bdelete lazy gives an error:

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