6

When strike C-x 3, a new window and buffer will open to the right of the current buffer.

How could set it open to the left of the current?

Drew
  • 77,472
  • 10
  • 114
  • 243
Wizard
  • 1,251
  • 6
  • 17
  • You mean you want the selected window being the one on the right? – JeanPierre Nov 19 '19 at 06:32
  • Yes, I want my focus window on right and the new opened window to its left. @JeanPierre – Wizard Nov 19 '19 at 06:42
  • Here is an example of how to display a buffer in any one of four directions, i.e., above, below, left, and right: https://stackoverflow.com/a/50867710/2112489 – lawlist Nov 19 '19 at 06:49

2 Answers2

9

C-x 3 is bound to the function split-window-right, that splits the current window horizontally, selecting the left window. We can define a function split-window-left that calls it then change the selected window to the one on the right, eg using other window:

other-window is an interactive compiled Lisp function in ‘window.el’.

(other-window COUNT &optional ALL-FRAMES)

Select another window in cyclic ordering of windows. COUNT specifies the number of windows to skip, starting with the selected window, before making the selection.

(defun split-window-left (&optional size)
  "Like split-window-right, with selected window on the right."
  (interactive "P")
  (split-window-right size)
  (other-window 1))

We keep the same semantics for the optionalsize argument: give the width of the left window if positive, of the right one if negative.

You can bind this to C-x 3 (overriding the binding to split-window-right) or to another key, eg C-x 9:

(global-set-key  "\C-x9" 'split-window-left)
JeanPierre
  • 7,465
  • 1
  • 20
  • 39
1

This might do the trick, and it's built in:

(split-window-right-and-focus)

Split the window horizontally and focus the new window.

Tim Stewart
  • 111
  • 4