EmacsWiki: Caps Key (original) (raw)

This page is about the keyboard key typically labeled CapsLock. It covers different ways to use the key, including changing its behavior.

Discussion

Should we move all CTRL key hints to MovingTheCtrlKey to avoid duplicate code (text) that may become obsolete and/or out-of-sync?

Warning about PS/2 -> USB adapters

Beware of some PS/2 to USB adapters. The two I’ve used so far don’t send repeat events for the Caps Lock key to the OS keyboard driver, i.e. if you want to type C-x C-f you have to release the Caps Lock key after hitting C-x and press it again for C-f (tested on Windows XP and Debian).

Redefining as the "Undo" key.

MeatBall:HumaneInterface says that the CapsLock key is useless, and that an UNDO key would be better. Here’s how.

In ~/.Xmodmap, remove the Lock modifier bit from the Caps_Lock key, and make it the Undo/Redo key

! No Caps Lock remove Lock = Caps_Lock keysym Caps_Lock = Undo Redo

Emacs binds the Undo/Redo keys automatically.

I’m curious, why is the Caps Lock key useless? - MathiasDahl

It introduces a mode, and thus mode errors by users. – AlexSchroeder

I’m not sold on the “modes are bad” argument. I came to this page specifically because I want to redefine my Caps Lock (or perhaps Shift+Caps Lock) to be a Shift Lock (like a typewriter). Anyone know if there’s a way to do that (like emacs’ scroll-lock-mode)? – Sinewalker

Redefining as Ctrl

In my opinion (and this is a religious issue), Caps should always be Ctrl, and left control could be the CapsKey. I prefer removing Caps Lock altogether. The additional benefit of having Caps acting like Ctrl is that Ctrl gets a more central position on the keyboard. Which, in Emacs, is quite useful considering ones frequent use of Ctrl commands.

! ! Swap Caps_Lock and Control_L ! remove Lock = Caps_Lock remove Control = Control_L ! Don't swap, forget it. !keysym Control_L = Caps_Lock keysym Caps_Lock = Control_L !add Lock = Caps_Lock add Control = Control_L

or, from a term, setxkbmap -option “ctrl:nocaps” for a temporary solution. Put in .xinit to make it permanent.

This could of course be extended with the above Undo Redo command(s) being attached to Control_L. For more information on how to reorganize the keyboard in X-Window, see xmodmap(1x) or the wiki page MovingTheCtrlKey. – JoachimNilsson

Another alternative is to map CapsKey to BackSpace, like in the LispMachine, and BackSpace to Undo/Redo.

Redefining as autocomplete/expand

It’s useful to map the CapsKey to dabbrev-expand, for automatic completion/expansion. Here’s how:

In ~/.Xmodmap, remap the Caps_Lock key to some suitable key:

! Caps Lock -> Nabla keycode 66 = nabla

Then in your ~/.emacs:

(when (equal "23" (substring emacs-version 0 2)) (global-set-key '[8711] 'dabbrev-expand))

Using CapsLock as Hyper Modifier

More modifiers are always good 😊

In ~/.Xmodmap, remap the Caps_Lock key to some suitable key:

! Caps Lock -> Nabla keycode 66 = nabla

If you add this to your .emacs you will get an Hyper key in gtk and in an xterm!

(define-key key-translation-map [8711] 'event-apply-hyper-modifier)

Undo / Redo mapping on win32

Is it possible to remap, or at least get Emacs to grok, the Caps Lock key to Undo / Redo as described above?

The links are dead, but you can use AutoHotkey.

I fixed the links, so they’re not dead anymore. (But you can still try AutoHotKey.)

An example AutoHotKey script

This remaps Caps Lock to control globally in windows. It also disables ctrl in emacs (to force unlearning of bad RSI key combinations - the first 3 lines can be removed to disable this). It also remaps caps lock functionality to start+caps lock for a fallback in case this is required. Currently using with AHK Version 1.1.33.04 on Win 10.

#IfWinActive emacs@ LCtrl::return #IfWinActive #CapsLock:: SetCapsLockState % !GetKeyState("CapsLock", "T") return *CapsLock:: Send {Ctrl down} return *CapsLock Up:: Send {Ctrl up} return

I remap Caps Lock to Super. This enables me to create very comfortable and intuitive key bindings without interfering with the standard Emacs bindings. See example on my wiki home page (JonasOster).

There is a caps lock minor mode. See https://elpa.gnu.org/packages/caps-lock.html.


CategoryKeys MovingTheCtrlKey RepeatedStressInjury