Frage

I use a to dig down into dired. Using ^ to go back up is very unintuitive for me. I wanted to change it to something else, like b or r . How can I do that ? I couldn't get global-set-key to work for the same.

~Cheers! NJ

War es hilfreich?

Lösung

(define-key dired-mode-map [yourkey] 'dired-up-directory)

Instead of [yourkey], you can put names like [up], or "b" or "r", and this would only be in dired, note.

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

You could also do for instance Control up. Mind that in some situations it's easier to use [], so you'd replace [yourkey] with [C-up] (literally)

The idea is: define the key for the specific map, and bind it to your desired function.

EDIT: Just so you know how to do this kind of things yourself next time, know that for any mode you have the ending (-mode-map), so LaTeX-mode-map, emacs-lisp-mode-map, etc. Those you use with define-key.

If you want to know what function is attached to a binding, use C-h k (Control + h, then k) followed by your key, and it will show you what the function is called that can be bound to something else (make sure you'd call it when dired-mode is active though!).

Andere Tipps

Alternatively, if you use the elisp shown here:

C-hig (dired-x) Optional Installation Dired Jump RET

you can use C-xC-j to call dired-jump.

This is better than dired-up-directory because it works in file buffers as well (in which case it takes you to the parent directory in dired).

In all cases, the resulting dired buffer has point set to the file or directory from which you came.

For what it's worth, I use the following to go up directories using e.

(add-hook 'dired-mode-hook
          (lambda ()
            (define-key dired-mode-map (kbd "e")
              (lambda () (interactive) (find-alternate-file "..")))))

This is different than dired-up-directory in that it stays in the current buffer, instead of loading the parent directory in a new buffer. (I used to care about unused buffers.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top