Emacs, switch to previous window

In Emacs, C-x o takes me to the next window.

What keyboard macro takes me to the previous window in Emacs?


Solution 1:

You might also want to try using windmove which lets you navigate to the window of your choice based on geometry. I have the following in my .emacs file to change windows using C-x arrow-key.

(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)

Solution 2:

That'd be C-- C-x o

In other words, C-x o with an argument of -1. You can specify how many windows to move by inserting a numeric argument between C-u and the command, as in C-u 2 C-x o. (C-- is a shortcut for C-u - 1)

Solution 3:

Personally I prefer to use window-number.el

To select a different window, use Ctrl-x, Ctrl-j n

Where n is the number of the window, the modeline of each window shows it's number, as shown in the screenshot.

Just download window-number.el, place it in your emacs load-path and use the following in your .emacs

 (autoload 'window-number-mode "window-number"
   "A global minor mode that enables selection of windows according to
 numbers with the C-x C-j prefix.  Another mode,
 `window-number-meta-mode' enables the use of the M- prefix."
   t)

There's another similar mode called switch-window.el which gives you big numbers in the windows... (pressing the number switches the window and reverts the display.)


(source: tapoueh.org)