[fzf#vim#buffers] Allow users to pass a custom list of buffer numbers

Introducing a global configuration variable may seem easier but this
method is more flexible in that it allows you to define multiple
variations of the command without having to repeatedly setting and
unsetting the variable.

  function! MyBuffers()
    return filter(range(1, bufnr('$')), 'buflisted(v:val) && getbufvar(v:val, "&filetype") != "qf"')
  endfunction

  command! -bar -bang Buffers call fzf#vim#buffers(MyBuffers(), fzf#vim#with_preview({'placeholder': '{1}'}), <bang>0)

Close #831
Close #393
This commit is contained in:
Junegunn Choi
2023-10-14 23:57:35 +09:00
parent f3b82091a6
commit d1016dbd7c
3 changed files with 23 additions and 17 deletions

View File

@@ -807,10 +807,16 @@ function! fzf#vim#_buflisted_sorted()
return sort(s:buflisted(), 's:sort_buffers')
endfunction
" [query (string)], [bufnrs (list)], [spec (dict)], [fullscreen (bool)]
function! fzf#vim#buffers(...)
let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000]
let sorted = fzf#vim#_buflisted_sorted()
if len(args) && type(args[0]) == s:TYPE.list
let [buffers; args] = args
else
let buffers = s:buflisted()
endif
let sorted = sort(buffers, 's:sort_buffers')
let header_lines = '--header-lines=' . (bufnr('') == get(sorted, 0, 0) ? 1 : 0)
let tabstop = len(max(sorted)) >= 4 ? 9 : 8
return s:fzf('buffers', {