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)?


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 – Chakravarthy Raghunandan Oct 23 '16 at 3:46
  • Isn't that what you asked for? Open only the topmost file? – John Kitchin Oct 23 '16 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. – Chakravarthy Raghunandan Oct 23 '16 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 – Chakravarthy Raghunandan Oct 23 '16 at 15:55
  • How about the revised version above? – John Kitchin Oct 23 '16 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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