remapping caps-lock

The Caps-Lock key on most keyboards is much bigger than its relative unimportance justifies. Personally, I hardly ever use the key at all. So can't we do something more useful with the Caps-Lock key than not using it?

Yes we can. Sascha Chua mentions a little trick to put in your .emacs to bind Caps-Lock to M-x:

;; bind Caps-Lock to M-x
;; http://sachachua.com/wp/2008/08/04/emacs-caps-lock-as-m-x/
;; of course, this disables normal Caps-Lock for *all* apps...
(if (eq window-system 'x)
    (shell-command "xmodmap -e 'clear Lock' -e 'keycode 66 = F13'"))
(global-set-key [f13] 'execute-extended-command)
First, it remaps the Caps-Lock key to F13 using xmodmap, and then binds that to 'execute-extended-command', a.k.a, M-x. It's important to note that this will remap Caps-Lock for all your programs, not just emacs.

Also note that the above only works on X-Windows (Linux/Unix); on MS-Windows you can use Lennart Borgmans tip instead:

(setq w32-enable-caps-lock nil)
(global-set-key [capslock] 'execute-extended-command)
As people have mentioned, you can of course map Caps-Lock to other keys instead, for example the Control key.


Anonymous said...

This kills capslock in all applications, not just emacs. :(

msm said...

did anyone EVER use caps-lock key?