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

[Question] Do not automatically select the first option from the list #3062

Open
Rid1FZ opened this issue Dec 29, 2024 · 5 comments
Open

[Question] Do not automatically select the first option from the list #3062

Rid1FZ opened this issue Dec 29, 2024 · 5 comments

Comments

@Rid1FZ
Copy link

Rid1FZ commented Dec 29, 2024

How can I make ivy not to select the first option automatically when opened? Now, by default, it selects the first option which can be triggerd by TAB or RET key.

@basil-conto
Copy link
Collaborator

Am I correct in understanding that, at the beginning of any given Ivy completion session, you want none of the potential candidates highlighted?

If so, I don't think Ivy currently supports that, though I could be wrong.

The closest way to emulate it that I can think of is to set ivy-use-selectable-prompt non-nil, and a default ivy-hooks-alist entry that calls (ivy-set-index -1), but that won't work in all cases.

Could you please describe in more details the kind of workflow you imagined?

@Rid1FZ
Copy link
Author

Rid1FZ commented Jan 9, 2025

@basil-conto In neovim, I use TAB to cycle through the options, and RET to confirm any option, but with a condition. If I manually do not select any option using TAB, RET will insert whatever I wrote. Else it will confirm highlighted option. There are some ways I can achive this, but the best way I found is no option highlighted automatically. I have to manually highlight any option to confirm that using RET. So by default, RET will have nothing to insert, and it will fallback to inserting the text I wrote. This method is supported in most of the completion engines in Neovim also in emacs company-mode. I just want it in ivy.

@basil-conto
Copy link
Collaborator

Right, AFAIK there's no OOTB way to achieve exactly this behaviour in Ivy.

For example, one could use C-M-j (ivy-immediate-done) to accept what one wrote rather than the currently selected candidate, and one could leverage the require-match argument for confirmation logic, but there's no general way to differentiate between exiting with the default candidate vs exiting with no candidate selected (where input may or may not be empty).

Patches welcome.

@Rid1FZ
Copy link
Author

Rid1FZ commented Jan 9, 2025

@basil-conto sorry, but is there a way to call (ivy-set-index -1) everytime user inserts/deletes a character? If it is possible, I will be able to assign the following function to RET key, and it will do the trick

(defun custom/ivy-done()
    (interactive)
    (if (= ivy--index -1)
        (ivy-immediate-done)
      (ivy-alt-done)))

@basil-conto
Copy link
Collaborator

is there a way to call (ivy-set-index -1) everytime user inserts/deletes a character?

I haven't tested this, but some possibilities include:

  • ivy-index-functions-alist
  • ivy-update-fns-alist
  • post-command-hook

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

No branches or pull requests

2 participants