Emacs: Dired Customization

By Xah Lee. Date: . Last updated: .

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

How to hide the file's unix owner and 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, call 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)

How to sort files in dired?

Emacs: Sort File by Time, Size, in Dired

How to delete or copy a 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, call dired-do-deleteD】 to delete directory.

How to 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 How to Evaluate Emacs Lisp Code

Now, go to dired, then call 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.

How to make dired use the same buffer for viewing directory?

In dired, call 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

How to hide some files?

Call dired-do-kill-linesk】 to hide marked files.

File Related Tips

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, call dired-jumpCtrl+x Ctrl+j】 to jump to the directory of current buffer.

how to open a (image, pdf, doc) file in external apps?

See: Emacs: Open File in External App.

How to rename multiple files?

See: Emacs: Batch Rename Files by Regex.

Using Dired+ Mode

For many extra features, you can install the “Dired Plus” mode. See: Using Emacs's “Dired Plus” Mode.

Dired topics

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs