1

When Dired is open, It would be cool if I could press one key and go up in the directory tree, to the parent directory. I have this feature in vim with netrw and I'd like to recreate it.

I'd like to press - and I go back (or up in the dir tree)

I'm not sure where I should get started with figuring it out.

Is it possible?

1 Answer 1

2

In Dired, by default ^ (command dired-up-directory) does what you ask.

You can find this by using C-h m (command describe-mode) in a Dired buffer. After a general description of the mode it lists the keys bound locally in the mode, including ^.

If you want to also bind - to the command then use this:

(define-key dired-mode-map (kbd "-") 'dired-up-directory

However, - is bound in Dired to negative-argument, as an abbreviation for doing C-u -. So to act on the previous 3 lines you can just use - 3 instead of C-u - 3. You might want to keep that behavior...


If you use library Dired+ (code) then ^ is bound to command diredp-up-directory, which is an improved version of dired-up-directory. From the doc string:

With a prefix arg, Dired the parent directory in another window.

On MS Windows, if you are already at the root directory, invoke diredp-w32-drives to visit a navigable list of Windows drives.

4
  • My biggest challenge with emacs is finding out the name of functions that do things. Thanks Drew!
    – Vinn
    Sep 30, 2022 at 19:04
  • 1
    @Vinn Start M-x then enter dired- and press TAB to see a list of commands whose name start with dired-. Even if you don't guess the “up” part of the name, you can at least guess the “directory” part of the name and enter M-x dired-directory then press TAB twice and out of the box this only offers three functions (“clean”, “create”, “up”) out of which “up” is the obvious candidate. Alternatively, use a command description search: C-u C-h d dired parent RET finds just dired-up-directory. Sep 30, 2022 at 19:13
  • This is really good advice. I will test that next time when I have a problem!
    – Vinn
    Sep 30, 2022 at 19:14
  • 1
    My advice is to always start with C-h m, to get info about the current context (major and minor modes). And there's C-x b. ;-)
    – Drew
    Sep 30, 2022 at 20:47

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.