junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.25k stars 2.38k forks source link

Ability to control search order (or have `--nth` respect it) #3854

Closed ibhagwan closed 3 months ago

ibhagwan commented 3 months ago

Checklist

Output of fzf --version

0.53

OS

Shell

Problem / Steps to reproduce

Hi again @junegunn.

Ref: #1440

Following on the discussion above, I’d like to consult your opinion about revisiting this.

Use case:

With fzf-lua the users can specify formatter = path.filename_first which transforms the path to a VSCode-like style of file.ext path/to/file, however, as you can imagine this affects the search order so now users can’t search for the path logically (or paste paths) as they have to first write the file and then the folder (or use space in between) - each resulting in additional mental overhead.

Consider I wanted to search for my path/to/fzf/setup.lua (with the filename first formatter):

Using space between the file/folder IMG_2157 Without space there would be no results IMG_2158

Tried rearranging the text/fields with both --with-nth and --nth but couldn’t find a way to make it work.

junegunn commented 3 months ago

I still don't think it's the right thing to do. fzf is a line filter, and it shouldn't be matching against what's not directly shown on the line. Implementing it properly will add additional complexity (highlighting, horizontal scrolling, scoring, etc) so I don't think it's worth it.

You could maybe repeat the name part again after the directory, maybe in a dimmer color, to allow searching against it.

file.txt    foo/bar/file.txt

And then --nth ..,2 to allow anchors on both. ^file.txt, ^foo, etc.

ibhagwan commented 3 months ago

I still don't think it's the right thing to do. fzf is a line filter, and it shouldn't be matching against what's not directly shown on the line. Implementing it properly will add additional complexity (highlighting, horizontal scrolling, scoring, etc) so I don't think it's worth it.

You could maybe repeat the name part again after the directory, maybe in a dimmer color, to allow searching against it.

file.txt    foo/bar/file.txt

And then --nth ..,2 to allow anchors on both. ^file.txt, ^foo, etc.

Ty @junegunn for the prompt response and suggestion.

Although I could repeat the filename, that changes the display (undesirable) and probably also has some other unintended consequences for matching that I cannot yet foresee.