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 swap
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.
Once I figured that out - this works great for me!
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])
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.
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)))
⌥ + ← - 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.
Your joy is just beginning. Other tricks include:
Read the excellent article at http://stevelosh.com/blog/2012/10/a-modern-space-cadet/ for a lot more information.