Sometimes I use dired to view or edit several files in one folder, one after the other. Dired is open in one window, and I open the files in another window by typing o
in dired. When I finish with one file and kill the associated buffer, I would like focus to switch back to the dired window, instead of remaining in the window that used to hold the buffer I just killed.
1 Answer
C-x 4 0
is bound to kill-buffer-and-its-window
. It should do just what you're asking for in this context: kill the file buffer you're visiting and delete its window, putting you back in the previously selected window, which is the Dired window.
(Otherwise, as @muffinmad said in a comment, if you don't need to view the visited file in a separate window, but can instead view it in the window that Dired was using, then just use f
or RET
followed by C-x k
.)
-
It must be
C-x k
instead ofC-x 0
becauseC-x 0
will delete window but we want to kill buffer and stay in current window. Commented Jun 8, 2019 at 19:11 -
-
This is what I need, thanks! I was originally thinking of something that would keep the second window open with another buffer in it, but actually there's no reason I need that. Commented Jun 9, 2019 at 23:47
<RET>
instead ofo
will open file in same window and after killing the file buffer dired buffer will remain in current window.