fzf.vim
fzf.vim copied to clipboard
Prioritize Open Buffers when using :Files?
- [x] I have fzf 0.30.0 or above
- [x] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
- [x] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
- [x] I have read through the manual page of fzf (
man fzf
) - [x] I have searched through the existing issues
Hello,
Is it possible to prioritize files that are already open in buffers when using :Files
? I often find myself jumping between the same files a lot, so I think it would be a more of an efficient workflow if already-opened files appeared at the start of the list.
I am aware that there is another command :Buffers
for viewing only open buffers - however I think it would be preferable not to have two different keybindings, because then you have to try and remember if you had already opened a buffer before trying either :Buffers
or :Files
.
Many Thanks
Seb
I have the same problem
I'm not all that familiar with vimscript but I think I have managed to get roughly what I want by adapting this example from the main FZF repo.
Here's my code:
" FZF Files and Buffers in a single list using Ctrl + P
nnoremap <C-P> :FzfFilesAndBuffers<CR>
command! FzfFilesAndBuffers call fzf#run({
\ 'source': reverse(s:all_files()),
\ 'sink': 'edit',
\ 'down': '40%',
\ })
function! s:all_files()
return extend(
\ reverse(
\ filter(
\ split(
\ system('fd --type file --type symlink --hidden --no-ignore-vcs --exclude vendor --exclude node_modules --exclude .git'),
\ "\n"
\ ),
\ '!empty(v:val)'
\ ),
\ ),
\ map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), 'bufname(v:val)'))
endfunction
The system()
call should be altered to meet the specific needs of the user.
It's not perfect, for instance if a buffer is open it's corresponding file will also show in the list, causing a duplicate, and also the currently opened file will be the first item in the list and can be selected, which isn't very useful. But generally I think it does the job.