I want to add keybinding to Dired mode for entering directory, and ONLY directory. By default enter key is bound to function dired-find-file. The problem with it is that its or opening new dired buffer if it is directory under cursor, or open file for editing if its file.

So I added two shortcuts for going to parent directory and stepping in directory under cursor this way: (define-key dired-mode-map (kbd "<left>") 'dired-jump) (define-key dired-mode-map (kbd "<right>") 'dired-find-file)

As you may guess the problem is in last - dired-find-file will work on non-directories too, and I want it not to do anything. So my question - is there a specific function for stepping in directory under cursor or, if not - is there a way to check if there is directory under cursor in dired mode to construct my own function? Thx.

  • Do you really want each directory in a different buffer? I use the dired i command, which gives an error if it's not a directory and expands it in the current buffer if it is. If that's not what you wanted, looking at the source for it might be a good start.
    – MAP
    Jun 29, 2016 at 23:10

1 Answer 1


That's an easy one to write:

(defun dired-find-directory ()
  "A `dired-find-file' which only works on directories."
  (let ((find-file-run-dired t)
        (file (dired-get-file-for-visit)))
    (when (file-directory-p file)
      (find-file file))))
  • Thats exactly what I was looking for, thanks a lot!
    – sandric
    Jul 1, 2016 at 14:29

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.