first post :)

I wondered if anyone knew a way to quickly change the dired path of of the additional dired (in a split window) to the current dired path? like the traditional OFM synchronize panes?

  • 2
    Welcome te emacs.stackexchange! Could you try to clarify your question? I'm not sure what you want to do.
    – JeanPierre
    Commented Mar 12, 2016 at 17:18
  • Hi and sorry for not being clear enough. i have 2 open dired windows. on the left i go to ~/Downloads. i want to have a function that when run, changes the right dired window to ~/Downloads. Does that make sense :)? thx! Z
    – zeltak
    Commented Mar 12, 2016 at 18:05
  • How about running the following function when you are in the left window?: M-x switch-to-buffer-other-window The default choice is always that the selected window be duplicated in the other window, although it is possible to select a different buffer to be displayed. If you are in the right window, you can run the function M-x switch-to-buffer. Arrow keys can be used in the mini-buffer to navigate possible choices, and there is is also tab completion available to suggest buffers matching the pattern presently in the mini-buffer.
    – lawlist
    Commented Mar 12, 2016 at 20:23

1 Answer 1


Not sure what you want to do with that. You can duplicate the buffer as suggested by @lawlist but then you have both windows displaying the same buffer.

If what you want is two separate dired buffers visiting the same directory (so that you can for example insert subdirs in one but not in the other) you can try this (this is quickly hacked code so it may have pitfalls but it seems to work).

(defun my/get-other-dired-directory ()
  "find name and directory of another dired buffer"
  (let ((bs (buffer-list))
        (here (current-buffer))
    (mapc (lambda (b) (unless (equal b here)
            (with-current-buffer b
              (if dired-directory
                  (setq this (cons (buffer-name) dired-directory)))))) bs)

(defun my/set-dired-dir-to-other ()
  "Change the dired directory to the one of another existing dired buffer"
  (let ((d (my/get-other-dired-directory)))
    (if d
          (setq dired-directory (cdr d)
                default-directory (cdr d))
          (rename-buffer (generate-new-buffer-name (car d))))
      (message "No other dired buffer"))))

(add-hook 'dired-mode-hook
      (lambda () (define-key dired-mode-map "z" #'my/set-dired-dir-to-other)))

What this code does is:

  1. find another dired buffer, get its name and directory,
  2. if found, change the directory of the current dired buffer, revert it (update content) and change its name (since the name is supposed to reflect the visited directory)

This is bound to the z key. As usual, put this in your init file.

  • thx so much! works as advertised ;-) Z.
    – zeltak
    Commented Mar 14, 2016 at 15:56
  • @zeltak: if this post solved your problem, please accept it.
    – Dan
    Commented Apr 12, 2016 at 0:25

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.