Emacs on Mac OS X Leopard key bindings

75,004

Solution 1

Swapping CTRL and CAPS LOCK

  1. Go into System Preferences
  2. Enter the Keyboard & Mouse preference pane
  3. In the Keyboard tab, click Modifier Keys...
  4. Swap the actions for Caps Lock and Control.

alt text

Using ALT/OPTION as META

  1. In the menu bar, click Terminal
  2. Click Preferences...
  3. Under the Settings tab, go to the Keyboard tab
  4. Check the box labeled Use option as meta key

alt text

That's it! You should be well on your way to becoming an Emacs master!

Solution 2

For reference, here are the key bindings, for moving around text:

+ - move left one word
+ - move right one word
+ delete - back delete one word
Shift + + delete - foward delete one word
+ - move up one paragraph
+ - move down one paragraph
+ - move to start of current line
+ - move to end of current line
Shift + any of the above extend selection by appropriate amount

Click then drag - select text
Double-click then drag - select text, wrapping to word ends
Triple-click then drag - select text, wrapping to paragraph ends

Shift + Select text with mouse - add to selection (contiguous)
+ Select text with mouse - add to selection (non-contiguous)
+ Drag - select rectangular area (non-contiguous)
+ + drag - add rectangular area to selection
Drag selection - move text
+ drag selection - copy text

Ctrl + A - move to start of current paragraph
Ctrl + B - move left one character
Ctrl + D - forwards delete
Ctrl + E - move to end of current paragraph
Ctrl + F - move right one character
Ctrl + H - delete
Ctrl + K - delete remainder of current paragraph
Ctrl + L - center the window on the current line
Ctrl + N - move down one line
Ctrl + O - insert new line after cursor
Ctrl + P - move up one line
Ctrl + T - transpose (swap) two surrounding character
Ctrl + V - move to end, then left one character
Ctrl + Y - paste text previously deleted with Ctrl - K

Add Option to Ctrl + F or Ctrl + B to move a word instead of a character at a time.

Solution 3

The other answer was very complete, but additionally I'd mention I just set the caps lock key to a second control key instead of swapping them.

Also, you'll notice that the large majority of the text entry fields in Mac OS X already accept emacs keystrokes (^A beginning of line, ^E end of line, ^P, ^N, ^K, ^Y, etc)

good luck

Solution 4

I really like the answer provided by Kyle Cronin, but I want to add one thing - make sure you select the appropriate keyboard for this to work. If you have an external keyboard plugged into your laptop, then there are is an additional drop down box and you will need to do this for both keyboards (or at least for your external keyboard). The screen shot below shows the "Select Keyboard" dialog box - I have selected "Joint Mac Keyboard", which is MacBook's way of saying GoldTouch external keyboard - the default is the built-in keyboard.
Screen shot showing "Select Keyboard" dialog

Once I figured that out - this works great for me!

Solution 5

If you use emacs over an ssh connection, or through a machine not on your local computer, the page up/page down buttons scroll through the terminal buffer - in my experience, not too helpful.

You can set your page down and page up buttons to send the appropriate commands to emacs. In emacs, you can scroll through the emacs buffer like so:

  • Page Up: Ctl-v
  • Page Down: Esc-v

So, to have the terminal send these commands to emacs, follow the instructions above to alter the Alt keys for Meta. However, instead of setting the "use option as meta" option, find the "page down" and "page up" options.

Page Down

Double click the "page down" option to edit it. Change Action to "send string to shell" and enter \026 as the string. Save it.

Page Up

Double click the "page up" button to edit it. Change Action to "send string to shell" and enter \033v as the string. Save it.

Share:
75,004

Related videos on Youtube

Kyle Cronin
Author by

Kyle Cronin

Updated on July 08, 2022

Comments

  • Kyle Cronin
    Kyle Cronin almost 2 years

    I'm a Mac user and I've decided to learn Emacs. I've read that to reduce hand strain and improve accuracy the CTRL and CAPS LOCK keys should be swapped. How do I do this in Leopard?

    Also, in Terminal I have to use the ESC key to invoke meta. Is there any way to get the alt/option key to invoke meta instead?

    update: While the control key is much easier to hit now, the meta key is also used often enough that its position on my MacBook and Apple Keyboard also deserves attention. In fact, I find that the control key is actually easier to hit, so I've remapped my control key to act as a meta key. Does anyone have a better/more standard solution?

  • Kyle Cronin
    Kyle Cronin over 15 years
    You may be on to something - I can't remember the last time I user caps lock.
  • Martin Wickman
    Martin Wickman over 14 years
    'Use option as meta key' does work, but this result in me not being able to type braces and pipes '[]{}|' etc since they are on Option-7 and option now... well maps to meta. Any ideas?
  • Kyle Cronin
    Kyle Cronin over 14 years
    @wic: Don't those characters have their own keys?
  • sverrejoh
    sverrejoh almost 14 years
    Not here in Europe. With a norwegian keyboard they are mapped to alt- 8 and 9 and alt+shift- 8 and 9.
  • Per Wiklander
    Per Wiklander about 13 years
    Switch layout when coding. Then they get their own keys like they should. I'm swedish and I never find the need to type my native characters while coding.
  • jocap
    jocap over 12 years
    I also use the US keyboard layout, not only when programming. Not being able to type @, {}, or [] always drives me crazy, especially on terminals which meta key you can't change (happened on a Linux server once).
  • Gourneau
    Gourneau over 12 years
    Another good resource is this page hcs.harvard.edu/~jrus/Site/System%20Bindings.html
  • asmeurer
    asmeurer over 12 years
    C-h does delete in bash and in Mac OS X Cocoa text boxes, but it does help in emacs.
  • Peter Ajtai
    Peter Ajtai about 12 years
    +1 & I actually find it better to switch the command key and caps lock, since I tend to hit command even more often than control (outside of Emacs)
  • hhh
    hhh about 8 years
    Even though I have done the setting, the CAPS Lock is still caps lock, not control as intended -- should this work everywhere in OSX? (I am using external keyboard and DV layout).
  • Kyle Cronin
    Kyle Cronin about 8 years
    @hhh The settings are per-keyboard, so make sure you've set it correctly for your external keyboard. But yes, once you make the change, it should work everywhere in OS X.
  • wle8300
    wle8300 about 8 years
    this is so awesome! thx! I didn't even think of doing that conditional logic for the capslock button. so sick!