Emacs: Dired Customization

By Xah Lee. Date: . Last updated: .

Tips for setting up emacs's dired.

Jump to File in Dired

In any open file, Alt+x dired-jumpCtrl+x Ctrl+j】 to jump to the directory of current buffer.

Before emacs 28, you need to load a lib.

Put this in your Emacs Init File:

(if (< emacs-major-version 28)
      ;; for dired-jump
      (require 'dired-x))

Allow Copy/Delete Directory

You can copy or delete a dir, including all subdirectories.

Put this in your Emacs Init File:

;; allow dired to delete or copy dir
;; 'top means ask every time
;; 'always means no asking
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes top)

Smart Suggest Target Dir

When you do copy files, emacs will prompt you for a target dir. You can make emacs automatically suggest the target dir on the split pane. [see Emacs: Split Windows]

For example, Alt+x dired, then Alt+x split-window-below, then navigate to another dir. Now, when you press C to copy, the other dir in the split pane will be default destination. Same for rename R and others.

Put this in your Emacs Init File:

(setq dired-dwim-target t)

Hide File Owner Permission Info

emacs dired-hide-details-mode 2022-04-22

In dired, Alt+x dired-hide-details-mode(】.

If you want it always on, add a hook. Like this:

(defun xah-dired-mode-setup ()
  "to be run as hook for `dired-mode'."
  (dired-hide-details-mode 1))

(add-hook 'dired-mode-hook 'xah-dired-mode-setup)

Make dired use the same buffer for viewing directory

Dired leaves a trail of directories. After a while, you have a lot buffers of dirs.

If you want dired always use the same buffer, put this in your Emacs Init File:

(require 'dired )

(if (< emacs-major-version 28)
      (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file) ; was dired-advertised-find-file
      (define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file ".."))) ; was dired-up-directory
    (setq dired-kill-when-opening-new-dired-buffer t)))

Make Dired Use Easier Keys

Make keys easier to type. For example, 5 instead of shift+5 for %, and “5 n” instead of shift+= for +.

You can move other frequently dired commands you use that have difficult key, to prefix 5.

(defun xah-config-dired ()
  "Config `dired'.
Version 2021-07-30 2023-02-25"
  (define-key dired-mode-map (kbd "5 n") #'dired-create-directory)
  (define-key dired-mode-map (kbd "5 m") #'dired-mark-files-regexp)
  (define-key dired-mode-map (kbd "5 h") #'dired-hide-details-mode)
  (define-key dired-mode-map (kbd "5 g") #'dired-mark-files-containing-regexp))

  (require 'dired )
  (add-hook 'dired-mode-hook #'xah-config-dired))

[see Ban Key Chords]

Emacs Dired, File Management

Emacs Init

Init Basics



Text Editing



Restore Things





Advanced Init Tips