(windmove-default-keybindings 'meta)
provides commands to move between emacs windows (eg M-<up>
to move up a window). They are working fine for me when emacs -nw
is run in a terminal, but in tmux they fail.
The individual commands work, eg winmove-up
; and when run they tell me:
You can run the command winmove-up with
M-<up>
But to M-<up>
itself, I get:
ESC <up>
is undefined
Same problem with any other prefix key (shift
, control
).
This is in tmux 1.9a/emacs 23.3.1 and tmux 2.0/emacs 24.5.1 under Ubuntu 12.04 and 14.04 respectively. In the first case I'm using "gnome-terminal". In the second ... I'm ssh'ing into a server and the TERM environment variable is "xterm". Once I start tmux, it becomes "screen-256color"; that's because I've used set -g default-terminal
Ideas?
With help from @Random832, the answer to this question and the first answer to this one, along with some useful information about how emacs handles function keys in the answer to this question, there are two approaches:
Approach #1: In your .tmux.conf
, use xterm-keys on
, but also, if you are using 256 colors, then set your default-terminal
correctly:
set -g xterm-keys on
set -g default-terminal "xterm-256color"
Approach #2: At a terminal, run cat
and then type M-<up>
etc to find the output. In my case it was: ^[[1;3A
(and B & C & D). Then, use this code in your .emacs
file:
(add-hook 'term-setup-hook
'(lambda ()
(define-key function-key-map "\e[1;3A" [M-up])
(define-key function-key-map "\e[1;3B" [M-down])
(define-key function-key-map "\e[1;3C" [M-right])
(define-key function-key-map "\e[1;3D" [M-left])))
Note that this second approach also works for other prefix keys (Shift
, Control
) and that this same problem appears in screen
.
Also note that all seems to work well except for in the gnus
article summary buffer, where M-<up>
and M-<dn>
behave like <up>
and <dn>
(though M-<rt>
and M-<lft>
work fine).