ctrlp.vim icon indicating copy to clipboard operation
ctrlp.vim copied to clipboard

giving preference to exact matches

Open BrettRasmussen opened this issue 10 years ago • 13 comments

First let me say how much I love CtrlP. It's super useful and powerful. Thanks so much, Kien!

An enhancement that I would find very helpful would be that when I'm not in regex mode, the list would automatically sort with preference to exact matches. Exact matches of filename would come first, then exact matches anywhere in the path (if in path mode), then fuzzy (aka spread out) matches in the filename, then fuzzy matches anywhere in the path.

For example, in my current project, I'm looking for this file:

public/angular/estimate_form/views/main.html

But if I just type "main.html" (in path/non-regex mode), I get a whole bunch of files that spell out all of those letters over the whole path. Sometimes there's a "main" all together, sometimes there's an "html" all together, and sometimes those letters are all spread out:

app/views/estimates/rfqs/index.html.erb app/views/companies/settings.html.erb doc/app/classes/MainController.html doc/app/classes/FormattingHelper.html app/views/companies/index.html.erb app/views/equipment_items/_packing.html.erb app/views/companies/new.html.erb doc/app/classes/WideFormatSection.html app/views/main/index.html.erb app/views/main/about.html.erb doc/app/classes/InventoryItemLocation.html doc/app/classes/CompanyInformation.html

With my current results list height (25), I actually don't get my desired file at all.

Of course, if I switch to regex mode, or if I use filename mode or "filename;path", I get better results. But when I do any of those things, there are drawbacks that come from them. For example, in regex mode I have to be precise with spelling and in filename mode I can't do "a/c/main_controller". So I have to be switching between modes to get different benefits at different times.

If the results were already ordered in the way I described above, my file would probably be the very first one in the list, but I could still use paths if desired. I could set it to path/non-regex by default, and pretty much leave it there all the time without thinking about modes, which one to switch to, etc.

I could see this feature either as just the default way it works or as an option that could be set in vimrc.

Again, thanks for the great plugin, and thanks for considering my suggestion.

BrettRasmussen avatar Apr 24 '14 20:04 BrettRasmussen

Same problem here. In large projects CtrlP is useless because of the above problem.

jonwingfield avatar May 18 '14 21:05 jonwingfield

:+1: This bugs me too!

wejrowski avatar Dec 09 '14 18:12 wejrowski

+1 for this. IMO in any mode, when sorting the matching anything that is an exact match, especially a full exact match, should be sorted first. I have the same problem that I literally cannot open a file named Lead.java as it shows tons of other matches first

collinpeters avatar Jan 07 '15 15:01 collinpeters

Completely agree with this !

edi9999 avatar Jan 07 '15 16:01 edi9999

I think https://github.com/ctrlpvim/ctrlp.vim will by default give preferences to exact match

edi9999 avatar Jan 11 '15 12:01 edi9999

Hmm... I see that that is "an active fork of ctrl-p" and that this (the original) has not received a commit since 2013. Is this one considered dead? :(

collinpeters avatar Jan 12 '15 15:01 collinpeters

In any case, ctrlpvim/ctrlp.vim behaves no differently for me

collinpeters avatar Jan 12 '15 15:01 collinpeters

I tried https://github.com/FelikZ/ctrlp-py-matcher, and it now finds files (exact matches) that it previously didn't due to max results / list height. It is also a lot faster than increasing max results in ctrlp itself (I would've needed max results set to 128 with ctrlp to find my file, which was very slow). Enable it with:

let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }

edwintorok avatar Jan 25 '15 16:01 edwintorok

+1. It is pretty frustrating when your file finder does not show the file you typed in but does show a bunch of other files that are not the file you typed in.

still-dreaming-1 avatar Sep 30 '15 15:09 still-dreaming-1

:+1: pretty annoying :-(

elbajo avatar Apr 15 '16 17:04 elbajo

I was annoyed by that as well. Try fzf, works pretty nicely. It also works with ag, if you do it like this.

hpurmann avatar Dec 15 '16 14:12 hpurmann

+1

ohad-coursera avatar Mar 22 '17 17:03 ohad-coursera

I was annoyed by this as well but discovered after hitting just also hit . You'll see a r show up before the >> where the path you type appears. This is regex mode as mentioned above, seems to always work well for me. Im working in a repo with many thousands of files

jrutishauser avatar May 03 '17 19:05 jrutishauser