10

My project has these files:

$ find . -type f -and -name 'peop*'
./app/assets/stylesheets/admin/sections/people.css.sass
./app/controllers/admin/people_controller.rb

As I got tired of typing :e app/assets/stylesheets/admin/sections/people.css.sass, I thought that ctrlp might be a good way to save some typing. However, I can't get it to match files in what I consider to be a sane way.

First, I use <C-p> and type peop, and that gives me these results ("first" match is at the bottom):

> app/models/attribute_group.rb
> app/models/contract_template.rb
> app/policies/contract_policy.rb
> app/uploaders/photo_uploader.rb
> app/policies/invoice_policy.rb
> app/views/layouts/pdf.pdf.haml
> app/uploaders/logo_uploader.rb
> app/models/property_object.rb
> app/policies/person_policy.rb
> app/policies/photo_policy.rb    
>>> peop_

These results are horrible. Neither files with peop in them are there. Even when I expand it to people:

> app/policies/contract_template_policy.rb
> app/models/concerns/exportable.rb
> app/models/contract_template.rb
> app/uploaders/photo_uploader.rb
> app/uploaders/logo_uploader.rb
> app/views/admin/people/_show.html.haml
> app/views/admin/people/_form.html.haml
> app/views/admin/people/show.html.haml
> app/views/admin/people/edit.html.haml
> app/views/admin/people/new.html.haml 
>>> people_

It doesn't list either of them (!)

I went through :help ctrlp-options, and found a single option that improves things somewhat:

Set this to 1 to set searching by filename (as opposed to full path) as the
default:
  let g:ctrlp_by_filename = 0

Can be toggled on/off by pressing <c-d> inside the prompt.

After setting this, I get the following results on peop:

> app/controllers/admin/organisation_people_controller.rb
> app/assets/stylesheets/admin/sections/people.css.sass
> doc/formulieren/opdrachtverlening-woningbeheer.pdf
> doc/formulieren/hulptabellen-object-unit-soort.pdf
> doc/formulieren/brandpreventievoorjongeren.pdf
> app/policies/organisation_person_policy.rb
> doc/prototype-admin/prototype/inspectiemodule_apparaten.html
> app/policies/property_object_policy.rb
> app/policies/person_policy.rb
> app/controllers/admin/people_controller.rb
>d> peop_

Okay, so this is slightly better, I get at least one of the expected files at the first result, and the other one as the 9th. It still conciders hulptabellen-object-unit-soort.pdf to be a better match than people.css.sass though (!)

Typing people finally gives me the 2 expected files as the first 2:

> app/controllers/admin/organisation_people_controller.rb
> app/assets/stylesheets/admin/sections/people.css.sass
> app/controllers/admin/people_controller.rb
>>> people_

How can I make this matching better? I don't mind "fuzzy matching", but it should not be so fuzzy it matches everything and everyone... In this case, I would expect typing <c-P>peop to have app/assets/stylesheets/admin/sections/people.css.sass as either the 1st or 2nd match.

7

A similar question was just asked on the Vim reddit here. I started using ctrlp-cmatcher myself quite awhile ago which I find to be much more intelligent at matching the right file. Note that it does require a compiled component. Otherwise you'll have to try some of the approaches in the article.

4

CtrlP has a few different modes, Ctrl-R and Ctrl-D. Ctrl-R uses your input as raw Regex, meaning you'll only find matches with people in it explicitly. Ctrl-D matches only the filename, ignoring the path.

I believe the default CtrlP functionality is just joining .* to every character as a raw character, so a period is treated as a period. If you knew in advance the file was at least 2 directories deep, you could do //people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.