Emacs, switch to previous window

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)


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)


If you work with multiple emacs windows (>3) a lot and you will want to save some keystrokes add this to your init file and you'll be better off:

(defun frame-bck()
  (interactive)
  (other-window-or-frame -1)
)
(define-key (current-global-map) (kbd "M-o") 'other-window-or-frame)
(define-key (current-global-map) (kbd "M-O") 'frame-bck)

Now just cycle quickly thru the windows with M-o


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)

Tags:

Emacs