I use WindMove in Emacs 24.1 to move around multiple windows using keyboard shortcuts:
(global-set-key (kbd "M-J") 'windmove-left) ; move to window on the left
(global-set-key (kbd "M-L") 'windmove-right) ; move " " the right
(global-set-key (kbd "M-I") 'windmove-up) ; move " " above
(global-set-key (kbd "M-K") 'windmove-down); ; move " " below
Is there a way to associate these WindMove keyboard shortcuts with char run mode on an ansi-term? I would like to avoid having to switch into line run mode for moving between windows. After a while it becomes tedious to type C-c C-k and C-c C-j back and forth to go into/leave the terminal.
The code below will work for you. It uses the Emacs advising mechanism, which allows a user to dynamically change a function’s behavior without modifying its source code directly. In this case, it is used to make the
winmove-*functions runterm-char-modebefore executing their original definition. If you are also using other window-selecting functions, such asother-window, besideswinmove-*, you can advise those functions in the same way. Refer to Advising Functions for details on the advising mechanism.The code also handles the issue related to the
term-raw-mapkeymap.term-raw-mapis not defined untilterm.elis fully loaded (or M-xansi-term is executed). So you should add the(define-key term-raw-map ...)forms to theterm-load-hookhook, which is automatically run whenterm.elis loaded, instead of putting them at the top level of the init file.