ctrlp.vim
ctrlp.vim copied to clipboard
giving preference to exact matches
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.
Same problem here. In large projects CtrlP is useless because of the above problem.
:+1: This bugs me too!
+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
Completely agree with this !
I think https://github.com/ctrlpvim/ctrlp.vim will by default give preferences to exact match
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? :(
In any case, ctrlpvim/ctrlp.vim behaves no differently for me
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' }
+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.
:+1: pretty annoying :-(
I was annoyed by that as well. Try fzf, works pretty nicely. It also works with ag
, if you do it like this.
+1
I was annoyed by this as well but discovered after hitting 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