reddit / emacs

Make emacs always have two vertical windows

MosaicIncaSleds · 2022-09-30 23:08
One window is way too wide for my taste. I would rather have the same buffer twice, with a vertical split, than one wide window. Yet, on my screen, three windows at the same time is a bit much. Emacs usually opens the third window with a horizontal split, and I hate that. Say a daily note in org-roam. I would like to tell emacs there should always be two windows, opened side-by-side, not three, not one, no horizontal split. How do I do that?
stormrider-io · 2022-10-01 00:35
do you mean on startup?
cretan_bull · 2022-10-01 00:36
See [20.6.1 How display-buffer works](https://www.gnu.org/software/emacs/manual/html_node/emacs/Window-Choice.html): As a simple solution, put this in your init.el: (setq split-height-threshold nil) This will prevent emacs from ever splitting a window vertically (note: the terminology here is a bit confusing. A vertical split results in windows that span horizontally across the width). You may want to instead tweak split-height-threshold and split-width-threshold to produce sensible behavior.
CannibalismIsNatural · 2022-10-01 01:23
[This](https://www.masteringemacs.org/article/demystifying-emacs-window-manager) article is pretty good at explaining how to set up different configurations.
terminal_cope · 2022-10-01 16:25
I didn't want to disable *all* vertical splits, but just prioritize horizontal splits above vertical where they're possible, while the default `split-window-sensibly` does the reverse. My solution is to advise it to pull out its second choice of horizontal and make it the first choice: (defun my/split-window-sensibly (org-fun command &optional window) "Advice for `split-window-sensibly' to prioritize horizontal." (let ((window (or window (selected-window)))) ;; if horizontal-splittable, do it, otherwise fall back to default behavior (if (window-splittable-p window t) (with-selected-window window (split-window-right)) (funcall org-fun window)))) (advice-add #'split-window-sensibly :around #'my/split-window-sensibly) (this assumes `split-window-preferred-function` is still at its default of `split-window-sensibly`).