Hans Maulwurf
Hans Maulwurf

Reputation: 81

Kill dired buffers immediately in Emacs

How can I achieve that when I search for a file with C-x d the buffer which showed me the possible completions will be killed automatically after opening the desired file?

Upvotes: 3

Views: 1594

Answers (3)

yuri
yuri

Reputation: 81

In Emacs version>28 you can set new custom variable dired-kill-when-opening-new-dired-buffer to t to achieve this behavior.

Upvotes: 6

Tino
Tino

Reputation: 454

Add the following into your .emacs file:

(eval-after-load "dired"
  (lambda ()
    (put 'dired-find-alternate-file 'disabled nil)
    (define-key dired-mode-map (kbd "RET") #'dired-find-alternate-file)))

Then, when you visit the file in Dired using RET, you are calling dired-find-alternate-file, so that the Dired buffer will be killed.

Upvotes: 0

phils
phils

Reputation: 73365

Simply use a in dired to open the file at point -- the dired buffer will be killed, and the chosen file visited in its place.

Upvotes: 5

Related Questions