Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have emacs in full-screen running through the terminal and split into 4 equally sized windows. Instead of using C-x o to go to the other window I would like to hardcode commands for going to each window.

Perhaps I could make the commands as follows:

  1. C-w C-i -- upper left window
  2. C-w C-o -- upper right window
  3. C-w C-k -- lower left window
  4. C-w C-l -- lower right window

  5. What can I add to my ~/.emacs file to set 4 global-key commands to switch between all 4 screens as demonstrated above?

share|improve this question
up vote 1 down vote accepted

You may write a simple function like that and set key bindings.

(defun select-nth-window (n)
  "Focus Nth window"
  (set-frame-selected-window (selected-frame)
  (set-frame-selected-window (selected-frame)
                 (nth n (window-list))))

(global-set-key (kbd "C-w C-i") '(lambda ()
                   (select-nth-window 0)))
(global-set-key (kbd "C-w C-o") '(lambda ()
                   (select-nth-window 2)))
(global-set-key (kbd "C-w C-k") '(lambda ()
                   (select-nth-window 1)))
(global-set-key (kbd "C-w C-l") '(lambda ()
                   (select-nth-window 3)))

Edit: I don't know how to save window layout but Emacs Wiki: Session Management may help you.

You also could learn more about emacs lisp from An Introduction to Programming in Emacs Lisp and Emacs Lisp Reference Manual.

share|improve this answer
What can I add to my .emacs file to start emacs with 4 windows like this? Also, where do you acquire the knowledge to find these functions? – CodeKingPlusPlus Jun 21 '13 at 21:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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