Windmove is a library built into GnuEmacs starting with version 21. It lets you move point from window to window using Shift and the arrow keys. This is easier to type than ‘C-x o’ and, for some users, may be more intuitive. To activate all these keybindings, add the following to your InitFile:

(when (fboundp 'windmove-default-keybindings)

The ‘fbound’ test is for those XEmacs installations that don’t have the windmove package available.

Using Meta

If you are a PcSelectionMode or CuaMode user, however, you will need to use your own keybindings, since shift plus arrow keys are used to extend the selection. For CuaMode it may be natural to use

(windmove-default-keybindings 'meta)

This will override ‘M-left’ and ‘M-right’ but these are duplicated by ‘C-left’ and ‘C-right’ which are probably more natural for a CuaMode user.


Some terminals do not support modified arrow keys. To use a prefix instead of a modifier, add something like the following to your InitFile.

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

See WindowNavigation for a similar piece of code, but written from scratch.

For OSX, see Emacs windmove and Mavericks

Ignore Errors

When you run for instance windmove-left and there is no window on the left, windmove will throw exception (and if you have debug-on-error enabled) you will see Debugger complaining. To prevent this situation you can use ignore-errors macro before running windmove function, here is helper function:

(defun ignore-error-wrapper (fn)
  "Funtion return new function that ignore errors.
   The function wraps a function with `ignore-errors' macro."
  (lexical-let ((fn fn))
    (lambda ()
        (funcall fn)))))

and you can add windmove keybinding with it:

(global-set-key [s-left] (ignore-error-wrapper 'windmove-left))
(global-set-key [s-right] (ignore-error-wrapper 'windmove-right))
(global-set-key [s-up] (ignore-error-wrapper 'windmove-up))
(global-set-key [s-down] (ignore-error-wrapper 'windmove-down))


If you want to use windmove on XEmacs, please read:


Is possible to make windmove jump between frames?

Yes. To jump between frames, see FrameMove (which can integrate seamlessly with windmove).

Look also at ‘M-x next-multiframe-window’ command and possibly bound it to a handy keybinding! There also exists: ‘M-x previous-multiframe-window’, so it will be better than the default: `other-window` (C-x 5 o).