XMODMAP(1)
๐ NAME ๐
okay so xmodmap is the utility for modifying keymaps and pointer button mappings in X ๐
โจ SYNOPSIS โจ
xmodmap [-options ...] [filename]
๐ธ DESCRIPTION ๐ธ
okay bestie, xmodmap is how you edit and display the keyboard modifier map and keymap table that client apps use to turn event keycodes into keysyms ๐ง it's usually run from your session startup script so your keyboard gets set up exactly how you like it ๐
๐ OPTIONS ๐
the following options work with xmodmap ๐
-display displayโ this one picks the host and display you want to use ๐-helpโ prints a quick rundown of the command line arguments to standard error ๐ซถ it happens wheneverxmodmapgets an argument it can't handle, so don't worry, it's not being dramatic-grammarโ prints a help message on standard error that explains the expression grammar used in files and with-eexpressions ๐-versionโxmodmapprints its version info and then peaces out ๐-verboseโxmodmapnarrates everything it's doing as it parses its input ๐ฅ-quietโ turns the verbose logging back off ๐ this is the default, so you're chill-nโxmodmapwon't actually change any mappings, it just shows you what it would do, same energy asmake(1)when you pass it this option ๐ฎ-e expressionโ runs an expression ๐ you can throw as many of these on the command line as you want-pmโ prints the current modifier map on standard output ๐ this is the default mode if you don't pick any other mode option-pkโ prints the current keymap table on standard output ๐-pkeโ prints the current keymap table on standard output, but as expressions you can feed right back intoxmodmapโจ iconic-ppโ prints the current pointer map on standard output ๐ฆ-โ a lone dash means "read from standard input" instead of a file ๐ง
the filename is a file full of xmodmap expressions that get executed ๐ท it's usually kept in your home directory with a name like .xmodmaprc
๐ EXPRESSION GRAMMAR ๐
okay so xmodmap reads in a whole list of expressions and parses all of them before it runs any of them ๐ซถ this is lowkey genius because you can refer to keysyms that are being redefined in a natural way without stressing about name conflicts ๐
the keysym names live in the header file <X11/keysymdef.h> (leave off the XK_ prefix). keysyms that match Unicode characters can be written as "U0020" through "U007E", and "U00A0" through "U10FFFF" covers every possible Unicode character ๐
keycode NUMBER = KEYSYMNAME ...โ assigns the list of keysyms to the keycode you pick ๐ฅ the keycode can be decimal, hex, or octal, and you can find it by running thexevprogram ๐ a key can hold up to eight keysyms, but the last four aren't used by any major X server implementation ๐ the first keysym is used with no modifier, the second with Shift, the third whenMode_switchis used with the key, and the fourth when bothMode_switchand Shift are usedkeycode any = KEYSYMNAME ...โ if no existing key has that list of keysyms,xmodmapgrabs a spare key on your keyboard and assigns them to it โจ the list can be decimal, hex, or octalkeysym KEYSYMNAME = KEYSYMNAME ...โ the keysym on the left gets translated into all the matching keycodes, and then the keycode expressions run for each one ๐ฆ heads up: if the same keysym is bound to multiple keys, the expression runs for each matching keycodeclear MODIFIERNAMEโ wipes every entry in the modifier map for the given modifier ๐งน the valid names are:Shift,Lock,Control,Mod1,Mod2,Mod3,Mod4, andMod5(case doesn't matter for modifier names, but it does matter for everything else ๐). for example,clear Lockremoves any keys that were bound to the shift lock modifieradd MODIFIERNAME = KEYSYMNAME ...โ adds all keys containing the given keysyms to the modifier map you name ๐ the keysym names get evaluated after all the input expressions are read, which makes swapping keys super easy to write (see the EXAMPLES section ๐)remove MODIFIERNAME = KEYSYMNAME ...โ removes all keys containing the given keysyms from that modifier map ๐ unlikeadd, the keysym names get evaluated as the line is read in, so you can remove keys from a modifier without worrying about whether they've been reassignedpointer = defaultโ resets the pointer map to its defaults, so button 1 makes a code of 1, button 2 makes a 2, and so on ๐ธpointer = NUMBER ...โ sets the pointer map to the button codes you list ๐ซถ the list always starts with the first physical button, and setting a button code to 0 disables events from that button ๐ซ
lines that start with an exclamation point (!) are comments ๐
โ ๏ธ bestie, if you want to change the binding of a modifier key, you also have to remove it from the appropriate modifier map first or it's gonna be a whole mess ๐ญ
๐ง EXAMPLES ๐ง
okay so a lot of pointers are designed so the first button gets pressed with your right hand's index finger ๐ lefties often find it way more comfy to flip the button codes so the primary button is pressed with the left index finger ๐ซถ on a 3 button pointer you can do it like this:
% xmodmap -e "pointer = 3 2 1"
a bunch of apps support Meta keys (kinda like Control, except you hold down Meta instead) ๐ but some servers don't have a Meta keysym in the default keymap table, so you gotta add one by hand ๐ ๏ธ this command attaches Meta to the Multi-language key (sometimes labeled Compose Character) ๐ it also takes advantage of the fact that apps needing a Meta key only need the keycode and don't require the keysym to be in the first column of the keymap table ๐ฆ so apps looking for a Multi_key (including the default modifier map) won't notice a thing ๐
% xmodmap -e "keysym Multi_key = Multi_key Meta_L"
some keyboards have an Alt key but no Meta key ๐คทโโ๏ธ in that case this might slay:
% xmodmap -e "keysym Alt_L = Meta_L Alt_L"
one of the simplest but most convenient xmodmap tricks is making the keyboard's "rubout" key generate a different keysym โจ people usually swap Backspace with Delete so it feels more natural ๐ฅ if you set the ttyModes resource in xterm too, every terminal emulator window will use the same key for erasing characters ๐
% xmodmap -e "keysym BackSpace = Delete"
% echo "XTerm*ttyModes: erase ^?" | xrdb -merge
some keyboards don't automatically make < and > when you shift the comma and period keys ๐ญ you can fix that by resetting the comma and period bindings with this script:
!
! make shift-, be < and shift-. be >
!
keysym comma = comma less
keysym period = period greater
the location of the Control and CapsLock keys is one of the most irritating keyboard differences ever ๐ค a super common move is swapping them:
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
run this example again to swap the keys back to how they were ๐
the keycode command is great for assigning the same keysym to multiple keycodes ๐ it's unportable, but it also lets you write scripts that reset your keyboard to a known state ๐งผ the script below sets backspace to generate Delete (like we did above), flushes all existing caps lock bindings, makes the CapsLock key act as a control key, makes F5 generate Escape, and makes Break/Reset act as a shift lock ๐
!
! On the HP, the following keycodes have key caps as listed:
!
! 101 Backspace
! 55 Caps
! 14 Ctrl
! 15 Break/Reset
! 86 Stop
! 89 F5
!
keycode 101 = Delete
keycode 55 = Control_R
clear Lock
add Control = Control_R
keycode 89 = Escape
keycode 15 = Caps_Lock
add Lock = Caps_Lock
๐ ENVIRONMENT ๐
DISPLAYโ used to get the default host and display number ๐ฆ
๐ SEE ALSO ๐
X(7), xev(1), setxkbmap(1), XStringToKeysym(3), and the Xlib documentation on key and pointer events ๐
๐ BUGS ๐
๐ญ every time a keycode expression gets evaluated, the server sends a MappingNotify event to every client, and that can cause some thrashing ๐ช๏ธ all the changes should be batched together and done at once. clients that take keyboard input and ignore MappingNotify events won't notice any changes made to keyboard mappings
xmodmap should generate add and remove expressions automatically whenever a keycode that's already bound to a modifier gets changed ๐
there should also be a way to let the remove expression accept keycodes as well as keysyms, for those times you really mess up your mappings ๐
๐ฉโ๐ป AUTHOR ๐ฉโ๐ป
Jim Fulton, MIT X Consortium, rewritten from an earlier version by David Rosenthal of Sun Microsystems ๐
bestie that's the whole manual ๐ it's the X Version 11 page for xmodmap 1.0.11, with the XMODMAP(1) manual page label, so now you're basically an xmodmap legend ๐๐ซถโจ
๐ฆ where this page comes from
- alpine 3.24: xmodmap-doc 1.0.11-r1 ยท MIT
- debian trixie: x11-xserver-utils 7.7+11
- epel 10: xmodmap 1.0.11-5.el10_1 ยท MIT AND MIT-open-group
- fedora 43: xmodmap 1.0.11-9.fc43 ยท MIT AND MIT-open-group
- fedora 44: xmodmap 1.0.11-10.fc44 ยท MIT AND MIT-open-group
- nixos 26.05: xmodmap 1.0.11
- opensuse-leap 16.0: xmodmap 1.0.11-160000.2.2 ยท MIT
- opensuse-leap 16.0: xmodmap 1.0.11-160000.2.2 ยท MIT
- opensuse-leap 16.0: xmodmap 1.0.11-160000.2.2 ยท MIT
- opensuse-leap 16.0: xmodmap 1.0.11-160000.2.2 ยท MIT
- ubuntu noble: x11-xserver-utils 7.7+10build2
- ubuntu questing: x11-xserver-utils 7.7+11
- ubuntu resolute: x11-xserver-utils 7.7+11build1
- ubuntu stonking: x11-xserver-utils 7.7+11build1
- Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved
- Copyright 1988, 1989, 1990, 1998 The Open Group
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms