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
  • 75,699
  • 9
  • 109
  • 225
AbstProcDo
  • 1,231
  • 5
  • 15

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,323
  • 1
  • 18
  • 37
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