I'm using Emacs in Mac OS X terminal, installed with homebrew.
My CTRL key is my C key, and the ALT key is Meta.
How would I define key-bindings for CMD key combinations?
For instance, I want to set CMD-(right arrow) to go to the end of the line.
EDIT
I've tried @nickcarlo's suggestions below
(setq mac-command-modifier 'super)
(global-set-key (kbd "s-<right>") 'move-end-of-line)
I don't think CMD key is being set to super properly, since I don't see s-foo
in the mini-buffer as I would if I had typed C-x
or M-x
or anything. I noticed that CMD-right, when I have two terminal windows open, switches between the two terminal windows, so I thought that might be blocking any custom setting. However, I tried:
(global-set-key (kbd "s-9") 'move-end-of-line)
.. and CMD-9 still does nothing, except beep to tell me I've pressed something wrong.
Setting non-CMD key-combos seems to work fine, like:
(global-set-key (kbd "C-w") 'move-end-of-line)
To interactively bind keys for all modes, type M-x global-set-key RET key cmd RET . To bind a key just in the current major mode, type M-x local-set-key RET key cmd RET . See Key Bindings in The GNU Emacs Manual .
Prefix keys are keys like C-x and C-c; they are parts of a complete key, and each constituent part of a prefix key is made up of its own keymap. A complete key is a command that, when input, executes its associated command. It is possible for Emacs to enumerate all the active minor and major mode key bindings in a buffer by typing C-h m.
You can tell Emacs that you want to replace all keys pointing to a certain command with one of your own choosing by using the remap event; this should be done instead of passing a key to the key bind function you are using.
A complete key is a command that, when input, executes its associated command. It is possible for Emacs to enumerate all the active minor and major mode key bindings in a buffer by typing C-h m. This command is very useful if you want to learn more about what a major or minor mode can do.
You can set it with something like:
(global-set-key (kbd "s-<right>") 'move-end-of-line)
"s" being the reference to your command key.
PS: I'm not on my mac right now so I'm not sure what exactly you need to write to set it to the specific keys you mentioned to move it to the end of line but command is represented by an s in emacs.
EDIT Just tested this on my mac. This is the exact code you'd write (if you wanted to set it globally) to bind your command key + right arrow key to move your cursor to the end of line.
If the above doesn't work, you could also try
(global-set-key (kbd "\s <right>") 'move-end-of-line)
The difference between the one above and this one is that the above equates to CMD+right and this one equates to CMD and then release CMD and hit the right key. Both work on OS X on my system.
Also check out the following post to set your CMD as the super key in case your Emacs doesn't already register it as such:
http://ergoemacs.org/emacs/emacs_hyper_super_keys.html
Specifically, you can use the following code to set up your CMD key as Super:
(setq mac-command-modifier 'super)
In Aquamacs, what worked for me is the following
(global-set-key (kbd "A-r") 'my-command)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With