What I'm trying to do is have swiper-isearch resume the last search with the next element selected. The definition of next is the next element from where my cursor currently is.

You can read my original post below for how I was trying to use ivy-resume and ivy-next-line to achieve this, but it didn't work — it always resumed with the originally selected item still pre-selected.

Original Post:

How can I resume ivy with the next line selected?

I want to issue a keyboard command that resumes the last ivy listing, but instead of resuming at the line it left off at, I want to resume with the next line selected. I thought this would be simple enough if I did the following:

(defun my-ivy-resume-with-next-line ()
  "Resume the last completion and move current line down one."
(global-set-key (kbd "s-g") 'my-ivy-resume-with-next-line)

When I hit my keyboard command, ivy resumes right where it left off — it does not go to the next line. I'm not sure if there's some simple elisp functionality that I should know to fix this, or if ivy-resume is doing something weird. My guess would be that maybe ivy-next-line is being called in my main buffer and not the newly created minibuffer from ivy-resume. (If that's the case, then this is a question of how to call that command in the context of the minibuffer.)


I have also tried various variations of the following for the message body per suggestions in the comments:

(minibuffer-with-setup-hook (:append #'ivy-next-line) (ivy-resume))

Nothing seemed to work for me in my testing. However, after hearing they were working for others, I changed which function I was using to create the initial ivy listing and it worked. So the minibuffer hook is working for me when ivy has been called using counsel-find-file but not when using swiper-isearch. My primary use case for this is to resume swiper and go to the next found item, so I still need help.

Software versions

  • swiper 20200220.1026
  • ivy 20200220.1043
  • Emacs 26.3
  • MacOS 10.15.3
  • 1
    Does this answer your question? Call a function and insert text in minibuffer prompt
    – Basil
    Commented Feb 25, 2020 at 18:31
  • TL;DR: ivy-resume does not return until after the minibuffer completion session has ended, by which point it is too late to call ivy-next-line, which you want called as soon as the minibuffer completion session starts. You can achieve this via (minibuffer-with-setup-hook (:append #'ivy-next-line) (ivy-resume)).
    – Basil
    Commented Feb 25, 2020 at 18:35
  • I tried that and it didn't work. It just resumes on the same line it was on, just like my original script.
    – bfad
    Commented Feb 25, 2020 at 22:23
  • It works for me. Are you sure you have reevaluated my-ivy-resume-with-next-line with its new definition, e.g. using C-M-x? When facing an issue in general, please update your question with a detailed set of steps to reproduce the issue, explaining what you expect and what you actually get at each stage, and which version of Emacs you are using; otherwise it is difficult to guess what is going wrong. Thanks.
    – Basil
    Commented Feb 26, 2020 at 3:54
  • Updated my description. It turns out that my primary use-case (and what I was testing) didn't work, but other ivy completions did.
    – bfad
    Commented Feb 26, 2020 at 13:26

1 Answer 1


I found a solution to what I was trying to do:

(defun my-swiper-isearch-again ()
  "Start swiper-isearch with the last thing searched for."
  (swiper-isearch (car swiper-history)))
(global-set-key (kbd "s-g") 'my-swiper-isearch-again)

Now when I press "s-g" the previous swiper search starts again from the point of the current cursor and moves then to the next item that matches the search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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