From d1016dbd7cec2d2a3bb5863776c84b4034e4b85e Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 14 Oct 2023 23:57:35 +0900 Subject: [PATCH] [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}'}), 0) Close #831 Close #393 --- README.md | 20 ++++++++++---------- autoload/fzf/vim.vim | 8 +++++++- doc/fzf-vim.txt | 12 ++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8d16b56..6fc2d18 100644 --- a/README.md +++ b/README.md @@ -217,16 +217,16 @@ endfunction Each command in fzf.vim is backed by a Vim function. You can override a command or define a variation of it by calling its corresponding function. -| Command | Vim function | -| --- | --- | -| `Files` | `fzf#vim#files(dir, [spec dict], [fullscreen bool])` | -| `GFiles` | `fzf#vim#gitfiles(git_options, [spec dict], [fullscreen bool])` | -| `GFiles?` | `fzf#vim#gitfiles('?', [spec dict], [fullscreen bool])` | -| `Buffers` | `fzf#vim#buffers([spec dict], [fullscreen bool])` | -| `Colors` | `fzf#vim#colors([spec dict], [fullscreen bool])` | -| `Rg` | `fzf#vim#grep(command, [spec dict], [fullscreen bool])` | -| `RG` | `fzf#vim#grep2(command_prefix, query, [spec dict], [fullscreen bool])` | -| ... | ... | +| Command | Vim function | +| --- | --- | +| `Files` | `fzf#vim#files(dir, [spec dict], [fullscreen bool])` | +| `GFiles` | `fzf#vim#gitfiles(git_options, [spec dict], [fullscreen bool])` | +| `GFiles?` | `fzf#vim#gitfiles('?', [spec dict], [fullscreen bool])` | +| `Buffers` | `fzf#vim#buffers([query string], [bufnrs list], [spec dict], [fullscreen bool])` | +| `Colors` | `fzf#vim#colors([spec dict], [fullscreen bool])` | +| `Rg` | `fzf#vim#grep(command, [spec dict], [fullscreen bool])` | +| `RG` | `fzf#vim#grep2(command_prefix, query, [spec dict], [fullscreen bool])` | +| ... | ... | (We can see that the last two optional arguments of each function are identical. They are directly passed to `fzf#wrap` function. If you haven't diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 02fc3ae..e57b7fa 100755 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -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', { diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 71b2679..d2179d2 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -1,4 +1,4 @@ -fzf-vim.txt fzf-vim Last change: September 14 2023 +fzf-vim.txt fzf-vim Last change: October 14 2023 FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc* ============================================================================== @@ -291,18 +291,18 @@ Vim functions~ Each command in fzf.vim is backed by a Vim function. You can override a command or define a variation of it by calling its corresponding function. - ----------+----------------------------------------------------------------------- - Command | Vim function ~ - ----------+----------------------------------------------------------------------- + ----------+--------------------------------------------------------------------------------- + Command | Vim function ~ + ----------+--------------------------------------------------------------------------------- `Files` | `fzf#vim#files(dir, [spec dict], [fullscreen bool])` `GFiles` | `fzf#vim#gitfiles(git_options, [spec dict], [fullscreen bool])` `GFiles?` | `fzf#vim#gitfiles('?', [spec dict], [fullscreen bool])` - `Buffers` | `fzf#vim#buffers([spec dict], [fullscreen bool])` + `Buffers` | `fzf#vim#buffers([query string], [bufnrs list], [spec dict], [fullscreen bool])` `Colors` | `fzf#vim#colors([spec dict], [fullscreen bool])` `Rg` | `fzf#vim#grep(command, [spec dict], [fullscreen bool])` `RG` | `fzf#vim#grep2(command_prefix, query, [spec dict], [fullscreen bool])` ... | ... - ----------+----------------------------------------------------------------------- + ----------+--------------------------------------------------------------------------------- (We can see that the last two optional arguments of each function are identical. They are directly passed to `fzf#wrap` function. If you haven't