Vim FZF: sort initial results by file date

I have this vim mapping:

nnoremap <silent> <leader><space> :Files<CR>

      

Can I change the sorting of the original list?
It would be nice to see the recently changed files.
When I start searching, the normal sort from fzf is fine.

+3


source to share


1 answer


I don't know the easy way, no.

But you can just write a function that will get a list of files sorted by date (note that this is all untested):

let l:filelist = split(system(find . -type f -printf '%T@ %p\n' | 
                              \ sort -k 1 -n | sed 's/^[^ ]* //'), 'n')

      

There are several other commands that can be used, depending on your environment. But here the first problems arise. This command lists all of your files in your directory. Respect your gitignore or any other work. Also, it is much slower than fzf!

Once you have the list, you can simply use fzf again:



call fzf#run({'source': l:filelist, 'sink': 'e', 'down': '40%'})

      

So I think this might work great for small projects, but if you have a larger project this is a way to slow things down, also if you are using something like rails that rebuilds your assets quite often you will have to filter the result.


Update:

As mentioned in the comment from r03, you can also edit the variable FZF_DEFAULT_COMMAND

if you want to use this globaly. There is no need to pass it to vimscript.

+3


source







All Articles