How can I switch focus after buffer split in emacs?

Solution 1:

You can switch between buffers with C-x o. As to do that automatically I don't think there is an existing command for that.

Solution 2:

You can do it like this:

(global-set-key "\C-x2" (lambda () (interactive)(split-window-vertically) (other-window 1)))
(global-set-key "\C-x3" (lambda () (interactive)(split-window-horizontally) (other-window 1)))

In Emacs 24.3.1 it works if you change the argument 1 for 0.

Solution 3:

!!!DO NOT USE THIS ANSWER!!! -- as pointed out in the comments, advising split-window can lead to undesired side-effects.

I recommend Bozhidar Batsov's answer instead.


Put the following in your .emacs file:

(defadvice split-window (after move-point-to-new-window activate)
  "Moves the point to the newly created window after splitting."
  (other-window 1))