Skip to content

Instantly share code, notes, and snippets.

@fractalbach
Last active August 10, 2018 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fractalbach/d906614fc27a6cb1812473d4f9e08524 to your computer and use it in GitHub Desktop.
Save fractalbach/d906614fc27a6cb1812473d4f9e08524 to your computer and use it in GitHub Desktop.
Map Caps to Control using setxkbmap

CAPS to Control

There's a bunch of ways to do this. On windows, I would just use AutoHotKey. On a linux distro, setxkbmap does the trick, but it is not as flexible.

The goal:

  1. remapping the capslock to control
  2. remap something else to toggle capslock
  3. restore default keyboard settings

Until I find a nice hotkey program, setxkbmap will do.

Info pages

info xkeyboard-config

This can also be found from info setxkbmap in the "SEE ALSO" section. It has a full list of all the options.

Quick and Dirty

Some quick commands to get the job done:

setxkbmap -option ctrl:nocaps
setxkbmap -option ctrl:swapcaps 
setxkbmap -option caps:ctrl_modifier

Restore Default

This clears all of the options.

setxkbmap us -option 

Another Way to Toggle Caps

This option will toggle caps by pressing both shift keys together, and

setxkbmap -option shift:both_capslock

Combination

Turn capslock into control, and still have the ability to

setxkbmap -option caps:ctrl_modifier -option shift:both_capslock

Using Alias

Make an alias for quick enable/disable. Can be anything, but this is what I'm using right now:

alias mycaps-on='setxkbmap -option caps:ctrl_modifier -option shift:both_capslock'
alias mycaps-off='setxkbmap us -option'

Now you'll be able to type in the alias command instead of the verbose setxkbmap insanity.

mycaps-on
mycaps-off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment