Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remap keys when in Emacs?

Tags:

emacs

key

remap

I am looking for a way to have my control key and caps-lock key switched when I am in the emacs window, but when I go to any other program such as Firefox I want to be able to use the normal control button for new windows, tabs and such.

Additional Information: I am using Ubuntu, but answers for all systems are good since someone else may want to know how to do it on their system.

like image 708
Anton Avatar asked Feb 03 '09 20:02

Anton


People also ask

How do I set Keybinds in emacs?

emacs file. 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 .

What is key binding in emacs?

Key Bind CommandsDefines a key against a keyboard map. Use this if you want to change a keymap that isn't the current buffer map. (local-set-key KEY COMMAND) Binds a key to the local keymap used by the active buffer, unlike define-key which takes an explicit keymap to bind a key against.

What is the Return key in emacs?

"RET" is the Return key while emacs runs in a terminal.


3 Answers

Emacs never actually sees the CapsLock keycode (under X anyway), so you can't remap the key in Lisp. Take a look at this page for details:

http://www.emacswiki.org/emacs/MovingTheCtrlKey

like image 112
jrockway Avatar answered Sep 23 '22 06:09

jrockway


On windows using Auto Hot Key you can achieve this with this piece of code put in default script:

#IfWinActive, emacs@      
    CapsLock::Control
#IfWinActive

Auto Hot Key is a very handy utility and it is also free software like in GPL.

like image 20
boskom Avatar answered Sep 21 '22 06:09

boskom


For globally remapping keys there is xmodmap. xkeycaps is an interactive tool. You can put control on both keys.

Since you want to remap the keys only for Emacs (which I find somewhat ill-advised) you need to look inside Emacs for a solution. It should be possible, because you can rebind all keys, but it may be too tedious to swap all keys around if the modifiers cannot be swapped.

Personally I map CapsLock to Compose, to type all kinds of funny characters like ä, ß, å, þ, «, —, ...

like image 43
starblue Avatar answered Sep 23 '22 06:09

starblue