Emacs dired-mode as a file manager
42 comments
·May 23, 2025susam
JCattheATM
> 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.
bradain
Emacs isn't really a follower of the unix philosophy since it's more a hold-over from the world of lisp machines.
Emacs also eschews the "everything is a file" philosophy of unix (programs in emacs are just lisp functions) and the idea of storing / transmitting data as plain text, instead using lisp data structures to do that.
Lisp itself is kind of antithetical to the unix philosophy too when compared with C. Lisp is presents an extremely simple, totally consistent core that is extremely difficult to implement efficient compilers for. C on the other hand was designed from the outset with the goal of being easy to write compilers for. Requirements for having function prototypes ahead of uses, having all variables declared at the top of a function, etc were done to make it easier to implement. Almost a perfect example of worse is better, really.
Check out the unix hater's handbook if you haven't, that sums up pretty nicely the world that emacs hails from.
chungy
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.
binary132
I think you would find that the primitives emacs lets you compose are not so different from the primitives bash lets you compose, just more syntactic and less, you know, clunky. :)
sixtyj
So it is similar to Total Commander, but in editor. Or Double Commander…
mimischi
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
nothrabannosir
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.
entropie
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...
julienchastang
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
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
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.
ww520
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
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).
ww520
Yes. dired-find-file-other-window is the one I found annoying. It moves the cursor/focus to the other window, and it keeps opening new split windows. If I ran the cmd 3 times, it would open 3 new split windows. Really annoying.
I want the cursor/focus to remain on the dired window so that I can go down the file list and see the file content on the other window. Ctrl-n and ctrl-o are all I need to do.
skydhash
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.
ww520
Yes, that works but the view window takes up the whole frame. I want the dired window remains and the cursor/focus to remain in the dired window so that I can go down the file list and see the file content on the other window. Ctrl-n and ctrl-o are all I need to do.
skydhash
I got you. I like to be focused on a single thing so whatever is in front of me is relevant to the current task: Either selecting files or viewing them. So I've never been a fan of the file explorer windows/dock in most editors and IDEs.
In Vim, I use vinegar, which bind the minus key to display the file's directory in netrw and in netrw, go up.
perihelions
> "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
If you just do C-x C-f, M-n to get the "next completion" gives you the file at point.
mrechsteiner
[dead]
ews
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.
90s_dev
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?
shwouchk
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
teddyh
Slight nitpick: It’s no longer called a “MIME Type”, it’s now called an “Internet Media Type”.
paulyy_y
The insanity of trying to shoehorn everything into emacs, even calling it an OS, is purely beyond.
bigdict
Once you realize that elisp is a better shell programming language than bash, it ceases to appear insane.
hollerith
I much prefer them to the people that try to shoehorn everything user-facing into the browser.
internet_points
s/browser/llm
snapdaddy
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
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
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.
hollerith
I like to call it a general interface to information.
timewizard
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.
TacticalCoder
[dead]
SoftTalker
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
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
Just because you've never felt the need doesn't mean you aren't stuck in a local minimum.
trey-jones
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
> 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
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.
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>.