When I use dired and move to another directory, I end up with a lot of buffers. How can I just use one buffer for navigation? reddit / emacs ---------------------------------------------------------------------- Status-Detective-783 · 2022-02-24 06:43 ---------------------------------------------------------------------- mkthree · 2022-02-24 07:04 You might want to use `a` (`dired-find-alternate-file`) instead of RET (`dired-find-file`). The former will kill the current Dired buffer before visiting the directory. ---------------------------------------------------------------------- Danrobi1 · 2022-02-24 07:39 To add to what u/mkthree said. There's also `i` which will expand the `directory` in the same `dired-buffer`. Run `dired-kill-subdir` to kill the expanded `directory`. ---------------------------------------------------------------------- olivuser · 2022-02-24 08:08 Just to add to this, because it is my current workflow when in dired. It is possible to hide a subditectory's contents (I believe it is C-$, not sure though). Thus, when using i, hiding subidrectories can declutter your buffer and also speedup killing the subdirs not required anymore. ---------------------------------------------------------------------- yep808 · 2022-02-24 08:12 Try dired-single. Works exactly as you wanted. ---------------------------------------------------------------------- Danrobi1 · 2022-02-24 09:06 Yep. There's a `dired-hide-subdir`. Good call. ---------------------------------------------------------------------- ZZhanChi · 2022-02-24 12:51 This is what I use to use dired in a single buffer automatically: ```lisp (defun fk/dired-up-directory () "`dired-up-directory' in same buffer." (interactive) (find-alternate-file "..")) (defun fk/dired-find-file (orig-func &rest args) "If selected file is a directory, open it in same buffer, otherwise, open the file in a new buffer." (let ((file (dired-get-file-for-visit))) (if (file-directory-p file) (apply 'dired-find-alternate-file args) (apply orig-func args)))) (advice-add 'dired-up-directory :override 'fk/dired-up-directory) (advice-add 'dired-find-file :around 'fk/dired-find-file) ``` source: https://github.com/KaratasFurkan/.emacs.d#dired-1 ---------------------------------------------------------------------- organic-bookworm · 2022-02-24 13:04 As a related note to consider, multiple Dired buffers may act as a sort of explicit file metadata cache, when fetching directories over slow media. ---------------------------------------------------------------------- The-Blackbeard · 2022-02-24 13:14 Emacs 28.1 will have the option `dired-kill-when-opening-new-dired- buffer` ---------------------------------------------------------------------- 00-11 · 2022-02-24 18:06 [Dired+](https://www.emacswiki.org/emacs/DiredPlus) gives you an easy way to do what you want. `C-M-R` (aka `C-M-S-r`), bound to `diredp- toggle-find-file-reuse-dir`, toggles whether Dired `find-file` etc. commands *reuse directories*. A prefix arg specifies directly whether or not to reuse. If its numeric value is non-negative then reuse; else don't reuse. To set the behavior as a preference (default behavior), put this in your init file, where `VALUE` is 1 to reuse or -1 to not reuse: (diredp-toggle-find-file-reuse-dir VALUE) ---- You can of course also just use `a` anytime, to not create a new buffer. But this toggle lets you set and keep the behavior till you change it (toggle again), and it affects multiple Dired commands that visit a directory. ---------------------------------------------------------------------- Status-Detective-783 · 2022-02-24 18:24 Cool thanks! And just for my newbie notes, prefix arg can be specified as `C-u -1 M-x dired RET`, which gives you a confirmation of dired listing switches set to `-al`, hit `RET` and then on to the dired interaction. Of course, that's more than needed given the easier options, but good to understand. :) ---------------------------------------------------------------------- 00-11 · 2022-02-24 19:05 `C-M-R` just determines whether, from now on (till you toggle again), Dired reuses buffers, as opposed to creating new ones. It doesn't change the interactive behavior of commands such as `dired` - so yes, you can still use a prefix arg with them, to set the `ls` switches.