Is there a configuration option in Magit that will force the "git status" window to always appear in a vertical split? I didn't see anything about that in the documentation, and Google was rather useless.
4 Answers
You can control how Magit — and many other modes that open new windows — divide a window by customising the variables split-height-threshold
and split-width-threshold
, and, if you need more control, changing split-window-preferred-function
. These are all documented in the Elisp reference, and see other questions here, e.g. Algorithm on deciding splitting vertically or horizontally
For a reason that I, and others, find puzzling, the default function prefers to split horizontally if possible, so in your case you might want to tweak the variables so that split-height-threshold
is greater than your window's maximum height, and so that a window is never split horizontally.
For me following solution worked out (Emacs 26.1): I customized
split-height-threshold
to 80
and split-width-threshold
to 160
.
It's from Spacemacs config. Since then my magit buffer always open as
vertical split, as well as diff buffers.
I needed to configure the split-width-threshold
to 0
and split-height-threshold
to nil
as split-window-sensibly
recommends:
In order to not split WINDOW vertically, set (or bind) the variable
split-height-threshold
to nil. Additionally, you can setsplit-width-threshold
to zero to make a horizontal split more likely to occur.
I asked a similar question recently. You could try this.
(add-to-list 'display-buffer-alist
`(,(rx bos "*magit:")
(display-buffer-reuse-window
display-buffer-below-selected)
(reusable-frames . visible)
(side . bottom)
(window-height . 0.4)))
But I don't use magit frequently and therefore I don't know if this would also open buffers in a vertical split, that you don't want to open that way.
split-window-preferred-function
and similar? These are in the manual, and control how Emacs splits windows for many different modes; this includes Magit, as far as I can see.