- Watch the video on YouTube!
- Check out the final code on GitHub
- Episode 10 of the Emacs From Scratch series
¶Dired Basics
¶Invocation
C-x d
orC-x C-f
-dired
dired-jump
- open Dired buffer, select the current fileprojectile-dired
¶Navigation
Emacs / Evil
n
/j
- next linep
/k
- previous linej
/J
- jump to file in bufferRET
- select file or directory^
- go to parent directoryS-RET
/g O
- Open file in “other” windowM-RET
- Show file in other window without focusing (previewing files)g o
(dired-view-file
) - Open file but in a “preview” mode, close withq
¶Configuration
dired-listing-switches:
Try-agho --group-directories-first
g
/g r
Refresh the buffer withrevert-buffer
after changing configuration (and after filesystem changes!)(use-package dired :ensure nil :commands (dired dired-jump) :bind (("C-x C-j" . dired-jump)) :config (evil-collection-define-key 'normal 'dired-mode-map "h" 'dired-up-directory "l" 'dired-find-file))
¶File Operations
¶Marking files
m
- Marks a fileu
- Unmarks a fileU
- Unmarks all files in buffer* t
/t
- Inverts marked files in buffer% m
- Mark files in buffer using regular expression*
- Lots of other auto-marking functionsk
/K
- “Kill” marked items (refresh buffer withg
/g r
to get them back)- Many operations can be done on a single file if there are no active marks!
¶Copying and Renaming files
C
- Copy marked files (or if no files are marked, the current file)- Copying single and multiple files
U
- Unmark all files in bufferR
- Rename marked files, renaming multiple is a move!% R
- Rename based on regular expression:^test
,old-\&
¶Deleting files
D
- Delete marked filed
- Mark file for deletionx
- Execute deletion for marksdelete-by-moving-to-trash
- Move to trash instead of deleting permanently
¶Creating and extracting archives
Z
- Compress or uncompress a file or folder to (.tar.gz
)c
- Compress selection to a specific filedired-compress-files-alist
- Bind compression commands to file extension
¶Other common operations
T
- Touch (change timestamp)M
- Change file modeO
- Change file ownerG
- Change file groupS
- Create a symbolic link to this fileL
- Load an Emacs Lisp file into Emacs
¶Single Dired buffer
Closed Dired buffers are just buried! They need to be refreshed if you go back to them.
Use dired-single to help with this!
;; Inside `use-package dired` (use-package dired-single) (evil-collection-define-key 'normal 'dired-mode-map "h" 'dired-single-up-directory "l" 'dired-single-buffer))
¶File icons
(use-package all-the-icons-dired :hook (dired-mode . all-the-icons-dired-mode))
¶Open external files
!
or&
to launch an external program on a file
(use-package dired-open :config ;; Doesn't work as expected! (add-to-list 'dired-open-functions #'dired-open-xdg t) ;; -- OR! -- (setq dired-open-extensions '(("png" . "feh") ("mkv" . "mpv"))))
¶Hide / show dotfiles
(use-package dired-hide-dotfiles :hook (dired-mode . dired-hide-dotfiles-mode) :config (evil-collection-define-key 'normal 'dired-mode-map "H" 'dired-hide-dotfiles-mode))