4

I use counsel-file-jump to search files recursively. I would like to open the directory that contains a particular file candidate. I can execute counsel-dired after I open the file, which allows me to open the directory which contains the file. I would like to jump straight to this directory without first opening the file.

How can I achieve this?

  • 3
    AFAIK, counsel-file-jump does not currently support this OOTB. For now, you could M-i (ivy-insert-current) to yank the selected candidate into the search string, edit the yanked string to remove the non-directory part, and then C-M-j (ivy-immediate-done) to visit the resulting directory. However, I suggest you submit a feature request at github.com/abo-abo/swiper/issues to add an action to counsel-file-jump to do this automatically. – Basil May 9 at 13:55
6

You can create a new Ivy action that opens the directory of a file name selection. It can be done with:

(defun my/ivy-open-dir-action (x)
  (interactive)
  (dired (or (file-name-directory x)
             default-directory)))

(ivy-add-actions
 #'counsel-file-jump
 '(("d" my/ivy-open-dir-action "open in dired")))

To invoke it, you can search normally and then M-o d to fire this action. In case you want to know more about Ivy actions, I recommend you take a look in the Ivy docs, specifically under (ivy) Actions.

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.