I set Alt as the windmove key to switch between frames in Emacs under Mac.
(windmove-default-keybindings 'meta)This works fine for the GUI version Emacs (the one with the widgets and other windows decorations), but not if I start emacs with emacs -nw from a Mac Terminal.app. For example, if I split window first with C-x 2, and press Alt + <Down>, then Emacs reports
ESC + <Down> is undefined. Can anyone help?
Emacs version is 24.4 installed from brew install.
2 Answers
It seems the easiest way is to just install iterm2. And in the Preferences > Profiles tab. Select your profile on the left, and then open the Keyd tab and set the option key to +ESC.
Then in your emacs setup set the key manually,
(global-set-key (kbd "ESC <up>") 'windmove-up)
(global-set-key (kbd "ESC <down>") 'windmove-down)
(global-set-key (kbd "ESC <right>") 'windmove-right)
(global-set-key (kbd "ESC <left>") 'windmove-left)I suggest you to use iterm2 since it's a better terminal. But in case you want to use terminal.app don't forget to check the Use option as meta key in Preferences > Settings > Keyboard, it works to some extend with the default emacs.
The same issue is true for Ubuntu when I use terminator as a terminal.
You can work around this problem by using the win-switch package which works fine in every case for me. Here you have a simple configuration that you can put in your init file (.e.g.: .emacs):
;; install win-switch package using package manager
(if (package-installed-p 'win-switch) nil (package-install 'win-switch))
;; my favourite quick keybindings
(global-set-key (kbd "M-<left>") 'windmove-left)
(global-set-key (kbd "M-<right>") 'windmove-right)
(global-set-key (kbd "M-<up>") 'windmove-up)
(global-set-key (kbd "M-<down>") 'windmove-down)The win-switch package has many other powerful utilities which are further detailed in the commentary part of the code.