Setting your keyboard layout should be one of the first things users do when installing or setting up their Linux system. Every system will come with a slew of preconfigured layouts for various languages or preferences. But what if you want to take it a step further and modify a layout to your liking?
That is where the
xmodmap command can help us. This command allows us to remap individual keys on our keyboard, which is useful for achieving a personalized and ideal keyboard layout which is just not provided by default in your Linux distro.
In this tutorial, we will take you through the step by step instructions to get the perfect keyboard layout on Linux by remapping keys with the
xmodmap can also be used to map more functionalities to your keyboard since some keys may not be in use.
In this tutorial you will learn:
- How to view the currently configure key map
- How to remap keys with
- How to load remapped keys each session start
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Some Linux distros or desktop environments may override the settings of
xmodmap. In that case, you will need to configure your custom keyboard mappings elsewhere. It is worth a shot to follow the steps below to see if they will work on your system.
How to view current keyboard mapping
Get started by opening a command line terminal and entering the following command to see the currently configured keyboard mappings in
$ xmodmap -pke
Output from the xmodmap command, showing the current mapping of our keys
A typical entry for a keyboard mapping will look something like this. This happens to be for the
keycode 24 = q Q q Q
As you can see, there are four different mappings for this key. The order of the settings is how we can tell what each one does. Here is what the order means. Keep in mind that not all need to be used, as is the case with our
q key which only uses the first four settings.
- Ordinary key press
- Key + Shift
- Key + Mode_switch
- Key + Mode_switch + Shift
- Key + ISO_Level3_Shift
- Key + Shift + ISO_Level3_Shift
In the vast majority of setups, you will only need to concern yourself with the first two settings (ordinary key press and key + Shift).
You may also see a mapping that has
NoValue, which is necessary to skip a certain mapping then continue with the next setting.
How to remap keys with xmodmap step by step instructions
- Start by making a copy of the current mappings and storing the file in your
$ xmodmap -pke > ~/.Xmodmap
- Now, using
nanoor your favorite terminal or GUI file editor, open this file to make your desired changes.
$ nano ~/.Xmodmap
Exit the file and save changes when done.
- For the changes to take effect, execute the following command to load the configuration into
$ xmodmap ~/.Xmodmap
- For good measure, you should add that line to the bottom of the
$HOME/.bashrcfile so it gets executed whenever a new terminal or shell is opened.
$ echo xmodmap ~/.Xmodmap >> ~/.bashrc
In this tutorial, we saw how to remap keys with
xmodmap on a Linux system. This is a quick and easy way to achieve the perfect layout for your keyboard, and customize it to your liking. It also works well as a way to play a trick on your colleagues, but you didn’t hear that from us.