Skip to content

Instantly share code, notes, and snippets.

@maguroguma
Created October 16, 2022 12:33
Show Gist options
  • Save maguroguma/be13f4d16afab52bf3b26a4f10c4412b to your computer and use it in GitHub Desktop.
Save maguroguma/be13f4d16afab52bf3b26a4f10c4412b to your computer and use it in GitHub Desktop.
" deletes buffers by fzf
" ref: https://github.com/junegunn/fzf.vim/pull/733#issuecomment-559720813
function! s:list_buffers_customized()
redir => list
silent ls
redir END
let l:res = []
let l:raw_lines = split(list, "\n")
for l:raw_line in raw_lines
let l:elems = split(l:raw_line)
let l:custom_line = l:elems[0] . "\t" . substitute(l:elems[2], '"', "", "g")
call add(l:res, l:custom_line)
endfor
return l:res
endfunction
function! s:delete_buffers(lines)
execute 'bwipeout' join(map(a:lines, {_, line -> split(line)[0]}))
endfunction
command! BD call fzf#run(fzf#wrap({
\ 'source': s:list_buffers_customized(),
\ 'sink*': { lines -> s:delete_buffers(lines) },
\ 'options': '--multi --reverse --bind ctrl-a:select-all+accept --prompt "delete(close) buffers> "'
\ }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment