Emacs on Mac OS X Leopard key bindings

MacosEmacsKeyboard ShortcutsKey Bindings

Macos Problem Overview


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?

Macos Solutions


Solution 1 - Macos

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 - Macos

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 - Macos

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 - Macos

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

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

Solution 5 - Macos

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.

Solution 6 - Macos

Not sure if you're totally married to using Emacs from the terminal, but another option is to use Carbon Emacs (my favorite) and Aquamacs (very Mac-like). Carbon Emacs uses the command key for meta, this is nice because you can do Control-Meta commands just by holding Control and Command down instead of first hitting escape then the control key sequence.

Also, if you're a serious Emacs user I thoroughly recommend that you get a keyboard suited for programming (that is one that is completely reprogrammable by itself). I use a Kinesis, it's a little bit of money but they are extremely durable and quite nice.

Solution 7 - Macos

Personally i have setup caps lock to behave like command on the system preferences and then on my emacs init.el file have:

(setq mac-command-modifier 'ctrl)

and this lets me use caps lock as command in most osx applications and as control in emacs. works well enough for me.

Solution 8 - Macos

Your joy is just beginning. Other tricks include:

  • Use the left and right shift keys to also be ( and ) for fast typing.
  • Remap your fn key or another key to be "super".
  • Make caps lock be control, but only with another key. By itself, it is escape.

Read the excellent article at http://stevelosh.com/blog/2012/10/a-modern-space-cadet/ for a lot more information.

Solution 9 - Macos

This thread was started 5 years ago and there is no mention of ns-win.el or build --with-ns. Here are all the key bindings available (out of the box) in Emacs Trunk as of October 2013. And, of course, you can create your own. Personally, I have one init.el with all my key bindings that can be used with Windows XP through Parallels on OSX, and also with OSX natively. Since the user can define his / her own keyboard shortcuts, I do not see a need to remap the keyboard in system preferences (with an Apple U.S. keyboard) unless using a keyboard that does not include the Command key. But, would I throw away my stash of IBM clicky keyboards with trackpoint built in? Of course not. :) I'm taking my IBM clicky keyboards with me into the next life. Any hand strain is most likely caused by improper wrist / arm / elbow position, not by hitting control versus caps lock. Accuracy is improved through practice, and with the help of a boss looking over your shoulder to see how you are coming along -- i.e., a little pressure to be more productive :)

(define-key global-map [?\s-,] 'customize)
(define-key global-map [?\s-'] 'next-multiframe-window)
(define-key global-map [?\s-`] 'other-frame)
(define-key global-map [?\s-~] 'ns-prev-frame)
(define-key global-map [?\s--] 'center-line)
(define-key global-map [?\s-:] 'ispell)
(define-key global-map [?\s-?] 'info)
(define-key global-map [?\s-^] 'kill-some-buffers)
(define-key global-map [?\s-&] 'kill-this-buffer)
(define-key global-map [?\s-C] 'ns-popup-color-panel)
(define-key global-map [?\s-D] 'dired)
(define-key global-map [?\s-E] 'edit-abbrevs)
(define-key global-map [?\s-L] 'shell-command)
(define-key global-map [?\s-M] 'manual-entry)
(define-key global-map [?\s-S] 'ns-write-file-using-panel)
(define-key global-map [?\s-a] 'mark-whole-buffer)
(define-key global-map [?\s-c] 'ns-copy-including-secondary)
(define-key global-map [?\s-d] 'isearch-repeat-backward)
(define-key global-map [?\s-e] 'isearch-yank-kill)
(define-key global-map [?\s-f] 'isearch-forward)
(define-key global-map [?\s-g] 'isearch-repeat-forward)
(define-key global-map [?\s-h] 'ns-do-hide-emacs)
(define-key global-map [?\s-H] 'ns-do-hide-others)
(define-key global-map [?\s-j] 'exchange-point-and-mark)
(define-key global-map [?\s-k] 'kill-this-buffer)
(define-key global-map [?\s-l] 'goto-line)
(define-key global-map [?\s-m] 'iconify-frame)
(define-key global-map [?\s-n] 'make-frame)
(define-key global-map [?\s-o] 'ns-open-file-using-panel)
(define-key global-map [?\s-p] 'ns-print-buffer)
(define-key global-map [?\s-q] 'save-buffers-kill-emacs)
(define-key global-map [?\s-s] 'save-buffer)
(define-key global-map [?\s-t] 'ns-popup-font-panel)
(define-key global-map [?\s-u] 'revert-buffer)
(define-key global-map [?\s-v] 'yank)
(define-key global-map [?\s-w] 'delete-frame)
(define-key global-map [?\s-x] 'kill-region)
(define-key global-map [?\s-y] 'ns-paste-secondary)
(define-key global-map [?\s-z] 'undo)
(define-key global-map [?\s-|] 'shell-command-on-region)
(define-key global-map [s-kp-bar] 'shell-command-on-region)
;; (as in Terminal.app)
(define-key global-map [s-right] 'ns-next-frame)
(define-key global-map [s-left] 'ns-prev-frame)

(define-key global-map [home] 'beginning-of-buffer)
(define-key global-map [end] 'end-of-buffer)
(define-key global-map [kp-home] 'beginning-of-buffer)
(define-key global-map [kp-end] 'end-of-buffer)
(define-key global-map [kp-prior] 'scroll-down-command)
(define-key global-map [kp-next] 'scroll-up-command)

;; Allow shift-clicks to work similarly to under Nextstep.
(define-key global-map [S-mouse-1] 'mouse-save-then-kill)
(global-unset-key [S-down-mouse-1])

Solution 10 - Macos

(not an ergonomic keyboard, but i really like the keys' travel and feel, and Control key , Caps Lock are swapped).

http://matias.ca/osxkeyboard/index.php

Solution 11 - Macos

I've created a fairly comprehensive set of bindings here for use outside of Terminal.

Personally, I can't use the mac laptop keyboard due to the absence of the right control key.

Instead, I have been using the Microsoft Natural Ergonomic Keyboard 4000 for over 7 years: it's got really fat, well-positioned Ctrl and Alt keys, and after downloading its drivers the "Start" and "Application" keys are trivially remapped to the Mac Cmd key, which is also fat and easily depressed.

To avoid emacs ergonomic concerns I've trained myself to use Ctrl, Alt, and Cmd the same way we use Shift - depressing them with the hand opposite the one typing the actual key. (That is, I just leave Caps Lock as is.)

Solution 12 - Macos

I set caps lock to control in system preference and I have the following in my init.el to set command to meta and option to super:

(custom-set-variables
 '(ns-alternate-modifier (quote super))
 '(ns-command-modifier (quote meta)))

Solution 13 - Macos

I would like to recommend 2 softwares Seil and Karabiner. By simply installing Seil and following the instructions in the software, you should be able to achieve what you want. From my experience, Karabiner is more powerful. I have a Japanese keyboard whose layout is different from the normal ones. I have some snippet which remaps two extra keys on my keyboard to F18 and F19 for other use. You can use the same syntax to edit your "private.xml" file to do more things.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyle CroninView Question on Stackoverflow
Solution 1 - MacosKyle CroninView Answer on Stackoverflow
Solution 2 - MacosChrisView Answer on Stackoverflow
Solution 3 - Macosmike511View Answer on Stackoverflow
Solution 4 - MacosR.KlugView Answer on Stackoverflow
Solution 5 - MacosTony WieczorekView Answer on Stackoverflow
Solution 6 - MacosdnolenView Answer on Stackoverflow
Solution 7 - MacosAlexandre PaesView Answer on Stackoverflow
Solution 8 - MacosCharles MerriamView Answer on Stackoverflow
Solution 9 - MacoslawlistView Answer on Stackoverflow
Solution 10 - MacosGene TView Answer on Stackoverflow
Solution 11 - MacosaecView Answer on Stackoverflow
Solution 12 - MacosLester CheungView Answer on Stackoverflow
Solution 13 - MacosMinwei ShenView Answer on Stackoverflow