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

#1239 Add ability to bdelete buffers with CTRL-D from :Buffers command #1465

Open
wants to merge 2 commits 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
40 changes: 27 additions & 13 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -739,19 +739,32 @@ 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 [t, w] = s:find_open_window(b)
if t
call s:jump(t, w)
return

for idx in range(1, len(a:lines) - 1)
let b = matchstr(a:lines[idx], '\[\zs[0-9]*\ze\]')

if a:lines[0] == 'ctrl-d'
execute 'silent bdelete' b
if len(a:lines) == 2
call fzf#vim#buffers()
endif
continue
endif
endif
let cmd = s:action_for(a:lines[0])
if !empty(cmd)
execute 'silent' cmd
endif
execute 'buffer' b

if empty(a:lines[0]) && 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])
if !empty(cmd)
execute 'silent' cmd
endif
execute 'buffer' b
endfor
endfunction

function! fzf#vim#_format_buffer(b)
Expand Down Expand Up @@ -783,10 +796,11 @@ function! fzf#vim#buffers(...)
let sorted = fzf#vim#_buflisted_sorted()
let header_lines = '--header-lines=' . (bufnr('') == get(sorted, 0, 0) ? 1 : 0)
let tabstop = len(max(sorted)) >= 4 ? 9 : 8
let expect_keys = join(keys(get(g:, 'fzf_action', s:default_action)), ',')
return s:fzf('buffers', {
\ 'source': 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': ['--multi', '-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, '--header', ':: Press '.s:magenta('CTRL-D', 'Special').' to delete buffer', '--expect', 'ctrl-d,'.expect_keys]
\}, args)
endfunction

Expand Down