Emacs dired-mode as a file manager

53 todsacerdoti 33 5/23/2025, 6:46:57 PM lynn.sh ↗

Comments (33)

susam · 3h ago
I didn't see this mentioned in the article, so I thought I would mention it here:

Dired stands for directory editing.

One of my favourite features of Dired is the ability to mark or unmark multiple files in a variety of ways: manually, using repetition counts, or with regular expressions. This can be done fluidly and spontaneously as we browse and inspect files. Once we're satisfied with our selection, we can perform bulk operations on them such as copying, moving, deleting, changing permission bits, compressing the marked files, etc.

It's a bit like how we can use a GUI desktop environment to mark multiple files and then perform bulk operations on them. This is something we cannot easily do on the shell with the standard Unix utilities. But we can do all of this from within Emacs using very concise sequence of keystrokes and muscle memory.

Further, unlike most GUI desktop environments, every Dired interaction is scriptable, recordable, and replayable. I mean every operation or key sequence in Dired is available as an Elisp function, so we can script repetitive tasks by writing small Elisp snippets. Or, alternatively, we can have Emacs record the repetitive actions as keyboard macros, which we can then replay as many times as needed. I no longer have to worry whether the underlying GUI desktop environment supports these features or not because I know Emacs does and I can just use Emacs to browse my system.

And that brings me to another important benefit of using Dired: my muscle memory for Dired is transferable across a wide variety of systems and environments. It doesn't matter whether I'm working locally or logged into a remote shell, or whether I'm on macOS, Xfce4, KDE, etc. I can browse and edit my files and directories in exactly the same way using the same muscle memory and the same set of Dired commands, key sequences, and features!

A couple of years ago, I used to host Emacs book club meetings. I've kept some notes on directory editing with Dired from those sessions here: <https://susam.net/cc/mastering-emacs/ch06.html#dired>.

JCattheATM · 29m ago
> One of my favourite features of Dired is the ability to mark or unmark multiple files in a variety of ways: manually, using repetition counts, or with regular expressions. This can be done fluidly and spontaneously as we browse and inspect files. Once we're satisfied with our selection, we can perform bulk operations on them such as copying, moving, deleting, changing permission bits, compressing the marked files, etc.

That does sound cool. Emacs sounds like the type of app I would have loved back when DOS was still a thing, but now after using linux for 20 something years, the fact that it can do everything just seems so antithetical to the unix way...even if I could see myself using it, the idea of being so dependent on one app for so much seems so weird to me these days. Guess I'll be sticking with vim and various cli tools until the end of time.

chungy · 7m ago
Emacs, and GNU at large, never cared for Eric Raymond's idea of "do one thing and one thing only" being the Unix way. They freely make large do-everything programs.
sixtyj · 2h ago
So it is similar to Total Commander, but in editor. Or Double Commander…
nothrabannosir · 9m ago
One difference (I assume?): it’s programmable. It’s a directory editor written in the same VM in which the editor (Emacs) is written. This makes it compostable with your existing IDE toolset of macros, plugins, hotkeys, etc.

For example: I never thought of using total commander to augment some custom hotkey in vim. But in Emacs it’s just another set of functions available right there.

mimischi · 1h ago
Just that it’s all done from the comfort of the editor one knows and loves, with the same key binding and semantics that at there, whether you edit files in fired, write code, a commit message or an email.

Not to get too deep into this, but there’s this warm fuzzy feeling of not having to use /yet another different app/ that’s ever so slightly different to the optimal workflow you have otherwise

julienchastang · 1h ago
wdired-change-to-wdired-mode, FTW! :-) An extremely cool feature is dired buffers are editable for changing file names and permissions. You can even use this feature, en masse, with other features like rectangle edit.
tcoff91 · 1h ago
Can you copy a line and paste it in a different directory to copy a file?

Oil.nvim provides an incredible experience for managing files. It'll even use the LSP to fix imports if you move files from place to place.

julienchastang · 49m ago
I've never tried that but copying files via two different dired buffer is trivial. It is also really useful for copying files to and from remote hosts via tramp. (If copying large files in this manner look into rsync versus ssh.) Here is my .emacs if you want to see it: https://github.com/julienchastang/dotemacs/blob/master/setti.... It is a continuous work in progress.
entropie · 1h ago
I use dired for a long time now and at first it felt a bit weird but not anymore. The ultimate killer feature is wdired [1] that make the dired buffer writeable and you can edit text/filenames/permissions like in any other emacs buffer and commit the changes with C-c C-c.

1: https://www.gnu.org/software/emacs/manual/html_node/emacs/Wd...

ww520 · 1h ago
In dired-mode, I want to have a split view of the directory listing on the left window and to quickly browse the content of each file on the right window. The default file visit command keeps opening a new window for each file which needs closing. It's really annoying. I put the following in init.el file and bind it to a key. It loads the current file under the cursor in the next existing window on right, on left, above, below, or opening a new window as needed.

  ;; In dired mode, visit the file at the cursor in the right/below/left/above window.
  (defun my-dired-display-direction ()
    (interactive)
    (let* ((file-or-dir (dired-get-file-for-visit))   ;; get the file at cursor
           (buffer (find-file-noselect file-or-dir))) ;; load the file into a buffer
      (let ((window                                   ;; figure out the window to use
             (cond ((get-buffer-window buffer (selected-frame)))
                   ((window-in-direction 'right))     ;; try window in each direction
                   ((window-in-direction 'below))     ;; and default to right
                   ((window-in-direction 'left))      ;; if no window found.
                   ((window-in-direction 'above))
                   (t (split-window (selected-window) nil 'right)))))
        (window--display-buffer buffer window 'window nil)
        window)) )
  
  ;; Bind ctrl-o to display at direction.
  (define-key dired-mode-map (kbd "C-o") 'my-dired-display-direction)
phforms · 1m ago
I guess you already know the command `dired-find-file-other-window` (bound to `o` by default), which reuses the right split window, if already there and opens a new window if there is none. Horizontal splits do not seem to be reused though (they often don’t have enough vertical space for dired anyway, which is why I guess they designed it this way).
skydhash · 27m ago
An alternative workflow I use is the dired-view-file bound to 'v' to have a read-only buffer for the file which you can scroll through with <space> and other such keys. Then you can use 'q' to close the buffer and 'e' to edit it.
perihelions · 3h ago
> "Opening them from dired-mode already puts them into emacs, so"

This also works globally with #'find-file-at-point (which isn't bound to a hotkey by default, but should be: this is one of my most satisfying hotkeys. That function opens any filepath appearing as a string, in any context, in the working directory of that context—filepath strings in files, and filepath strings as outputs from shell commands, being the top two).

(It's like converting every file reference into a clickable URL—only, implicitly).

ruricolist · 2h ago
If you just do C-x C-f, M-n to get the "next completion" gives you the file at point.
ews · 1h ago
The most amazing part of guix (and nixOS) is that you can just copy that piece of code into your home-config.scm and have it running in a few seconds. It's pretty mind blowing.
shwouchk · 56m ago
my absolute favorite feature of dired is rw mode (^x ^q) - edit your dir like a normal text file. use regex replacement, macros with counters, multi cursor - whatever you like. See the result of your edits, commit bam. much more fun than piping find through something
90s_dev · 3h ago
The one thing I miss about dired-x is being able to edit multiple filenames simultaneously in the same way you do edit a file using multiple cursors, and commit the changes all at once. Can someone make that work in Windows Explorer or VS Code please?
teddyh · 1h ago
Slight nitpick: It’s no longer called a “MIME Type”, it’s now called an “Internet Media Type”.
paulyy_y · 3h ago
The insanity of trying to shoehorn everything into emacs, even calling it an OS, is purely beyond.
bigdict · 3h ago
Once you realize that elisp is a better shell programming language than bash, it ceases to appear insane.
hollerith · 2h ago
I much prefer them to the people that try to shoehorn everything user-facing into the browser.
internet_points · 2h ago
s/browser/llm
snapdaddy · 3h ago
How many editors can you think of that don't do any (strictly) unnecessary file operations, e.g. renaming files? The author's problem is that Emacs is just really good at it, so he wants to use it more.
tadfisher · 2h ago
Emacs is a shell, not an OS. It's an extremely customizable and programmable shell that works with many third-party utilities, but it's still a shell.
rbc · 1h ago
I'd call it more than a shell. It's more like a text oriented Lisp (Emacs Lisp to be specific) runtime environment with built in editing, interpretation, compilation, and debugging tools. It's also been a popular home for numerous applications that have found lives of their own, far beyond editing text.
timewizard · 2h ago
It gives me fewer reasons to leave Emacs. Which increases my productivity. There's very little 'mental context switch' delay since it's all the same tool with the same interface.
SoftTalker · 3h ago
My file manager is the shell and the utilities like cp, mv, rm, find, xargs, grep, etc.

Have never felt the need for anything beyond that.

sudahtigabulan · 10m ago
I feel exactly the same, but a sibling comment reminded me how I got there.

I didn't need a replacement for Windows Explorer, until I tried Linux (bash, really) out of boredom/curiosity, and now I can't imagine going back.

Could be that there's another step up. And we can't see it from where we are standing.

sfpotter · 2h ago
Just because you've never felt the need doesn't mean you aren't stuck in a local minimum.
trey-jones · 2h ago
dired-mode is fairly necessary in emacs to preserve the continuity of what you are editing.

For example, if I'm editing a file called originalfilename.txt, and I decide it should be called newfilename.txt, I can mv originalfilename.txt newfilename.txt in the terminal and it's all good, but you're still editing the buffer originalfilename.txt in emacs and if you save it you will have a new file with that name.

Using dired to change the filename updates all the buffers that are using that file.

dired gets some hate, I think because it creates a lot of buffers and they tend to stick around, but it's never bothered me.

skydhash · 32m ago
> dired gets some hate, I think because it creates a lot of buffers and they tend to stick around, but it's never bothered me.

There's a variable in recent versions of emacs that deals with that

  dired-kill-when-opening-new-dired-buffer
I'm glad it's a switch, though. I set it to true, but I can see someone being used to the dired command to go to a specific directory, and then manage things with dired-insert-subdir.
partdavid · 2h ago
I'm also an emacs user in the habit of using the shell for file management, and I just deal with this mismatch. It hasn't been annoying enough for me to solve by switching to something else. But then again, I guess I don't do a lot "file management", whatever that really means.