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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -688,18 +688,30 @@ function! s:bufopen(lines)
if len(a:lines) < 2
return
endif
let b = matchstr(a:lines[1], '\[\zs[0-9]*\ze\]')
if empty(a:lines[0]) && get(g:, 'fzf_buffers_jump')

let key = a:lines[0]
let buffer_numbers = map(a:lines[1:], {_idx, bufline -> matchstr(bufline, '\[\zs[0-9]*\ze\]')})

if key == 'ctrl-d'
execute 'bdelete' join(buffer_numbers, ' ')
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?


if empty(key) && get(g:, 'fzf_buffers_jump')
let [t, w] = s:find_open_window(b)
if t
call s:jump(t, w)
return
endif
endif
let cmd = s:action_for(a:lines[0])

let cmd = s:action_for(key)
if !empty(cmd)
execute 'silent' cmd
endif

execute 'buffer' b
endfunction

Expand Down Expand Up @@ -729,13 +741,17 @@ endfunction
function! fzf#vim#buffers(...)
let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000]

let expected_keys = 'ctrl-d,' . join(keys(s:default_action), ',')
let ctrl_d_header = ["\t\t:: Press ".s:magenta('CTRL-D', 'Special')." to delete"]
let sorted = fzf#vim#_buflisted_sorted()
let header_lines = '--header-lines=' . (bufnr('') == get(sorted, 0, 0) ? 1 : 0)
let header_lines = '--header-lines=' . (bufnr('') == get(sorted, 0, 0) ? 2 : 1)
let tabstop = len(max(sorted)) >= 4 ? 9 : 8

return s:fzf('buffers', {
\ 'source': map(sorted, 'fzf#vim#_format_buffer(v:val)'),
\ 'source': ctrl_d_header + map(sorted, 'fzf#vim#_format_buffer(v:val)'),
\ 'sink*': s:function('s:bufopen'),
\ 'options': ['+m', '-x', '--tiebreak=index', header_lines, '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}-/2', '--tabstop', tabstop]
\ 'options': ['+m', '-x', '--tiebreak=index', header_lines, '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}-/2', '--tabstop', tabstop, '-m', '--expect', expected_keys]
\}, args)
endfunction

Expand Down