Having marked a bunch of files in dired-mode, if I wanted to open all them at once, I press F. But, the problem is, all the selected files opens in their own separate window and now i've at least as many windows as the files I marked in dired-mode.

Is it possible to change this behaviour to open only the window of the topmost file in dired listing (while also opening the rest of the selected files in dired-mode, but not opening each of them in a separate window)?

2 Answers 2


If you want that to happen all the time, try:

(define-key dired-mode-map (kbd "F") (lambda ()
                       (find-file (car (dired-get-marked-files)))))

If you want all the files to get opened, you could try this variation:

(define-key dired-mode-map (kbd "F")
  (lambda ()
    (mapc #'find-file (reverse (dired-get-marked-files)))))
  • this does not open multiple files. Opens only one file which my point is on Commented Oct 23, 2016 at 3:46
  • Isn't that what you asked for? Open only the topmost file? Commented Oct 23, 2016 at 12:02
  • Ah I meant only the window of the topmost file to open, the rest of the buffers should be open in the background. By default it opens a new window for all buffers instead of opening just one. Cluttering my emacs frame. Commented Oct 23, 2016 at 15:47
  • There seems to be one minor problem. Your code works fine, except it also opens a new buffer empty buffer associated with the topmost file in the directory. Check here :- imgur.com/a/kSRwq (check first file in the minibuffer). Can I somehow stop this from happening ? and open only the first file i've selected Commented Oct 23, 2016 at 15:55
  • How about the revised version above? Commented Oct 23, 2016 at 17:36

Spacemace Config

Based on the awesome solution by @John Kitchin, I implemented in spacemacs at the user-config function. You can use one of the two functions below depending on your preference.

  • Using the spacemacs specific keybinding based on (general).
   (setq dired-dwim-target t)

   ;; --- another may to achieve ----
   (defun open-several-files-at-once ()
     (mapc #'find-file (reverse (dired-get-marked-files))))
   (spacemacs/set-leader-keys "o" 'open-several-files-at-once)

  • Method #2, Using the mapping based on natural emacs (works for any framework)
   (define-key dired-mode-map (kbd "C-c C-o")
     (lambda ()
       (mapc #'find-file (reverse (dired-get-marked-files)))))
  • Be aware to map to free-keys not used by dired.
  • You should set (setq dired-dwim-target t) to open in same tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.