How To Assign Special Characters To Keys In Ubuntu and Linux

Having friends and business partners around the world I frequently type texts in different languages and so far always struggled with non-standard Roman characters on my German keyboard. At some point I was so fed up that I spent a couple of hours to find a solution to make the process a bit less cumbersome.

While some non-standard Roman characters can be typed even on an German keyboard by using an "accent" modifier key, others such as for example the
'ç' are not directly reachable this way. As I need such characters quite frequently, however, I was looking for a possibility to assign such special characters to standard Roman alphabet keys together with the ALT or ALT-GR modifier key. The 'ç' for example should be reachable with the ALT or ALT-GR key (not available on a standard US keyboard) + the standard 'c' key.

On Ubuntu and I guess many other Linux based GUI's, the ALT key is already used for other purposes by the GUI so I focused on a solution with the ALT-GR key. As this key is not available on the standard US keyboard layout I am not sure if the following also works for this keyboard layout. But for all layouts that have an ALT-GR key here's the command to put the 'ç' on ALT-GR + c:

xmodmap -e "keycode 54 = c C c C ccedilla Ccedilla ccedilla Ccedilla"

54 is the code for the key on which the standard Roman "c" is located at on a German keyboard.

The current assignment of all keys is queried with the following command:

xmodmap -pk


xmodmap -pk | grep "(c)"

with the brackets around the character filters the output for the line with the code for key to which a specific character is assigned.

Non-standard Roman characters have a name that can be used in the assignment command above. The 'ç' character, for example like in 'François', is called ccedilla for the lowercase variant and Ccedilla for the uppercase variant. For the list of other special characters have a look here.

For each special character assignment a separate xmodmap -e… command is required. Changes are not persistent, however, i.e. a reboot returns the computer to the standard keyboard layout. To make the assignments persistent one can for example put all xmodmap commands in a shell script and execute it automatically during the login process.