I want to be able to press Alt + C to generate Ç
, and Alt + Shift + U to generate Ü
, and so on.
How can I do this? Compose key doesn't allow me to make a custom shortcut, nor does dead keys.
If you want to remap more than a couple keys, it sounds like you want to create a custom keyboard layout, a question which has been asked here before:
On the other hand, it isn't too hard to remap a few keys. Let's do the ones you asked for.
The xmodmap
command can be used to remap the keyboard. For example, for the mappings you mention, create a .Xmodmap
file in your home directory (note that I'm using >> rather than >, so it appends to rather then replaces the file):
$ echo keysym Alt_R = Mode_switch >> ~/.Xmodmap
$ echo keysym C = c C ccedilla Ccedilla >> ~/.Xmodmap
$ echo keysym U = u U udiaeresis Udiaeresis >> ~/.Xmodmap
... where 'ccedilla' is ç and udiaeresis is ü (both of which I just entered using this method, though I personally prefer the compose key method). I'll explain this in more detail below.
If you want these settings to be used every time you start the Ubuntu GUI (i.e. X server), you should then create (or edit) a file called .xinitrc
in your home directory, and add this line (if it's not already there, which it probably isn't): xmodmap ~/.Xmodmap
You can also type xmodmap ~/.Xmodmap
from your terminal to test your settings.
Note that there is no simple way to tell xmodmap to "undo" mistakes other than restarting the X server (if you've made them load automatically via .xinitrc
, you'll need to fix .Xmodmap first)! However, you may be able to reset things to defaults by using setxkbmap -layout us
(changing 'us' to whatever is appropriate for your normal layout).
Tips: To experiment with xmodmap mappings, you can run the commands one at a time, from the command line, e.g.:
$ xmodmap -e 'keysym U = u U udiaeresis Udiaeresis >> ~/.Xmodmap'
And you can use xmodmap -pke
to show the current keymappings, or just xmodmap -p
to show the modifier (Alt, Ctrl, etc.) mappings.
For a list of keysyms that you can remap, see this (which is where I found 'ccedilla' etc.) http://www.in-ulm.de/~mascheck/X11/keysyms.txt
As promised, here is a brief explanation of the 3 lines I suggested putting in your .Xmodmap
:
The first line will ensure that your right Alt
key is treated as AltGr
, as it already is on certain international keyboards. Unless you are in the USA you probably don't need that line.
The 2nd and 3rd lines remap the C and U keys, respectively.
You'll note that there are 4, space-separated entries after the '=' sign on each line. Here's what they mean:
Other resources/references:
And don't forget to look at the man pages:
$ man xmodmap
$ man xev