24

I am very very new to emacs. I want something like this. Every time I open a new buffer, it should split current winodow vertically. How should I change .emacs file. Please provide some pointers.

6
  • 1
    What do you mean? When Emacs opens, it has a specific buffer opened up, vertically split? Or when you open a specific buffer, it splits vertically? Or something else.
    – zck
    Nov 23, 2013 at 20:46
  • @Robin Green is correct. I like the emacs-startup-hook because it gives me more control over the location where it appears inside my user configuration files: (add-hook 'emacs-startup-hook (lambda () (split-window-right) )) . And, of course, you have all the options in the world to put inside it -- e.g, split-window-vertically; split-window-horizontally; do the hokey pokey and turn yourself around . . ., etc.
    – lawlist
    Nov 24, 2013 at 0:11
  • 1
    Please specify exactly how you normally "open a new buffer" so that we can understand the exact result you want to achieve -- i.e., what are the exact steps that you take when "opening a new buffer". For example, are you using something like (find-file "foo.txt") or (get-buffer-create "foo.txt")? Also, do you want one window on the left and one window on the right? Or, do you want one window on top, and one window on bottom? And which window do you want your new buffer to appear in -- top, bottom, left, or right? And what do you want to appear in the other window?
    – lawlist
    Nov 24, 2013 at 7:17
  • 1
    Also, what happens when you already have two windows open and you open a new buffer? Do you want 3 windows or 4 windows total, or do you want the new buffer to take over an existing window -- if so, what window should it take over -- left, right, top or bottom -- and what buffer should appear in the other window when opening a new buffer? There are quite a few options based upon your personal preferences.
    – lawlist
    Nov 24, 2013 at 7:27
  • 2
    possible duplicate of Setting Emacs Split to Horizontal
    – Tony
    Oct 3, 2014 at 11:19

4 Answers 4

22

You know that you can do this manually with C-x 3 right? So we can use this fact to learn how to add the command to do this to .emacs.

We just need to find out what the function is. So let's do C-h k C-x 3 to find the help for C-x 3. That shows:

C-x 3 runs the command split-window-right, which is an interactive compiled Lisp function in `window.el'.

So, open .emacs (C-x C-f ~/.emacs), go to the end of the file and add:

(split-window-right)

Then save the file, restart emacs and it should work. I just tested it.

4
  • 2
    Every time I open a new buffer, it should split the current window vertically. and btw this says "An error occurred while loading `~/.emacs" Nov 24, 2013 at 5:36
  • @username_4567 you must have made a mistake because I don't get an error. What is your error? Nov 24, 2013 at 8:02
  • 2
    Has split-window-right been around a lengthy period of time going back several Emacs versions? If it has been (i.e., if the issue is not related to an unrecognized function available only in subsequent Emacs versions), then yes, there is/are one or more error(s) higher up in the user .emacs file.
    – lawlist
    Nov 24, 2013 at 14:53
  • 3
    This answers how to open a new window, but not the OP's question of how to open a new buffer in a vertically split window. That's different. C-x 3 splits the window vertically, and (split-window-right) just makes Emacs always open with two windows, vertically split. Right?
    – James
    Apr 24, 2018 at 17:11
20

I don't remember the exact route I followed to get this, but I have the following configuration to suggest to Emacs that it should split the frame vertically rather than horizontally when Emacs has the choice (eg when bringing up help).

This seems to work fine on my widescreen monitors.

(setq split-height-threshold nil)
(setq split-width-threshold 160)
2
  • 2
    Worked for me on a 1280x800 screen reducing the 160 to 80
    – user234461
    Jun 10, 2015 at 21:42
  • This did not work for me on a 1080p external monitor. Dec 10, 2018 at 10:41
4

Add This to .emacs to split windows vertically as default opening a new buffer in other windows

(setq
   split-width-threshold 0
   split-height-threshold nil)
0

From this post on reddit you can set this explicitly for ediff.

(custom-set-variables
 '(ediff-window-setup-function 'ediff-setup-windows-plain)
 '(ediff-diff-options "-w")
 '(ediff-split-window-function 'split-window-horizontally))

This has the advantage that it doesn't impact other splits.

Your Answer

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

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