Cached at:
07/24/26, 05:05 PM
# My Emacs configuration (Dired)
Source: [https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html)
A calendar icon05 Jul 2026
---
## Table of Contents
- [Preamble](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#preamble)
- [Calling the Dired](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#invoke-dired)
- [File operations](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#file-ops)- [Powerful rename](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#wdired) - [Copy/move files like in mc \(or Far\)](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-mc-like) - [Search for something](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-search)- [find\-name\-dired](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#find-name-dired) - [find\-grep\-dired](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#find-grep-dired)
- [External programs](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-external-programs)
- [Dired and photos/images](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-images)
- [Emacs\-specific things](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-emacs-specific)
- [Configuration overview](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-configuration-overview)- [Keybindings](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#emacs-dired-keybindings) - [Hooks](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#emacs-dired-hooks) - [Dired\-related variables](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#emacs-dired-variables) - [Faces customization](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#emacs-dired-faces)
- [Download](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#rc-dired-el-download)
- [Notes](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#notes)
This blog post is a part of the series of posts about my Emacs configuration\. Previous posts:
- [My Emacs configuration \(common parts\)](https://eugene-andrienko.com/2025-06-30-my-emacs-configuration-common.html)
- [Why and how I ditched use\-package?](https://eugene-andrienko.com/2025-10-10-emacs-ditch-use-package.html)
Here I will be dedicated to the configuration, and my habits, and usual actions during the Dired usage\. I decided not to just describe configuration and that's all — you could read a lot of likewise blogposts already\. Instead of it I also would like to describe how I am using Dired every day\.
Little explanation about[Dired](https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html)for readers, who didn't use it before\. It is a program for Emacs which works as a powerful file browser, which treats your precious files and directories as an \(almost\) usual Emacs buffer — so you can navigate through and work with you catalogs using the same "emacs\-habits"\.
Figure 1:Two Dired windows opened in the Emacs\.## Preamble
Since, I tend to use a kinda*minimalist*environment for computing — first, I used a CLI \(`bash`then`zsh`\) for the most of the operations with files and catalogs\. It works well, but I wanted to have some interactivity — copy/move*some files*from one catalog to another catalog without issuing multiple`cp`commands[1](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.cp), view contents of one directory while browsing another catalogs, like in Midnight Commander, etc\.
Some time I used the mentioned`mc`and it went well\. But I wanted more — preview images, etc — and the Midnight Commander was unable to help me with this, since it doesn't have plugins like Far\. Yes, it has a good menu, binded to F2 key, able to display various commands for various file types\. But it wasn't enough for me\.
So, by the way, I decided to give Dired a try — since it is already installed with almost every Emacs distribution\. And things went so well, that I'm staying with the Dired now\.
## Calling the Dired
Usually I'm invoking the Dired in two ways\. First, if I'm working with some project[2](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.project), I press`C\-x p d`hotkey and type some letters to jump into the desired catalog inside the project\.
E\.g\. if I work with my dotfiles and want to open directory`configs`I type:
```
C-x p d configs <RET>
```
And fall into the desired catalog:
If I want just to open the root catalog of the project — I use`C\-x p D`keybinding instead\.
Second, my beloved, method — the`C\-x C\-j`keybinding[3](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.jabber)\. It opens the Dired buffer in the*current working directory*\. For example, if I want to work with files for my blogpost, while I'm editing the post itself — I just press`C\-x C\-j`and buffer with article's Org file and images opens:
Figure 2:After C\-x C\-j press while editing the article\.org fileOf course, there are some other methods to invoke the Dired, which I'm using\. For example the default`C\-x d`keybinding, which I rebinded to`C\-x C\-d`for convenience:
```
(keymap-global-set "C-x C-d" 'dired)
```
I'm using this keybinding most of the time, when I want just to open some directory, local or remote \(with the help of TRAMP\)\. E\.g\. this is how I could open`bin`catalog on the not so remote server`server\.example\.com`with the`username`user account:
```
C-x C-d /ssh:
[email protected]:~/bin
^
- After entering this colon, the GnuGP will ask me about my
password for private key, to decipher ~/.authinfo.gpg with
username's password for server.example.com.
```
Also, in my system the Emacs frame with Dired buffer could be opened from any program which could open the file manager — e\.g\. after downloading file in Librewolf, I could press the*folder*icon in the "Downloads" drop\-down menu and the Emacs frame with Dired buffer for directory with my downloaded file will be opened:
I already described how to setup Emacs as a default file manager here:[Emacs Dired as a default file manager](https://eugene-andrienko.com/2025-07-24-x11-configuration-simple.html#xdg-utils-directory)\.
## File operations
Usual file operations: copying, moving or removing sets of files — are pretty simple\. "Just" mark some files with`m`keybinding and copy/move them \(see the[32\.7 Operating on Files](https://www.gnu.org/software/emacs/manual/html_node/emacs/Operating-on-Files.html)in the Emacs Manual\)\.
I placed*just*in the quotes, because there is not only`m`keybinding to mark files\. There are a lot of ways to do so — look at the[32\.6 Dired Marks vs\. Flags](https://www.gnu.org/software/emacs/manual/html_node/emacs/Marks-vs-Flags.html)section from Emacs manual\. Most of the time I'm using the next ways to mark some files:
KeybindingDescription\* sMark all files and catalogs\* \.Mark files with the specified extension% mMark files with names matched by regexpURemove all markstToggle marksFor example, I'm using`\* \.`to mark unwanted files by it's extension and delete them\. E\.g\. to delete all*web\-pee*images:`\* \. webp RET D y RET`\. Neat thing: if cursor already on the line with WEBP image, then the`\* \. RET D y RET`is enough, the`webp`part is preselected by default\.
By the way, these long "keybindings" are not real — there are two separate keybindings \(`\. \*`and`D`\), my answer for the prompt about file extension to select, and answer for the file deletion confirmation\.
Or another example: if I want to convert all WEBP images to the JPG \(I dislike WEBP as a*corporate image format*, to be honest\), then I'll do it in the next way:
- Press`\* \.`on the line with the WEBP image, and press`RET`\.
- At this point all WEBP files in the directory are selected\.
- Then I press`\!`and press`M\-n`few time to scroll to the mine \(previously saved\) special commands for images\.
- When the`gm convert ? \`?\`\.jpg`command is selected — I press Enter
- And after some waiting, all WEBP files converted to JPEG with[GraphicsMagick](http://www.graphicsmagick.org/)\. Unwanted WEBP files could be deleted as described above\.
You may wonder — how I define`gm convert`command for image files? The answer is in the[External programs](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#dired-external-programs)section\.
Another favorite keybinding is the`% m`— with the power of regular expressions I'm finally able to select any files in some catalog in a very tricky way — this is a thing that I was missing while using CLI or`mc`for file operations\. IIRC, the`mc`allows to select files by regexp, but in Dired this feature a way richer\.
Here the synthetic example, where I'm selecting image files starting from`e6f`substring and ending with`\.webp`or`\.webp\.SOME\_3\_LETTER\_EXTEN`— with the help of`^e6f\.\+\\\.webp\\\.?\\\(\[a\-z\]\\\{3\\\}\\\)?`regexp:
Separately from described*marks*, files also could be*flagged*for deletion —*mark*and*flags*are different inside Dired, so I able to*mark*some files to copy them to another place; and simultaneously*flag*another files to delete them\. These*flagged*files will have another face than the*marked*files — e\.g\. if*marked*files have purple face \(see the screenshot above\), then the*flagged*files will have the red one:
To*flag*by hand there is a`d`hotkey\. And to delete*flagged*files the hotkey`x`could be used\. And of course, there are much more keybindings, which I'm using to*flag*files for deletion:
KeybindingDescription% &Flag garbage files% dFlag files by regexpThe "garbage files" defined by the`dired\-garbage\-files\-regexp`variable\. E\.g\. in my configuration the artifacts from LaTeX build are considered "garbage":
```
;; Regexp for garbage files.
;; These files could be flagged
;; with "% &"
(setopt dired-garbage-files-regexp
"\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|o\\|orig\\|rej\\|toc\\)\\)\\'")
```
So, when I press`% &`, then all LaTeX build artifacts will be selected in the current directory for deletion\.
The`% d`works like`% m`keybinding, but it*flags*files instead of*marking*them\.
### Powerful rename
Let's look to the one of the most powerful Dired features\. Since directory listing just a buffer in the Emacs — it could be edited as a usual text? Of course\!
This is that the WDired mode does — it makes Dired buffer writable\. So the filenames could be edited as usual text: with the help of`isearch\-query\-replace\-regexp`, macros and other cool Emacs features\.
To enter WDired mode the`C\-x C\-q`keybinding could be used\. And the`C\-c C\-c`keybinding will return to the usual Dired mode with all the changes applied\. With the`C\-c C\-k`keybinding to return to the usual Dired mode with all the changes discarded\.
I often use WDired mode to strip unwanted text from filenames\. E\.g\. I want to remove`\.fb2`part from a lot of filenames like:
```
some-interesting-book.fb2.epub
```
In this situation I just perform the next things:
- Press`C\-x C\-q`to go to the WDired mod
- Enter`C\-s \.fb2 M\-% RET \!`— and all`\.fb2`suffixes are gone\! Basically, here the 3 commands:1. Search for`\.fb2`substring with`C\-s` 2. Call the`query\-replace`with`M\-%`keybinding 3. Tell the Emacs that the replacement string is empty by not entering any string to replace and just pressing the`RET`key\. 4. Tell the Emacs that it should replace any occurrences in the buffer without any further questions by pressing`\!`
- Press`C\-c C\-c`to apply changes\.
Another good example \(without regular expressions\)\. Here, I have audio files from "Regular Expressions" \(Регулярные выражения\) podcast:
As you can see, the files are badly named: months, days and hours don't have the prepending`0`for numbers less than 10, so the files sorted in the wrong way\. I can fix it by renaming everything in the Dired buffer:
Of course, some automation with regular expression could be also performed here, but I just want to show that WDired buffer could be edited literally as a text\.
By default, WDired allows to change only filenames\. But it also able to edit Unix access rights with`r`,`w`and`x`buttons with the next line in the configuration:
```
(setopt wdired-allow-to-change-permissions t)
```
If`dired\-hide\-details\-mode`is disabled in the Dired buffer \(it could be done by the pressing to the`\(`key\), then access rights will be visible and could be changed with the next keys:
- `r`: set read mode
- `w`: set write mode
- `x`: set executable mode
- `\-`: remove mode under the cursor\.
### Copy/move files like in mc \(or Far\)
Basically, there is nothing Dired\-specific — just create two vertical windows and open Dired buffers in each of them\.
But, there is one caveat exists — with default settings you will not be able to mimic the common thing from`mc`: copy files between two directories with substituted path to the destination directory, like`mc`or Far does\.
To fix it, I just set the next option:
```
(setopt dired-dwim-target t)
```
And after pressing`C`\(copy\) or`R`\(rename/move\) the path for destination is substituted from the second Dired window\.
### Search for something
Common search operations could be performed as usual, like in any other Emacs buffer \(e\.g\. with`C\-s`\)\. I already provided some not so easy examples above\.
There is one Dired\-related variable, which I changed to search only for filenames \(and skip catalogs\) with`C\-s`hotkey:
```
(setopt dired-isearch-filenames t)
```
Another common hotkey, which I'm using, is a`j`\. It allows to move cursor to the desired file or directory in the Dired buffer just by entering it's name:
But, of course, there are much more commands to use\. There are two notable and very useful commands:
- find\-name\-dired
- find\-grep\-dired
I don't know what's up in the Linux world, but in the BSD world there are the next settings necessary to use these commands and see the nice output in the Emacs, since the Dired defaults are for Linux coreutils but not for the BSD coreutils:
```
(setopt find-grep-options "-q")
(setopt find-ls-option '("-ls" . "-dils"))
```
#### find\-name\-dired
First cool command is`M\-x find\-name\-dired`\. It searches for files with given filename \(wildcards allowed\) in the given catalog\. The found files are shown in the nice Dired buffer with all Dired\-related features, mentioned above and below\.
For example, the result of`M\-x find\-name\-dired RET /bin RET c\* RET`:
Basically, it is just an interface for`find DIR \-name NAME`command, with Dired buffer attached\. So I'm using it mostly to search for some files, e\.g\. for some Java files when I'm know only the class name\.
#### find\-grep\-dired
Second cool command is the`M\-x find\-grep\-dired`\. It searches for files with given**content**\(regexp not only allowed but strongly recommended\!\) in the specified catalog\. The found files also shown in the newly opened Dired buffer\.
E\.g\. the result of`M\-x find\-grep\-dired RET ~/rsync/blog/articles/it/ RET \[Ee\]macs RET`:
This command is just an Emacsified version of`grep \-r '\[Rr\]egex' \*`, so it is used in the same way — when I need to search for some text in files\. Of course, the buffer with results is just an usual Dired buffer\.
## External programs
Now it's time to speak about external programs, which could be called from inside Dired\.
By default, the Emacs tries to open any file inside itself, if user presses`RET`on the file in the Dired buffer\. But, it may be convenient to open some files with external programs, for example open videos with MPlayer or open an image with nSxiv\. And the variable`dired\-open\-extensions`could help with that\!
It is just a list of conses[4](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.cons), where the*car*is the file extension and the*cdr*is the program \(from`$PATH`in my case\) which should open all the files with such extension:
```
(setopt dired-open-extensions '(("png" . "sxiv")
("PNG" . "sxiv")
("jpeg" . "sxiv")
("jpg" . "sxiv")
("JPEG" . "sxiv")
("JPG" . "sxiv")
("gif" . "sxiv")
("GIF" . "sxiv")
("webp" . "sxiv")
("WEBP" . "sxiv")
("avi" . "mplayer")
("m4a" . "mplayer")
("mkv" . "mplayer")
("mp3" . "mplayer")
("flac" . "mplayer")
("mp4" . "mplayer")
("webm" . "mplayer")
("eps" . "gv")))
```
I think, this part of configuration is self\-explanatory — it instructs Dired to open all images with`sxiv`command, and all videos with`mplayer`command\.
Let's look to another way to launch specific programs for specific files in the Dired\. I'm speaking about`dired\-guess\-shell\-alist\-user`variable and the`\!`or`&`hotkeys in the Dired buffer\.
First thing, you \(as a reader\) should know, The`\!`hotkey in the Dired buffer will run entered command**synchronously**— so Emacs will lock itself, while the command is running\. Sometimes, when the command \(like`gm convert`\) will exit very fast, it is OK and I could wait some small time while my files are transforming\. But, some commands take a lot of time, so there the`&`is to the rescue\. It will run the entered command**asynchronously**, so the Emacs will not be locked while the command is running\. It is useful for e\.g\. converting some video files from WEBM to MP4, etc\.
Of course, the entered command will be applied to the file under the cursor or to the*marked*files in the Dired buffer\.
Second thing: after your press one of the before\-mentioned keybindings, then the Dired will show you the prompt in the minibuffer, like this:
And there are two important keybindings:
- `M\-p`shows you the commands which you entered before in this prompt\.
- `M\-n`shows the*predefined*commands\.
Emacs Dired allows to*define*a lot of commands, depending on the filename extension, so for the images the`M\-n`will show one set of*predefined*commands and for videos it will show another set of commands\. The variable`dired\-guess\-shell\-alist\-user`allows to define these commands, like this:
```
dired-guess-shell-alist-user
'(("\\.\\([Jj][Pp][Ee]?[Gg]\\|[Pp][Nn][Gg]\\|[Tt][Ii][Ff]\\{2\\}\\|[Ww][Ee][Bb][Pp]\\)$"
"sxiv -t * "
"sxiv -o * | xargs rm -f"
"sxiv -o * | xargs dragon"
"sxiv -o * | xargs gimp"
"gm convert ? -resize 1080x1080^ resized_`?`"
"gm convert ? -resize 2560x2560^ resized_`?`"
"pngquant --speed 1 --strip --skip-if-larger --force * "
"jpegoptim -m 80 --auto-mode -s * ")
("\\.ORF$"
"rawtherapee * ")
("\\.[Gg][Pp][Xx]$"
"qmapshack * "))
```
This variable is just a list of lists, where the each inner list should contain two things:
1. Regular expression which selects the file extension\. For this extension \(or these extensions\) the next written command\(s\) will be displayed after pressing`M\-n`\.
2. The next items of inner list is just a strings with commands, which should be launched for the files with extensions from item \#1\.
So, in the example, provided above, there are:
- Some commands:`sxiv`,`gm`,`pngquant`and`jpegoptim`— were assigned to the common extensions for images, like: JPG, PNG, TIFF and WEBP images\.
- Command to launch RawTherapee for`\*\.orf`files\.
- Command to launch QMapShack for`\*\.gpx`files\.
Note, that where a various wildcard symbols in these command:`\*`,`?`and`\`?\``\. For example \(and for my further explanation\), lets assume what we have the next files in the catalog, opened in Dired:
- 01\.jpg
- 02\.jpg
- 03\.jpg
The command like this:`rm \*`— issued from Dired with the help of`\!`or`&`keys will be landed to the shell in the next form:
```
rm 01.jpg 02.jpg 03.jpg
```
But, if you type the`rm ?`instead — then the Dired will issue**three**commands:
```
rm 01.jpg
rm 02.jpg
rm 03.jpg
```
And for the`mv ? \`?\`\.test`the next three commands will be issued:
```
mv 01.jpg 01.jpg.test
mv 02.jpg 02.jpg.test
mv 03.jpg 03.jpg.test
```
How these tricks with`\*`,`?`and`\`?\``could be used? The first one is self\-explanatory — just use it, if need to apply some command to the all selected files\.
The`?`and`\`?\``are more tricky\. E\.g\., they could be used for image conversion via GraphicsMagick — when you don't want to lost the original filename\. Here the`\`?\``comes to the rescue — with back\-quotes it is possible to add some text before or after the original filename, because both`\*`and`?`should be surrounded by spaces or Dired will not understand it[5](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.dired-globbing)\. So with e\.g\.`gm convert ? \`?\`\.png`the next three commands will be executed by the Emacs:
```
gm convert 01.jpg 01.jpg.png
gm convert 02.jpg 02.jpg.png
gm convert 03.jpg 03.jpg.png
```
And the next command won't do anything meaningful:
```
gm convert ? ?.png
```
First, it will ask user about:
```
1 occurrence of ‘?’ will not be substituted. Proceed? (y, n, ?)
```
And if user answers`y`, then the next non\-desired commands will be executed:
```
gm convert 01.jpg ?.png
gm convert 02.jpg ?.png
gm convert 03.jpg ?.png
```
## Dired and photos/images
Let's delve[6](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.llm)into the photography topic much more\.
Usually, my photos land to the some catalog, named with pattern:*date of event*\-*name of the event*\. And I'm using Dired to work with these photos, intensively:
1. Copying the photos from camera with`C\-x d /media/exfat/Olymp/DCIM/100OLYMP`in one window and`C\-x d ~/pictures/date\-name`on the other window, then press`\* s`to mark all new photos and press`r`to copy them with the help of openrsync\.
2. With the help of before\-mentioned`dired\-guess\-shell\-alist\-user`I'm first selecting some \(usually 30\-50%\) photos for deletion\. The command`sxiv \-o \* \| xargs rm \-f`allows me to mark some bad photos with`m`key, so their filenames will be sent to the input of`rm \-f`, when I quit from[nSxiv](https://codeberg.org/nsxiv/nsxiv)image viewer\. 
3. Then, I use the same command:`sxiv \-o \* \| xargs gimp`— to open marked images in the Gimp for some edits\.
Another few tricks which I'm using to connect photography and Dired\. First of all, there is a`C\-t t`hotkey to display thumbnails for selected images right in the Dired buffer\. This looks like this:
The same hotkey could be used to hide thumbnails for selected images\. It is extremely useful when I want just copy specific images to the \(e\.g\.\) friend's USB\-drive\.
The next convenient hotkey is a`C\-t o`\. It displays a separate Image Dired buffer with thumbnails \(and customizable information bar\) for selected images and some useful hotkeys, to rotate pictures, open them in Gimp, etc\. I didn't use it much enough, but it convenient to operate with photos like it happens with usual file browser within a fat DE; or to select the photo with necessary DPI and size\.
The information bar is not the default — it is customizable and of course it was customized\. The contents of this bar is generated in the`image\-dired\-format\-properties\-string`function and \(in my case\) I just override it with my function via`advice\-add`:
```
(advice-add 'image-dired-format-properties-string :around #'evgandr/image-dired-enrich-properties)
```
The custom function`evgandr/image\-dired\-enrich\-properties`looks like this:
```
;;;###autoload
(defun evgandr/image-dired-enrich-properties (original-fun buf file image-count props comment)
"Advice for `image-dired-format-properties-string'.
This advice adds image resolution to the image description in the
`image-dired' buffer. The arguments are almost the same as for the
`image-dired-format-properties-string' function: BUF is a Dired buffer,
FILE is an original image file, IMAGE-COUNT is an overall count of
images as a string, PROPS is a stringified list of tags, COMMENT is a
comment for image file.
One new argument is an ORIGINAL-FUN which is an original
`image-dired-format-properties-string' function."
(let ((original-str (apply original-fun (list buf file image-count props comment)))
(size (evgandr/image-size file)))
(concat original-str " " size)))
```
This function just wraps around original function and add some string from`evgandr/image\-size`function to the default contents of the bar: number of file in the list, file name and size\. The*default contents*is taken from the original function \(look at the`original\-fun`parameter\)\.
The`evgandr/image\-size`function retrieves the information about given image file via`gm indetify`\(it is a GraphicsMagick, since ImageMagick embraced LLM slop in the codebase[7](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.imagemagick-slopware)\):
```
(defun evgandr/image-size (file)
"Return image resolution.
FILE is an image file."
(with-temp-buffer
(call-process "gm" nil t nil "identify"
"-format" "%wx%h dpi:%xx%y compression:%Q" file)
(string-chop-newline (buffer-string))))
```
The general idea of all of these modifications is not mine — it was taken from the[Extending image\-dired](https://stefanorodighiero.net/blog/extending-image-dired.html)blogpost\.
## Emacs\-specific things
Here just an one thing, which I'm using\. Since all my Emacs configuration is byte\-compiled, I'm using Dired to byte\-compile changed`\.el`files from my configuration\. There are 3 simple steps:
1. Open the necessary catalog with the help of`C\-x p p dotfiles RET d emacs\.d/config RET`\.
2. Select all`\*\.el`files in the directory with my Emacs configuration files with`\* s`\.
3. Press`B`to Byte\-compile the selected files\.

## Configuration overview
Let's go to the last chapter — to the ELisp code with which I configure Dired\. As I wrote[before](https://eugene-andrienko.com/2025-10-10-emacs-ditch-use-package.html), I don't use`use\-package`and use simple old ways to write my Emacs configuration with`require`,`provide`and so on\.
With Dired I'm using the next few external packages:
- `delight`to hide some minor modes from the modeline\.
- `dired\-rsync`to use rsync \(I'm using openrsync, since rsync is the LLM\-slop[8](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.rsync-slopware)too\) to copy files between catalogs\.
- `dired\-subtree`to open catalogs in the Dired as subcatalogs in the same buffer with a`TAB`key\.
- `dired\-x`for`dired\-omit\-mode`usage\. This mode hides some uninteresting files in the Dired buffers \(like`\*\.elc`files, etc\)\.
- `nerd\-icons\-dired`to have a nice icons, like you already have seen on the screenshots above\. Obviously the Nerd Icons and`nerd\-icons`plugin should be installed first\.
```
1: ;;; rc-dired.el --- Dired configuration --- -*- lexical-binding: t -*-
2: ;;; Commentary:
3:
4: ;;; Code:
5:
6: (require 'delight)
7: (require 'dired)
8: (require 'dired-hide-dotfiles)
9: (require 'dired-open)
10: (require 'dired-rsync)
11: (require 'dired-subtree)
12: (require 'dired-x)
13: (require 'image-dired)
14: (require 'nerd-icons-dired)
```
Then, I'm disabling some minor modes from displaying them in the modeline with the help of`delight`:
```
16: (delight 'auto-revert-mode nil "autorevert")
17: (delight 'nerd-icons-dired-mode nil "nerd-icons-dired")
18: (delight 'dired-hide-dotfiles-mode nil "dired-hide-dotfiles")
19: (delight 'dired-omit-mode nil "dired-x")
```
Also, I added this line to enable`dired\-find\-alternate\-file`[9](https://eugene-andrienko.com/2026-07-05-my-emacs-configuration-dired.html#fn.dired-find-alternate-file)\. It works in conjunction with`dired\-kill\-when\-opening\-new\-dired\-buffer`variable, described below and helps me to maintain amount of opened Dired buffer at low level:
```
207: (put 'dired-find-alternate-file 'disabled nil)
```
### Keybindings
Some custom keybindings is in use\. First:
```
21: (keymap-global-set "C-x C-d" 'dired)
```
The default one is`C\-x d`but I want to use`C\-x C\-d`since it is uniform with`C\-x C\-f`\.
Next keybinding is to create*something*:
```
22: (define-key dired-mode-map (kbd "+") 'evgandr/dired-create-file-or-directory)
```
By default, the`\+`could be used to create a new directory\. But I want not to just create a new catalog, but also a new empty file with the same keybinding\. So, the custom`evgandr/dired\-create\-file\-or\-directory`function helps here:
```
79: ;;;###autoload
80: (defun evgandr/dired-create-file-or-directory (path)
81: "Create file or directory in the current working directory.
82:
83: Create file or directory using PATH as a path to the new file or
84: directory. The directory path should contain trailing slash at the end."
85: (interactive "GCreate new file or directory: ")
86: (if (or (file-exists-p path)
87: (file-directory-p path))
88: (message "Error: '%s' already exists." path))
89: (if (string-match "/$" path)
90: (dired-create-directory path)
91: (dired-create-empty-file path)))
```
The idea of this function is not mine, but I lost the URL of blogpost where it was introduced :\-\(\. The function works pretty simple: if path ends with`/`then user wants to create a new catalog and it will be created\. Otherwise, the new empty file will be created\.
Third, I defined some keybindings especially for`dired\-mode\-map`to simplify usage of some plugins:
```
35: ; Keybindings for
36: ; `dired-hide-dotfiles',
37: ; `dired-rsync' and
38: ; `dired-subtree'
39: (add-hook 'dired-mode-hook
40: (lambda ()
41: (keymap-set dired-mode-map "H" 'dired-hide-dotfiles-mode)
42: (keymap-set dired-mode-map "r" 'dired-rsync)
43: (keymap-set dired-mode-map "<tab>" 'dired-subtree-toggle)
44: (keymap-set dired-mode-map "TAB" 'dired-subtree-toggle)
45: (keymap-set dired-mode-map "<backtab>" 'dired-subtree-remove)
46: (keymap-set dired-mode-map "S-TAB" 'dired-subtree-remove)))
```
There are the next keys:
- `H`key to hide/show dotfiles in the catalog\.
- `r`to invoke`openrsync`for files/directories copying\.
- `TAB`to display subcatalog contents as a subtree\.
- `S\-TAB`to hide the subtree\.
Figure 3:This is how the expanded subcatalogs looks like in the Dired buffer\.
### Hooks
To enable some helper minor modes there are some hooks are in use:
```
24: ; Enable some helper modes in
25: ; Dired
26: (add-hook 'dired-mode-hook 'dired-omit-mode)
27: (add-hook 'dired-mode-hook 'dired-hide-details-mode)
28: (add-hook 'dired-mode-hook 'dired-hide-dotfiles-mode)
29: (add-hook 'dired-mode-hook 'hl-line-mode)
30: (add-hook 'dired-mode-hook 'nerd-icons-dired-mode)
31: ; Use Dired to attach files in
32: ; mail client
33: (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
34: ; Auto refresh dired buffer
35: (add-hook 'dired-mode-hook 'auto-revert-mode)
```
These minor modes enables some pretty things:
The dired\-omit\-mode, dired\-hide\-details\-mode and dired\-hide\-dotfiles\-modeJust hide dotfiles,`\.`and`\.\.`catalogs, and don't display file attributes by default\. If I need to look at the hidden files, I just press`H`; and if I need to view to file attributes I could just press`\(`key\.The hl\-line\-modeI need to highlight the whole line, where the cursor stays, in the Dired buffers — it helps me to see where is my cursor at all\.The nerd\-icons\-dired\-modeThis mode just enables nice Nerd Icons in the Dired buffers \(if they were installed first\)\.The turn\-on\-gnus\-dired\-modeThere is a knob to enable`gnus\-dired\-mode`— a special mode to work with e\-mail attachments\. With it, I can*mark*some files and then press`C\-c RET C\-a`to attach these files to the e\-mail\.The auto\-revert\-modeIt is used in the same way as in other buffers — to revert buffer if underlying contents were changed\. In case of Dired: if files/catalogs in the opened directory are added/deleted — then the Dired buffer will be automatically updated\.
### Dired\-related variables
This section will be a looooong one :\-\)\. If code comment for some variable is self\-explanatory — I will skip the unnecessary repeating\.
If I*marked*some files and want to create an archive with the help of`Z`button, then the resulting TAR archive will be compressed with zstd:
```
93: ; Compress to the `.tar.zst'
94: ; by default
95: (setopt dired-compress-directory-default-suffix ".tar.zst"
```
The next Dired setting is a very convenient\. I can specify a lot of non\-existent catalogs in the path, where I want to copy file — and Dired will create all of these catalogs by itself:
```
96: ; Create non-existent
97: ; destination directories on
98: ; copying/moving files
99: dired-create-destination-dirs 'always
```
```
100: ; old -> new/ will copy old
101: ; inside the new/. old -> new
102: ; will renamed old to the new.
103: dired-create-destination-dirs-on-trailing-dirsep t
104: ; Suggest already opened Dired
105: ; buffers for file operations
106: dired-dwim-target t
107: ; Don't wrap long filenames,
108: ; truncate them
109: dired-filename-display-length 'window
110: ; Don't show free space line
111: dired-free-space nil
112: ; Regexp for garbage files.
113: ; These files could be flagged
114: ; with "% &"
115: dired-garbage-files-regexp "\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|o\\|orig\\|rej\\|toc\\)\\)\\'"
116: ; Special commands for files
117: ; with specified extensions
118: dired-guess-shell-alist-user
119: '(("\\.\\([Jj][Pp][Ee]?[Gg]\\|[Pp][Nn][Gg]\\|[Tt][Ii][Ff]\\{2\\}\\|[Ww][Ee][Bb][Pp]\\)$"
120: "sxiv -t * "
121: "sxiv -o * | xargs rm -f"
122: "sxiv -o * | xargs dragon"
123: "sxiv -o * | xargs gimp"
124: "gm convert ? -resize 1080x1080^ resized_`?`"
125: "gm convert ? -resize 2560x2560^ resized_`?`"
126: "pngquant --speed 1 --strip --skip-if-larger --force * "
127: "jpegoptim -m 80 --auto-mode -s * ")
128: ("\\.ORF$"
129: "rawtherapee * ")
130: ("\\.[Gg][Pp][Xx]$"
131: "qmapshack * "))
```
Since I'm using GNU Stow to manage my dotfiles, these files in`$HOME`are just symlinks\. And I'm too lazy to press`\(`every time when I need to see the destination of the symlink\. So, I have this:
```
132: ; Show symlink targets if all
133: ; other details are hidden
134: dired-hide-details-hide-symlink-targets nil
```
```
135: ; ISearch will search only for
136: ; filenames
137: dired-isearch-filenames t
```
By default \(IIRC\) the Dired will open a new buffer for each opened subdirectory\. So, when I'm browsing e\.g\. some Maven projects, I'll get a long list of unnecessary for me buffers\. To avoid this, the variable`dired\-kill\-when\-opening\-new\-dired\-buffer`exists — it instructs Dired to kill the buffer with parent directory when I go to deeper in the file hierarchy\. There is always a`^`button to go back\.
```
138: ; Only one Dired buffer
139: dired-kill-when-opening-new-dired-buffer t
```
```
140: ; Extensions of LaTeX files to
141: ; clean them with
142: ; `dired-clean-tex'
143: dired-latex-unclean-extensions '(".fdb_latexmk" ".fls" ".glo"
144: ".idx" ".lof" ".log" ".lot"
145: ".nav" ".out" ".snm" ".synctex.gz"
146: ".vrb")
147: ; Display human-readable files
148: ; sizes
149: dired-listing-switches "-alh"
150: ; Enable mouse dragging to
151: ; another apps
152: dired-mouse-drag-files t
153: ; Skip empty lines
154: dired-movement-style 'bounded
155: ; Don't show messages from
156: ; dired-omit
157: dired-omit-verbose nil
158: ; How to open some files
159: dired-open-extensions '(("png" . "sxiv")
160: ("PNG" . "sxiv")
161: ("jpeg" . "sxiv")
162: ("jpg" . "sxiv")
163: ("JPEG" . "sxiv")
164: ("JPG" . "sxiv")
165: ("gif" . "sxiv")
166: ("GIF" . "sxiv")
167: ("webp" . "sxiv")
168: ("WEBP" . "sxiv")
169: ("avi" . "mplayer")
170: ("m4a" . "mplayer")
171: ("mkv" . "mplayer")
172: ("mp3" . "mplayer")
173: ("flac" . "mplayer")
174: ("mp4" . "mplayer")
175: ("webm" . "mplayer")
176: ("eps" . "gv"))
177: ; Copy recursively
178: dired-recursive-copies 'always
179: ; Delete recursively, ask once
180: dired-recursive-deletes 'top
```
The next two variables are necessary to instruct`dired\-rsync`to use`openrsync`:
```
181: dired-rsync-command "/usr/local/bin/openrsync"
182: dired-rsync-options "-a"
```
By default, the`dired\-subtree`plugin uses a very strange set of colors — aka not matching with my Solarized Light theme — in the background face for files and catalogs in the subtree\. So the next variable set to`nil`disables this behavior:
```
183: ; Use default background face
184: ; in the directory listings
185: dired-subtree-use-backgrounds nil
```
```
186: ; Grep options for "M-x
187: ; find-grep-dired"
188: find-grep-options "-q"
189: ; Find options for "M-x
190: ; find-grep-dired"
191: find-ls-option '("-ls" . "-dils")
192: ; External viewer for images
193: image-dired-external-viewer "nsxiv"
194: ; Margin between thumbnails
195: image-dired-thumb-margin 5
196: ; Use 256x256 size for
197: ; thumbnails
198: image-dired-thumb-size 256
199: ; Store thumbnail at
200: ; `~/.cache/thumbnails'
201: image-dired-thumbnail-storage 'standard-large
202: ; Use Emacs Lisp realization
203: ; of ls
204: ls-lisp-use-insert-directory-program nil
205: ls-lisp-dirs-first t
206: ; Change permissions in WDired
207: wdired-allow-to-change-permissions t)
```
### Faces customization
There are not so much customization I've made\. Just changed colors of blue header with current path on the top of Dired buffer and color of directory — so they match with my Solarized Light color scheme:
```
210: (custom-set-faces
211: `(dired-directory ((t (:foreground "#268bd2"))))
212: `(dired-header ((t (:background
213: "#268bd2"
214: :foreground
215: "#eee8d5")))))
```
## Notes