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) (windmove-default-keybindings))
‘fbound’ test is for those XEmacs installations that don’t have the windmove package available.
This will override
‘M-right’ but these are duplicated by
‘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 Terminal.app.
When you run for instance windmove-left and there is no window on the left, windmove will throw exception (and it you have debug-on-error enabled) you will see Debuger, to prevent that you can use ignore-errors macro before run 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 () (interactive) (ignore-errors (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).