Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to delete buffers in :Buffers command #1239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mracos
Copy link

@mracos mracos commented Feb 4, 2021

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 mracos force-pushed the mf-add-delete-option-to-buffers-command branch from d17b80d to a54fcbc Compare February 4, 2021 02:50
return
endif

let b = buffer_numbers[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple buffers are selected we open only the first one, not sure if this is the right/desired behaviour

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can delete multiple buffer at once? just like we open multiple files using tab in :Files or there's a different mechanism here?

@dav-dev
Copy link

dav-dev commented Apr 28, 2021

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 ?

@mracos
Copy link
Author

mracos commented Apr 30, 2021

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 mracos force-pushed the mf-add-delete-option-to-buffers-command branch from a54fcbc to 6609189 Compare April 30, 2021 16:13
By pressing the CTRL-D keybinding
@mracos mracos force-pushed the mf-add-delete-option-to-buffers-command branch from 6609189 to 58fbfd3 Compare May 25, 2021 18:01
@rameshsanth
Copy link

rameshsanth commented Aug 3, 2021

@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

@perrupa
Copy link

perrupa commented Oct 19, 2021

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. 👌

@Limero
Copy link

Limero commented Jul 26, 2022

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

@miklhh
Copy link

miklhh commented Feb 28, 2023

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

@miklhh
Copy link

miklhh commented Mar 1, 2023

@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.

@doronbehar
Copy link
Contributor

@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!

@mracos
Copy link
Author

mracos commented Mar 6, 2023

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

connermcd added a commit to connermcd/fzf.vim that referenced this pull request Mar 29, 2023
connermcd added a commit to connermcd/fzf.vim that referenced this pull request Mar 29, 2023
This commit extends the :Buffers command with --multi to allow <Tab>
selection of multiple buffers that can then be deleted with CTRL-D or
opened into separate tabs/splits/vertical splits with
CTRL-T/CTRL-X/CTRL-V.
@connermcd
Copy link

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.

@doronbehar
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants