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?

  • 1
    See emacs.stackexchange.com/q/17872/4068 for previous answers from bmag and Stefan for variables that modify emacs behaviour. Also 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 8 '17 at 14:40
  • The attached link is invalid. – Manoel Vilela Nov 9 '17 at 8: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 9 '17 at 11:26
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 :)

  • 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 7: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: github.com/emacs-mirror/emacs/blob/… – Manoel Vilela Nov 13 '17 at 2: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 7:15
  • P.S. I can neither upvote nor accept answers since I don't have enough reputation. – datv Nov 14 '17 at 7: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 8: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)
New contributor
Yashesh Bhatia is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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