简体   繁体   中英

OSX + Terminal.app + Emacs + make command key operate as meta

I'm on OSX Lion

I running emacs inside of Terminal.app

I want command-x to result in Mx (and in general, command -> M)

I have tried the following solution and they're not what I want:

What I want, is only inside of Terminal.app (or only inside of emacs), to bind the command key to meta. How do I achieve this?

fwiw - iterm2 requires a bit of additional attention to make cmd map to meta and play well with other applications. (cmd-tab behavior, cmd-space (quicksilver), etc.) here's my config which biases towards left-handed cmd-tab operation, etc.

within iterm2

  • (preferences >> keys tab) left cmd needs to be remapped to left-option
  • global shortcut keys set the following to "do not remap modifiers"
    • cmd-space (makes quicksilver work normally)
    • ctl-cmd-space (makes my omnifocus binding work)
    • cmd-` - cycle windows
    • cmd- -> (right arrow) makes tab cycling work correctly
  • (preferences >> profiles tab >> keys subtab) i map left option-key to escape. this provides the expected behavior for most meta expecting shell applications

this results in using right-cmd for certain local iterm tasks but toggling between applications with different keybindings, etc, does the usual left-handed operational things and retraining my muscle memory was minimized.

First, in Terminal's preferences, on the Settings tab, on the Keyboard subtab, there's an checkbox "Use option as meta key". It's not exactly what you asked for, but it's built in.

I was thinking that Cocoa Key Bindings system might help here, but according to my searches, it deliberately doesn't permit remapping Command. This page has a lot of information about the customizability of Cocoa's key bindings and text defaults.

I use cmd-key-happy ( https://github.com/aim-stuff/cmd-key-happy ) which allows you to swap alt and commmand keys for specific applications.

So in Terminal.app you can use all the meta modifiers as expected, while the Mac-specific commands (copy, paste, close, new) work with alt instead.

FWIW: I found another way to accomplish this that's better for me (this is in iTerm2).

I wanted emacs to behave the same in the terminal as it does in a window. I have my emacs set to use the command key as the meta key via the following snippet:

;;osx keys
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'alt)

So to get my command key behaving like a meta key in iTerm2, I went to preferences->profiles->->keys and added new keys. The only problem is you have to do it for each key separately, but you can say for example,

keyboard shortcut: <type command-p>
action: send escape sequence
Esc+: p

So I did that for my most frequently used meta+ keys. It would be nice if there was another set of radio buttons like there is for option/alt, where you could just say "command key acts like Esc+".

Why are you insistent on Terminal.app? Just install iterm2 and move on with life.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM