Emacs: Dired Customization

By Xah Lee. Date: . Last updated: .

tips for setting up emacs's dired. See also: emacs dired basics.

In a file, how to go to its directory and place cursor on the file name

Put this in your init file:

(require 'dired-x)

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

delete/copy directory

Put this in your emacs init:

;; allow dired to delete or copy dir
(setq dired-recursive-copies (quote always)) ; “always” means no asking
(setq dired-recursive-deletes (quote top)) ; “top” means ask once

Then in dired, Alt+x dired-do-deleteD】 to delete directory.

copy from one dired dir to the next dired dir shown in a split window

Put this in your emacs init:

(setq dired-dwim-target t)

Eval the above or restart emacs. [see Evaluate Emacs Lisp Code]

Now, go to dired, then Alt+x split-window-below, then go to another dired dir. Now, when you press C to copy, the other dir in the split pane will be default destination. Same for dired-do-renameR】 and others.

hide file owner permission info

emacs dired-hide-details-mode
M-x dired-hide-details-mode. Top is normal dired, bottom is dired with hide details on.

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

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

In dired, Alt+x dired-find-alternate-filea】 to open the file/directory without creating a new buffer.

If you want Enter and ^ (parent dir) to use the same buffer, put the following in your emacs init file:

(require 'dired )

(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

hide some files

Alt+x dired-do-kill-linesk】 to hide marked files.

Dired topics

  1. File Manager, dired
  2. Dired Customization
  3. Find Replace Text in Directory
  4. Batch Rename Files
  5. Dired Sort File by Time, Size
  6. Open File in External App
  7. Rename File from Space to Hyphen/Underscore
  8. Convert Image Files in Dired

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp