Skip to content
HN On Hacker News ↗

My Emacs configuration (Dired)

▲ 43 points 19 comments by meysamazad 4w ago HN discussion ↗

Pangram verdict · v3.3

We believe that this document is fully human-written

0 %

AI likelihood · overall

Human
100% human-written 0% AI-generated
SEGMENTS · HUMAN 5 of 5
SEGMENTS · AI 0 of 5
WORD COUNT 1,781
PEAK AI % 0% · §4
Analyzed
Jul 24
backend: pangram/v3.3
Segments scanned
5 windows
avg 356 words each
Distribution
100 / 0%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 1,781 words · 5 segments analyzed

Human AI-generated
§1 Human · 0%

A calendar icon 05 Jul 2026 Table of Contents Preamble Calling the Dired File operations Powerful rename Copy/move files like in mc (or Far) Search for something find-name-dired find-grep-dired External programs Dired and photos/images Emacs-specific things Configuration overview Keybindings Hooks Dired-related variables Faces customization Download Notes This blog post is a part of the series of posts about my Emacs configuration. Previous posts: My Emacs configuration (common parts) Why and how I ditched use-package? 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 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 commands1, 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.

§2 Human · 0%

First, if I'm working with some project2, 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 keybinding3. 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 file Of 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:username@server.example.com:~/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. 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 in the Emacs Manual).

§3 Human · 0%

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 section from Emacs manual. Most of the time I'm using the next ways to mark some files: Keybinding Description * s Mark all files and catalogs * . Mark files with the specified extension % m Mark files with names matched by regexp U Remove all marks t Toggle marks For 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. 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 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.

§4 Human · 0%

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: Keybinding Description % & Flag garbage files % d Flag files by regexp The "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.

§5 Human · 0%

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: Search for .fb2 substring with C-s Call the query-replace with M-% keybinding Tell the Emacs that the replacement string is empty by not entering any string to replace and just pressing the RET key. 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.