3

I really like how ido-find-file, if it can’t find a file matching your string (and you’ve let it idle for like a second), will search your whole home directory for files matching that string, and then your whole directory tree. (At least, I think that’s how it works. I’ve never been able to untangle the code.) I’m hoping there’s an equivalent to that functionality in ivy/counsel, like for counsel-find-file, but I haven’t found it.

This is similar to this question: What's the equivalent of `helm-find` in ivy/counsel? I want to find files **recursively** … but not exactly. I think? I’ve never used helm. I’m glad to know of counsel-file-jump, but it’s too slow up front for what I need since it doesn’t do that gradual ratcheting that ido-find-file does.

1
  • 1
    If you don't manage to get equivalent functionality for ivy/counsel, there's absolutely nothing wrong with using ido for finding files and ivy/counsel for everything else.
    – Omar
    Commented Feb 19, 2020 at 0:34

1 Answer 1

0

Although the following is not triggered automatically it might be what you need:

(define-key ivy-minibuffer-map (kbd "'") 'my-ivy-switch-file-search)

(defun my-ivy-switch-file-search ()
  "Switch diffrent file search, preserving current input."
  (interactive)
  (let ((input (ivy--input))
        (dir (or ivy--directory default-directory)))
    (if (and (locate-dominating-file "." ".git")
             (not (eq (ivy-state-caller ivy-last) 'counsel-git)))
        (ivy-quit-and-run
         (let ((default-directory dir))
           (counsel-git input)))
      (if (equal ivy--directory "/")
          (ivy-quit-and-run
           (let ((default-directory dir))
             (counsel-locate input)))
        (ivy-quit-and-run
         (let ((default-directory dir))
           (counsel-file-jump input)))))))

This will let you choose a different file search using '.

4
  • Thanks! That’s pretty cool. I guess my next question would be how to make it automatic (with a delay)… any takers? Commented Jan 25, 2019 at 5:35
  • Hm, I guess this would require some work. What if you make a typo and don't correct it fast enough?
    – clemera
    Commented Jan 25, 2019 at 14:06
  • I guess I’d change the search string and then, after another delay, it would run the search again. Also, any pointers or information on how to extend the behavior of ivy/counsel would be welcome, my Elisp skills are getting respectable but these completion frameworks melt my brain ^_^; Thanks! Commented Jan 25, 2019 at 20:33
  • With the approach of my answer ivy quits and restarts. So when you would make a typo and don't really want to search with counsel-file-jump it would be necessary to quit ivy again and go back to the previous counsel-find-file. I don't know a good solution which behaves like your described ido behavior. Maybe consider submitting a feature request on the project page.
    – clemera
    Commented Jan 26, 2019 at 1:57

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.