cpsm
cpsm copied to clipboard
Prioritize buffers and MRU in mixed mode
First off: cpsm does a fantastic job matching, so thank you! However, there is one thing I miss from CtrlP's default matcher.
When you launch the default CtrlP matcher in mixed mode (e.g. by putting let g:ctrlp_cmd = 'CtrlPMixed'
in .vimrc
) then CtrlP automatically searches open buffers and most-recently-used files as well as the general list-of-all-files that it collects. Importantly, the default matcher prioritizes these subsets aggressively, which means that while cpsm does a much better job matching in the general case, I find the default matcher slightly more efficient for frequently-used files.
As a particular case in point: I have a large ruby project with a file app/models/order.rb
which I access extremely frequently. So-much-so in fact that when I use the default matcher I don't even have to enter a query string at all; it is the first choice of the default 10. However, when I use cpsm I have to enter a few characters to access it. The default matcher is similarly more efficient in terms of number-of-characters for other files on my MRU list.
It would be great if CPSM could similarly prioritize MRUs when running in mixed mode.
Note: did a little more digging and wanted to clarify, this is not the same issue as solved by g:cpsm_match_empty_query
(or at least, that is not sufficient). Unsetting that will correctly display my MRUs before I enter any characters, but as soon as I enter a search my MRUs are ignored.
For example, the 2nd-10th MRU files are all only a few characters (usually < 4) away with the default matcher, where-as I have to type more with cpsm. I suppose the correct setting would be g:cpsm_prioritize_provided_order
or something like that, if it existed? I'm happy to try working on this with a few pointers, but my knowledge of Ctrl-P's matcher behaviour is pretty minimal right now.
CtrlP doesn't seem to actually provide information about which files are MRU and which are not, making handling the mixed mode a bit tricky. (I don't really know Vimscript, but it looks like the default matcher handles this problem by never reordering items, so MRU results stay at the top.) So I think an option like g:cpsm_prioritize_provided_order
is the only viable approach. (That said, it's probably better made part of a g:cpsm_mru
option that will also imply g:cpsm_match_empty_query
.) I'll look at doing this.
Not perfect, but at most g:ctrlp_mruf_max
entries will be MRUs, and the open buffers are easy enough to determine yourself by asking vim, so everything else is safe to re-order. My vimscript isn't bad, although Ctrl-P is pretty complex. If you have any specific questions I'll try to help.