6

How to get swiper to search for the last searched term , much like (default) isearch-forward does when pressing C-s twice?

1
  • 3
    Actually this is by default works the way you want... Just press C-s
    – Maxim Kim
    Commented Mar 21, 2018 at 11:59

2 Answers 2

10

When you invoke swiper press M-p to search for previously searched thing.

M-n will let you search for the word under cursor.

C-s will search for the next occurence.

UPD, thx @Basil

After you invoke the swiper press C-s to search for a previously searched string. Press C-s again to go to the next occurrence.

2
  • 2
    You should mention that C-s (ivy-next-line-or-history) will either select the previous history element on empty input or move N matches forward, as you allude to in your comment.
    – Basil
    Commented Mar 21, 2018 at 12:50
  • 1
    @yPhil you You should make it clear that you're just looking for a way to get the last searched term, under any key and not just that which you used to invoke swiper.
    – mkcms
    Commented Mar 21, 2018 at 13:15
0

For what is worth, here is my swiper config right now.

  • I can search the rightmost expression(s) by pressing repeatedly C-f ;
  • I can search the "last term" by pressing C-f C-s (thanks @maxim-kim) and ;
  • I can access both recent files and opened buffers by pressing f4 :)
  • And I still have C-s bound to isearch for macros and such.

.

(use-package ivy-hydra
  :ensure t)

(use-package swiper
  :ensure try
  :bind
  (([f4] . ivy-switch-buffer)
   ([(control c) (f)] . counsel-ag)
   ([(control c) (g)] . counsel-git)
   ([(control c) (j)] . counsel-git-grep)
   ([(control c) (l)] . counsel-locate)
   ([(control d)] . swiper-ag)
   ([(control f)] . swiper)
   ([(control h) (control f)] . counsel-describe-function)
   ([(control h) (control v)] . counsel-describe-variable)
   ([(control o)] . counsel-find-file)
   ([(control shift o)] . counsel-recentf)
   ([f9] . counsel-rhythmbox)
   :map ivy-minibuffer-map
   ([(control f)] . ivy-yank-word)
   :map read-expression-map
   ([(control r)] . counsel-expression-history))
  :config
  (progn
    (define-key
      ivy-switch-buffer-map
      [(control w)]
      (lambda ()
        (interactive)
        (ivy-set-action 'kill-buffer)
        (ivy-done))))
  :init
  (setq  ivy-use-virtual-buffers t
         ivy-ignore-buffers '("\\` " "\\`\\*")
         ivy-display-style 'fancy
         ivy-count-format "(%d/%d) "
         ivy-initial-inputs-alist nil
         ivy-extra-directories nil))

(use-package try
  :ensure t)

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.