3

Once upon a time, Choose Window (invoked by C-x C-b) used to always split the window vertically.

Starting from a certain Emacs version (I can't recall which one), that split is now either vertical or horizontal, depending on the containing windows aspect ratio.

Is there a way to force C-x C-b to always split vertically?

Drew
  • 75,699
  • 9
  • 109
  • 225
datv
  • 133
  • 4
  • 1
    See https://emacs.stackexchange.com/q/17872/4068 for previous answers from bmag and Stefan for variables that modify emacs behaviour. Also https://stackoverflow.com/q/23659909/2911961 gives us "I can set `split-height-threshold` to `nil` to inhibit vertical split altogether" from Romain – p_wiersig Nov 08 '17 at 14:40
  • The attached link is invalid. – Manoel Vilela Nov 09 '17 at 08:45
  • That "Choose Window" label is odd. By default, as `C-h k C-x C-b` will tell you, "C-x C-b runs the command `list-buffers`". Even taking into account that it's paraphrasing the commands, "Choose Window" doesn't make sense as a description for `list-buffers` – phils Dec 09 '17 at 11:26

2 Answers2

2

You can overwrite that keybinding with a hack like that:

(global-set-key (kbd "C-x C-b")
                (lambda ()
                  (interactive)
                  (let ((display-buffer-overriding-action ;; force window
                         '((display-buffer-reuse-window 
                            display-buffer-same-window)
                           (inhibit-same-window . nil))))
                    (split-window-horizontally) ;; split window
                    (other-window 1) ;; change it
                    (list-buffers))))

In general I prefer use ibuffer instead of list-buffers, but now is your call. Use whatever you think that is better :)

Manoel Vilela
  • 675
  • 3
  • 20
  • I put your solution in my .emacs but it now complains *"Symbol's function definition is void: split-window-right".* Is your solution version-specific? – datv Nov 12 '17 at 07:10
  • Maybe is if your emacs version is too old. Emacs currently is on version 27, I use 25.3. You can find the source of this function here: https://github.com/emacs-mirror/emacs/blob/bc511a64f6da9ab51acc7c8865e80c4a4cb655c2/lisp/window.el#L5238 – Manoel Vilela Nov 13 '17 at 02:20
  • You're right. I am still using version 23.2. I managed to copy the function to my `.emacs` and the horizontal splitting works perfectly. Vertical splitting works almost perfectly (when the vertical split occurs, the bottom window also splits horizontally). – datv Nov 14 '17 at 07:15
  • P.S. I can neither upvote nor accept answers since I don't have enough reputation. – datv Nov 14 '17 at 07:17
  • No problem at all, but I think you can accept answer yes. On my machine works perfectly the solution I attached here, probably the "almost" is something because the emacs version. Upgrade emacs is not a option for you use-case? – Manoel Vilela Nov 14 '17 at 08:29
  • Change `split-window-right` to `split-window-horizontally`, which is the original name for that command (and it remains as an alias in current versions of Emacs, so it's not going to break if you update). – phils Dec 09 '17 at 11:29
0

Credit - How to change the default split-screen direction?

The code below worked for me.

$ cat ~/.emacs
;;
;; https://stackoverflow.com/questions/7997590/how-to-change-the-default-split-screen-direction
;; C-x C-b
;; splits the window vertically
;;

;; Use (setq split-width-threshold nil) for vertical split.
;; Use (setq split-width-threshold 1 ) for horizontal split.
;; (setq split-width-threshold 1 )
(setq split-width-threshold nil)
Stefan
  • 26,154
  • 3
  • 46
  • 84