Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In ivy mode, commands that have input as prefix of their name should be presented first #265

rudi opened this issue Oct 16, 2015 · 3 comments


Copy link

rudi commented Oct 16, 2015

Using standard completion or icomplete-mode, M-x man RET executes the man command. When turning on ivy-mode, man is somewhere on the 8th screen. (Entering ^man on the prompt helps a bit, but once the library is loaded, various commands starting with uppercase "Man-" prefix are presented before man even in that case.) Other commands have the same problem, e.g., gnus is presented after diary-from-outlook-gnus when typing M-x gnus.

Would it be possible to sort the list of completions so that prefix matches of the input string come before other possibilities?

Copy link

abo-abo commented Oct 16, 2015

You should use a dedicated command for M-x:

(global-set-key (kbd "M-x") 'counsel-M-x)

It already comes with ^ as the initial input, so the issue disappears.

Alternatively, you can rely on flx to do the prefix sorting:

(setq ivy-re-builders-alist
      '((t . ivy--regex-fuzzy)))

Copy link

abo-abo commented Nov 13, 2015


(setq ivy-prefix-sort t)

to turn on the new behavior. It's off by default, because it can be potentially more time-consuming.
If it turns out to be fast enough, ivy-prefix-sort will be made on by default.

abo-abo added a commit that referenced this issue Nov 13, 2015
* ivy.el (ivy-prefix-sort): Remove defcustom.
(ivy--filter): Forward sorting of matched candidates to `ivy--sort'.
(ivy-sort-matches-functions-alist): New defcustom.
(ivy--sort): New defun.

Fixes #269
Fixes #265
Copy link

abo-abo commented Nov 13, 2015

I reconsidered the customization interface because of #269. You should now use:

(setq ivy-sort-matches-functions-alist
      '((t . ivy--prefix-sort)))

to turn on the prefix sorting. It's more flexible, since it allows to turn on extra sorting only for some commands if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants