Emacs has a complex mechanism to handle the vicissitudes of function key and modifier encodings on various terminal types. It doesn’t work out of the box in all cases. The following settings should work on your terminal:
(define-key input-decode-map "\e\eOA" [(meta up)])
(define-key input-decode-map "\e\eOB" [(meta down)])
(global-set-key [(meta up)] 'transpose-line-up)
(global-set-key [(meta down)] 'transpose-line-down)
You should be able to use (kbd "<M-up>")
and (kbd "<M-down>")
in place of [(meta up)]
and [(meta down)]
, as long as you’ve done the step of telling Emacs (via input-decode-map
) about the escape sequences that your terminal uses to encode these key combinations.