Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

Whenever I open more than one file at the same time with emacs, as in:

emacs foo.dat bar.dat

The window that opens will be split between the two files (a buffer for each file). I would like to avoid that. Is there a line I can place in my .emacs file to keep that from happening? I would like emacs to only open one buffer in the window, no matter how many files I'm loading.

I'm using version 23.1.1.

share|improve this question
up vote 4 down vote accepted

The following code works for me (add into ~/.emacs):

(add-hook 'emacs-startup-hook
          (lambda () (delete-other-windows)) t)

The emacs-startup-hook is run after loading the init file and processing the command line, so all files have been loaded and opened; calling delete-other-windows leaves just one of them visible (normally the last one given on the command line).

Note: you might also need to customize inhibit-startup-screen and set it to t for the above to work.

share|improve this answer
It's unlikely to matter in this case, but you should always use add-hook for hooks, rather than manipulate the list directly. In an unrelated note, curiously, if inhibit-startup-screen if left off, you get exactly two windows: one for the last file on the command line and one with the startup screen. – Gilles Sep 27 '10 at 21:08
@Gilles thanks, fixed – Riccardo Murri Sep 28 '10 at 7:33
Yeah, both work great. Thanks. – Malabarba Sep 28 '10 at 11:37

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.