Variable: dired-dwim-target

dired-dwim-target is a customizable variable defined in dired.el.gz.

Value

nil

Documentation

If non-nil, Dired tries to guess a default target directory.

This means: if there is a Dired buffer displayed in some window, use its current directory, instead of this Dired buffer's current directory.

You can customize it to prefer either the next window with a Dired buffer, or the most recently used window with a Dired buffer, or to use any other function. When the value is a function, it will be called with no arguments and is expected to return a list of directories which will be used as defaults (i.e. default target and "future history")
(though, dired-dwim-target-defaults might modify it a bit).
The value t prefers the next windows on the same frame.

The target is used in the prompt for file copy, rename etc.

View in manual

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/dired.el.gz
(defcustom dired-dwim-target nil
  "If non-nil, Dired tries to guess a default target directory.
This means: if there is a Dired buffer displayed in some window,
use its current directory, instead of this Dired buffer's
current directory.

You can customize it to prefer either the next window with a Dired buffer,
or the most recently used window with a Dired buffer, or to use any other
function.  When the value is a function, it will be called with no
arguments and is expected to return a list of directories which will
be used as defaults (i.e. default target and \"future history\")
\(though, `dired-dwim-target-defaults' might modify it a bit).
The value t prefers the next windows on the same frame.

The target is used in the prompt for file copy, rename etc."
  :type '(choice
          (const :tag "No guess" nil)
          (function-item :tag "Prefer next windows on the same frame"
                         dired-dwim-target-next)
          (function-item :tag "Prefer next windows on visible frames"
                         dired-dwim-target-next-visible)
          (function-item :tag "Prefer most recently used windows"
                         dired-dwim-target-recent)
          (function :tag "Custom function")
          (other :tag "Try to guess" t))
  :group 'dired)