0

Sometimes I do a search with swiper and navigate to a location in the code that seems like what I was searching for, only to find it wasn't. This is more common with a symbol name that is a little too generic.

I'd like to simply restart the search, but I have to type the full symbol again.

I could copy/yank the symbol, which would be fine, but even that could be automated, as in: "search for thing under point." I'd probably want that too, but first thing: I'd just like to repeat the previous search.

How can I do that without having to re-type the criteria? Or have swiper remember the last search?

4
  • 1
    Not sure if I follow you, are you meaning M-p ?
    – Muihlinn
    Aug 17 '20 at 17:03
  • Actually this will work. I was expecting the call to launch swiper and pre-populate the search. This works just as well: start-search then iterate through the search history with M-p.
    – lucidquiet
    Aug 17 '20 at 17:27
  • C-s after calling swiper - without input - will bring the last item in history too.
    – Muihlinn
    Aug 17 '20 at 19:42
  • swiper is an isearch replacement and works on the same model.
    – NickD
    Aug 18 '20 at 2:00
1

C-s after calling swiper will bring up the last search. M-p will iterate back through the search history. M-n will do the same the other way.

If you followed the installation instructions and used the proposed bindings, swiper-isearch is bound to C-s, so C-s C-s will do what you want with zero effort.

As @NickD pointed, Swiper is an isearch replacement, most you did using isearch, will work with swiper.

On the secondary question, searching for "thing at point", you can choose between:

  • using C-s M-j (assuming that C-s calls swiper), it'll insert the current subword in the minibuffer.

  • writing a custom function which is basically a matter of using thing-at-point over what you find more useful, putting it into the completion list then funcall swiper or the other commands.

    Swiper's author provided the example code here

Finally, reading the docs always worth the time spent doing it, usually saves unnecesary headaches.

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.