fzf.vim icon indicating copy to clipboard operation
fzf.vim copied to clipboard

Add support to delete buffers in :Buffers command

Open mracos opened this issue 4 years ago • 11 comments

By pressing the CTRL-D keybinding. Also enabled the -m multi select option to be able to delete multiple buffers.


Screen Shot 2021-02-03 at 23 46 44

mracos avatar Feb 04 '21 02:02 mracos

Would it be possible to also include Ctrl-W for buffer-wipe and also the possibility to delete/wipe the current (%) buffer which is currently unfortunately unselectable ?

dav-dev avatar Apr 28 '21 12:04 dav-dev

Hi @dav-dev! I tried to make this patch as small as possible to increase the probability of being merged (easier to review, no big changes, etc). Let's first hear what the maintainers have to say and then we can improve upon (if gets merged haha). WDYT?

mracos avatar Apr 30 '21 16:04 mracos

@junegunn Lets get this merged.. This is super useful for power users

@mracos What do you think about "select all" buffers matching the search pattern for deletion ? I'm thinking add "Ctrl-a" to do select all and ctrl-d to delete them

rameshsanth avatar Aug 03 '21 18:08 rameshsanth

Hey peeps 👋

Is this something that could be added in config via fzf_action? or can :Buffers not be customized in the same way as :Files?

" Delete a buff
function! s:delete_buffer(args)
  " Delete buffer here...
endfunction

let g:fzf_action = {
  \ 'ctrl-q': function('s:build_quickfix_list'),
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': 'split',
  \ 'ctrl-v': 'vsplit',
  \ 'ctrl-d': function('s:delete_buffer'),
  \ }

https://github.com/perrupa/dotfiles/blob/master/vim/plugin/fzf.vim#L13-L17

I found this PR trying to add something like above in my .vimrc and would love to help if possible. 👌

perrupa avatar Oct 19 '21 18:10 perrupa

I was looking for this feature and found this PR. It's exactly what I'm missing, any potential to get it merged?

Limero avatar Jul 26 '22 16:07 Limero

Sending my encouragement to get this exact functionality merged into fzf.vim. Would absolutely love it.

miklhh avatar Feb 28 '23 13:02 miklhh

@mracos, I think it would be a really nice touch if CTRL+D did not close the :Buffers window, but instead closed the selected buffers and simply updated the :Buffers window. Further, when I tried your branch mracos:mf-add-delete-option-to-buffers-command, :Buffers no longer seem to honor my keybindings within the :Buffers window.

miklhh avatar Mar 01 '23 09:03 miklhh

@mracos, I think it would be a really nice touch if CTRL+D did not close the :Buffers window, but instead closed the selected buffers and simply updated the :Buffers window. Further, when I tried your branch mracos:mf-add-delete-option-to-buffers-command, :Buffers no longer seem to honor my keybindings within the :Buffers window.

I too think this is the ideal behavior. I have been thinking about this feature for a long time, and after reading the changes here and the source code a bit, I think it'll require rather large rewrites to function! s:fzf and to function! fzf#run (from junegunn/fzf).

The problem is that currently this PR uses the --expect ctrl-d fzf argument, and not --bind=ctrl-d:execute(<cmd>). The hard part is to make <cmd> delete the line from the query, which is currently held in a temporary file when you run :Buffers.

The current implementation is great never the less, thanks for putting the hard work!

doronbehar avatar Mar 04 '23 17:03 doronbehar

Hey folks, thank you so much for the investigation and interest. It's been a while since I've last touched this PR and I have stopped using fzf.vim ever since 😞

So if anyone wants feel free to pick up this PR from there or even redo it from scratch, given that it's stale it might be easier

mracos avatar Mar 06 '23 12:03 mracos

See PR above as a proposed solution. I have just a few comments on the thread:

@mracos What do you think about "select all" buffers matching the search pattern for deletion ? I'm thinking add "Ctrl-a" to do select all and ctrl-d to delete them

While it is possible and relatively easy to use fzf's --bind to set ctrl-a:select-all. I did not include this in the PR as this behavior is inconsistent across fzf.vim and in other areas alt-a:select-all is used. I think it would be useful to have a consistent behavior for all functions that use --multi.

Would it be possible to also include Ctrl-W for buffer-wipe and also the possibility to delete/wipe the current (%) buffer which is currently unfortunately unselectable ?

Adapting this PR to allow CTRL-W to execute :bwipeout is trivial to implement, but as the vim :help :bwipeout suggests you should only do this "if you know what you're doing". Usually :bdelete is sufficient and should be the more common use case, so I didn't implement this. Deleting or wiping the current buffer is as simple as typing :bd or :bw and I did not feel this needed to be an additional functionality within the plugin.

connermcd avatar Mar 29 '23 18:03 connermcd

BTW I use https://github.com/ibhagwan/fzf-lua which has this feature.

doronbehar avatar Mar 31 '23 13:03 doronbehar