Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to be able to automate the process of opening several files in emacs under a single frame, so that the frame splits up into multiple windows. Currently I am only able to open 2 files in a single emacs frame (2 windows) by typing this in a linux terminal: emacs file1 file2. However, if I try to open more than 2 files, for example by typing emacs file1 file2 file3 then it will open file3 in one window and in the other window it will come up with a 'CRM buffer' which lists the files in the directory.

How do I get it to open more than 2 files, so that the emacs frame is split up into more than 2 windows?

Note that 'window' means window in the emacs sense, not in the MS windows sense (frames).

share|improve this question
up vote 2 down vote accepted

You can prevent the buffer list from coming up by setting inhibit-startup-buffer-menu to t as described here. However, that still does not result in more than 2 windows. Looking at the initialization code in startup.el, this does not seem to be customizable.

However, the ibuffer command ibuffer-do-view (bound to v) displays multiple buffers in the way you want. You can use it programatically. Put this in your .emacs file:

(defun view-files-in-windows ()
  (ibuffer)                      ; Activate ibuffer mode.
  (ibuffer-mark-special-buffers) ; Mark the special buffers.
  (ibuffer-toggle-marks)         ; Toggle buffers, leaving the non-special ones
  (ibuffer-do-view))             ; Show each buffer in a different window.

Then run emacs like this:

$ emacs file1 file2 file3 file4 --eval "(view-files-in-windows)"

(It fails if there are too many files and the windows would become too small.)

share|improve this answer
Nice one thanks! Is there a way to start it so that the 4 windows appear in 2 rows instead of one column? – Eddy Aug 1 '11 at 16:52
@Eddy: Please consider upvoting answers you accept, as the answer probably was helpful ;) – Nikana Reklawyks Nov 19 '12 at 5:34

I'm not too familiar with ibuffer, but if your files are sequentially numbered, grid-files-sq might be something like what you're looking for, or you can use GridLayout

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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