ChatGPT解决这个技术问题 Extra ChatGPT

Emacs on Mac OS X Leopard key bindings

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?

it's better to move it to for apple.stackexchange.com

K
Kyle Cronin

Swapping CTRL and CAPS LOCK

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

https://i.stack.imgur.com/G8MFP.png

Using ALT/OPTION as META

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

https://i.stack.imgur.com/F7vfP.png

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


'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?
@wic: Don't those characters have their own keys?
Not here in Europe. With a norwegian keyboard they are mapped to alt- 8 and 9 and alt+shift- 8 and 9.
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.
@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.
3
3 revs, 3 users 68%

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.


Another good resource is this page hcs.harvard.edu/~jrus/Site/System%20Bindings.html
C-h does delete in bash and in Mac OS X Cocoa text boxes, but it does help in emacs.
m
mike511

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


You may be on to something - I can't remember the last time I user caps lock.
R
R.Klug

https://i.stack.imgur.com/YvovM.png

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


佚名

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.


d
dnolen

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.


A
Alexandre Paes

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.


C
Charles Merriam

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.


this is so awesome! thx! I didn't even think of doing that conditional logic for the capslock button. so sick!
l
lawlist

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])

G
Gene T

(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


a
aec

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.)


L
Lester Cheung

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

M
Minwei Shen

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.