A Log In The Life.

May The Code Be With You !

iTerm2, Emacs で meta キー + arrows

はじめに

多くの場合 iTerm2 に Left option(⌥) key acts as: +Esc を設定しておけば option キーをMeta キーとして使えます。
ですが、キーとの組み合わせではうまくいかないこともあるようです。
分割した Window を移動しやすいようにいかの設定をしてますが、これがうまく動いてくれませんでした。

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

どうやら、Meta キーではなく Esc キーを送っているようです。

環境

  • Mac OS X 10.7.3
  • iTerm 1.0.0.20120203
  • GNU Emacs 23.3.1

iTerm

iTerm の Preferences > Profiles > Keys で以下の設定をしています。

  • Left option(⌥) key acts as: +Esc

Hack

Preferences > Profiles > Keys > Profile Shortcut Keys: に以下の設定をします。

Keyboard Shortcut : ⌥↑
Action : Send Escape Sequence
Esc+ [1;4A
Keyboard Shortcut : ⌥↓
Action : Send Escape Sequence
Esc+ [1;4B
Keyboard Shortcut : ⌥→
Action : Send Escape Sequence
Esc+ [1;4C
Keyboard Shortcut : ⌥←
Action : Send Escape Sequence
Esc+ [1;4D

これで Emacs に Esc キーではなくちゃんと Meta キーを送ってくれます。

Appendix

  • Emacs + paredit under terminal (Terminal.app, iTerm, iTerm2)

http://offbytwo.com/2012/01/15/emacs-plus-paredit-under-terminal.html