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, 2019 at 13:55

1 Answer 1


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)
  (dired (or (file-name-directory x)

 '(("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.

  • @Basil this seems to be a useful feature. Could you (or someone else) PR in the swiper repo with this?
    – andrej
    May 10, 2019 at 9:49
  • 1
    @andrej If no-one beats me to it, sure.
    – Basil
    May 10, 2019 at 9:53
  • Here it is: github.com/abo-abo/swiper/pull/2057 May 10, 2019 at 15:56

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.