On my work laptop, a Powerbook, I use a Carbon build of Emacs’ CVS HEAD. I use the Command key as Meta, since "the key to the left of space is Meta" is utterly ingrained at the muscular level. But when I SSH to a remote host in a Terminal window, the Command key is taken by Terminal.app, and the Option key acts as Meta. This wouldn’t be a problem if I didn’t use fill-paragraph (bound on M-q) so often. Since Command-Q quits Terminal, I lose all of my SSH sessions if I accidentally use the Command key instead of the Option key. Evil! Just the same, trying to copy some text with M-w results in the terminal window closing. Ugh.

Another problematic key is M-p, which is often bound (in the minibuffer, in shell buffers, etc.) to "give me the previous element in my input history." Command-P brings up the print dialog box, which is pretty much never what I want to happen.

Here’s a shell command which overrides those key bindings, so I don’t do so much damage:

defaults write NSGlobalDomain NSUserKeyEquivalents \
   '{"Quit Terminal" = "@$Q"; "Close" = "@$W"; "Print..." = "@~P";}'

This places the Quit command on Command-Shift-Q, the Close command on Command-Shift-W, and the Print command on Command-Option-P. You’ll have to quit and re-launch Terminal.app for these to take effect.

Comments

  1. This is great, thanks!

    Of course, the best thing would be if Apple could finally remove that Terminal.app bug where there's a missing preference for "use command as meta"...

    k, 30 May 2008

  2. One slight problem though. For me, this rewrites the defaults for Any program...

    k, 31 May 2008

  3. defaults write com.apple.Terminal NSUserKeyEquivalents '{"Quit Terminal" = "@$Q"; "Close Window" = "@$W"; "Print..." = "@~P";}'

    keeps it within Terminal.app though. (Sorry for posting thrice...)

    (Found the solution at http://www.hoboes.com/Mimsy/?ART=248 )

    k, 31 May 2008

  4. Hank

    what that does on os x 10.5.5 is ADD the command to the set that allows me to quit the app. so when i throw in something like "Quit Terminal" = "@$Q", it'd result in have both @Q and @$Q commands work as the quit command. how do i remove the commandQ completely and just use @$Q?

    Hank, 9 November 2008

  5. Henry

    Thanks a lot for posting this. I've accidentally closed Firefox with @Q many times when I meant to press @W. I tried the command you posted, but for me, it merely ADDS an addition Quit command. So now I can quit Firefox by pressing @[HTML_REMOVED]Q or @Q (When I really wanted to get rid of @Q).

    This is what I used: defaults write NSGlobalDomain NSUserKeyEquivalents '{"Quit Firefox" = "@$Q";}'

    Henry, 5 July 2009

Add a comment

Posting...