Linux Commands Examples

A great documentation place for Linux commands


utility for modifying keymaps and pointer button mappings in X

see also : X - xev - setxkbmap


xmodmap [-options ...] [filename]

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!



How do I swap Alt and Windows keys with xmodmap?

This is my Xmodmaprc:

! Exchange left Alt and left Win
remove mod1 = Alt_L
remove mod4 = Super_L
add mod1 = Super_L
add mod4 = Alt_L
! Exchange tilde and lesser/greater
keycode  94 = grave asciitilde dead_grave dead_tilde grave asciitilde
keycode  49 = less greater less greater bar brokenbar bar brokenbar
! Steve, your keyboard sucks

You'll have to modify your .xsession or .xinitrc to call xmodmap .Xmodmaprc


Many pointers are designed such that the first button is pressed using the index finger of the right hand. People who are left-handed frequently find that it is more comfortable to reverse the button codes that get generated so that the primary button is pressed using the index finger of the left hand. This could be done on a 3 button pointer as follows:

%  xmodmap -e "pointer = 3 2 1"

Many applications support the notion of Meta keys (similar to Control keys except that Meta is held down instead of Control). However, some servers do not have a Meta keysym in the default keymap table, so one needs to be added by hand. The following command will attach Meta to the Multi-language key (sometimes labeled Compose Character). It also takes advantage of the fact that applications that need a Meta key simply need to get the keycode and don’t require the keysym to be in the first column of the keymap table. This means that applications that are looking for a Multi_key (including the default modifier map) won’t notice any change.

%  xmodmap -e "keysym Multi_key = Multi_key Meta_L"

Similarly, some keyboards have an Alt key but no Meta key. In that case the following may be useful:

%  xmodmap -e "keysym Alt_L = Meta_L Alt_L"

One of the more simple, yet convenient, uses of xmodmap is to set the keyboard’s "rubout" key to generate an alternate keysym. This frequently involves exchanging Backspace with Delete to be more comfortable to the user. If the ttyModes resource in xterm is set as well, all terminal emulator windows will use the same key for erasing characters:

%  xmodmap -e "keysym BackSpace = Delete"
%  echo "XTerm*ttyModes:  erase ^?" | xrdb -merge

Some keyboards do not automatically generate less than and greater than characters when the comma and period keys are shifted. This can be remedied with xmodmap by resetting the bindings for the comma and period with the following scripts:

! make shift-, be < and shift-. be >
keysym comma = comma less
keysym period = period greater

One of the more irritating differences between keyboards is the location of the Control and Shift Lock keys. A common use of xmodmap is to swap these two keys as follows:

! 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

This example can be run again to swap the keys back to their previous assignments.

The keycode command is useful for assigning the same keysym to multiple keycodes. Although unportable, it also makes it possible to write scripts that can reset the keyboard to a known state. The following script sets the backspace key to generate Delete (as shown above), flushes all existing caps lock bindings, makes the CapsLock key be a control key, make F5 generate Escape, and makes Break/Reset be 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

xmodmap ~/.xmodmap
xmodmap $HOME/.Xmodmap
xmodmap /Users/neil/.Xmodmap
xmodmap ~/.Xmodmap
xmodmap ~/dotfiles/scripts/apple-xmodmap
xmodmap ~/dotfiles/scripts/shared-xmodmap

In Linux, how can I map SHIFT_L/SHIFT_R when pressed without additional key?

maybe look a xbindkeys to change the key mapping or just find a good coding plugin for vim or gedit or whatever you like to use or code your own.

tools to change keymaps


and write a script to enable it.


Why won't my xmodmap command run on startup/login?

Some systems look for a file named ~/.Xmodmap and execute the commands found there. Try putting these lines in that file:

keysym Delete = Menu
keysym Menu = Delete

Binding Super+C Super+V to Copy and Paste

Probably Windows key is modifier key. run this and try again:

xmodmap -e 'remove Mod4 = Super_L'

Changing the Mod key in Awesome WM

I have a file with these two lines in my home:

clear lock 
keysym Caps_Lock = Super_L

It gets called from my rc.lua like this:

awful.util.spawn("xmodmap /home/username/your_xmodmap.file")

Xmodmap: Six characters to one key?

Put lines like the following in your ~/.Xmodmap:

keycode 0x2D = k K U03BA U039A U0915 U05DB U0137 U0136

The keycode can be obtained by running xev and pressing the key. If you're starting from a known state, for example, a US keyboard layout, you can use the keysym already assigned to the key, as in

keycode k = k K U03BA U039A U0915 U05DB U0137 U0136

The 8 columns on the right of the = sign successively correspond to the bare key, Shift, AltGr, AltGr+Shift, and repeat these four with ISO_Level3_Shift as well.

The words on the right of the = sign are keysyms. You can find valid keysym names in /usr/include/X11/keysymdef.h (or wherever your distribution puts keysymdef.h); look for lines of the form #define XK_foo 0xabcd /* ... */: foo is the keysym name. You can also use U1234 where 1234 is the number of a unicode character in hexadecimal (for “exotic” characters like ?, that's often the only option).

Final warning: there are two ways to configure the keyboard under X. Xmodmap is the simple way. Xkb is another way; it's more powerful, a lot more complex, and less well documented. Sometimes xkb settings can prevent xmodmap settings from working: the xkb configuration can affect what modifiers the xmodmap columns correspond to.


Remapping characters in xmodmap

Have you tried

xmodmap -pke

and checked that these lines still appear in that form in the output? There could be other startup scripts that override some of your settings...


How to rebind AltGr+a to \ with xmodmap?

xmodmap -pke lists the configuration of the current layout. I had to add the following lines to my .xmodmap file

keycode 38 = a A a A backslash AE ae
keycode 39 = s S s S bar section ssharp

How to swap Ctrl and Windows keys with xmodmap

If your only aim is to swap Ctrl and Caps Lock, then the file you're generating might be a bit overkill.

I use setxkbmap to change the layout, as xmodmap has failed across THE setup of my various machines:

setxkbmap -option rctrl:swapcaps

and I put that into my .xinitrc

Also note that when experimenting, setxkbmap -option resets everything back to the initial layout.

EDIT: I found this over on, which also describes resetting using setxkbmap


Swapping numbers and symbols in X11, but keeping alt+n

Well so far I haven't figured out how to do what I originally wanted. Instead I ended up configuring individual applications that expect alt+n to accept alt+symbol.

Here is a write up on the configurations for swapping number and symbol keyboard keys for my setup.


The xmodmap program is used to edit and display the keyboard modifier map and keymap table that are used by client applications to convert event keycodes into keysyms. It is usually run from the user’s session startup script to configure the keyboard according to personal tastes.


The following options may be used with xmodmap:

This option specifies the host and display to use.


This option indicates that a brief description of the command line arguments should be printed on the standard error channel. This will be done whenever an unhandled argument is given to xmodmap.


This option indicates that a help message describing the expression grammar used in files and with -e expressions should be printed on the standard error.


This option indicates that xmodmap should print logging information as it parses its input.


This option turns off the verbose logging. This is the default.


This option indicates that xmodmap should not change the mappings, but should display what it would do, like make(1) does when given this option.

-e expression

This option specifies an expression to be executed. Any number of expressions may be specified from the command line.


This option indicates that the current modifier map should be printed on the standard output. This is the default mode of operation if no other mode options are specified.


This option indicates that the current keymap table should be printed on the standard output.


This option indicates that the current keymap table should be printed on the standard output in the form of expressions that can be fed back to xmodmap.


This option indicates that the current pointer map should be printed on the standard output.


A lone dash means that the standard input should be used as the input file.

The filename specifies a file containing xmodmap expressions to be executed. This file is usually kept in the user’s home directory with a name like .xmodmaprc.


to get default host and display number.


expression grammar

The xmodmap program reads a list of expressions and parses them all before attempting to execute any of them. This makes it possible to refer to keysyms that are being redefined in a natural way without having to worry as much about name conflicts.

The list of keysym names may be found in the header file <X11/keysymdef.h> (without the XK_ prefix), supplemented by the keysym database /usr/share/X11/XKeysymDB. Keysyms matching Unicode characters may be specified as "U0020" to "U007E" and "U00A0" to "U10FFFF" for all possible Unicode characters.

The list of keysyms is assigned to the indicated keycode (which may be specified in decimal, hex or octal and can be determined by running the xev program). Up to eight keysyms may be attached to a key, however the last four are not used in any major X server implementation. The first keysym is used when no modifier key is pressed in conjunction with this key, the second with Shift, the third when the Mode_switch key is used with this key and the fourth when both the Mode_switch and Shift keys are used.

keycode any = KEYSYMNAME ...

If no existing key has the specified list of keysyms assigned to it, a spare key on the keyboard is selected and the keysyms are assigned to it. The list of keysyms may be specified in decimal, hex or octal.


The KEYSYMNAME on the left hand side is translated into matching keycodes used to perform the corresponding set of keycode expressions. Note that if the same keysym is bound to multiple keys, the expression is executed for each matching keycode.


This removes all entries in the modifier map for the given modifier, where valid name are: Shift, Lock, Control, Mod1, Mod2, Mod3, Mod4, and Mod5 (case does not matter in modifier names, although it does matter for all other names). For example, ’’clear Lock’’ will remove all any keys that were bound to the shift lock modifier.


This adds all keys containing the given keysyms to the indicated modifier map. The keysym names are evaluated after all input expressions are read to make it easy to write expressions to swap keys (see the EXAMPLES section).


This removes all keys containing the given keysyms from the indicated modifier map. Unlike add, the keysym names are evaluated as the line is read in. This allows you to remove keys from a modifier without having to worry about whether or not they have been reassigned.

pointer = default

This sets the pointer map back to its default settings (button 1 generates a code of 1, button 2 generates a 2, etc.).

pointer = NUMBER ...

This sets the pointer map to contain the indicated button codes. The list always starts with the first physical button. Setting a button code to 0 disables events from that button.

Lines that begin with an exclamation point (!) are taken as comments.

If you want to change the binding of a modifier key, you must also remove it from the appropriate modifier map.


Every time a keycode expression is evaluated, the server generates a MappingNotify event on every client. This can cause some thrashing. All of the changes should be batched together and done at once. Clients that receive keyboard input and ignore MappingNotify events will not notice any changes made to keyboard mappings.

Xmodmap should generate "add" and "remove" expressions automatically whenever a keycode that is already bound to a modifier is changed.

There should be a way to have the remove expression accept keycodes as well as keysyms for those times when you really mess up your mappings.

see also

X , xev , setxkbmap , XStringToKeysym, Xlib documentation on key and pointer events


Jim Fulton, MIT X Consortium, rewritten from an earlier version by David Rosenthal of Sun Microsystems.

How can this site be more helpful to YOU ?

give  feedback