This answer explains how to set this up with xmodmap. Put the configuration snippets below in ~/.Xmodmap, and run xmodmap <~/.Xmodmap to apply them. Depending on your distribution and your setup, ~/.Xmodmap may be loaded automatically when you log in, or you may need to call xmodmap explicitly from ~/.xinitrc or ~/.xsession, or you may need to configure your desktop environment to apply ~/.Xmodmap.
X has a keysym (i.e. an abstract key name) called Mode_switch. On most keyboard mappings for latin-script languages other than US, this keysym is bound to the key labeled AltGr, which replaces the right Alt key. You can choose to map Mode_switch to a different key such as Caps Lock. On a PC keyboard, the keycode (what the hardware sends) for Caps Lock is 66, so change its binding to Mode_switch, and remove the caps lock modifier from it:
keycode 66 = Mode_switch
clear Lock
You also need to associate a modifier with Mode_switch. There are 5 custom modifiers, Mod1 through Mod5; any will do, but there has to be one. Run xmodmap -pm to see what modifiers are in use, and pick one of the 5 that isn't, then add a line like this to your .Xmodmap:
add Mod3 = Mode_switch
In an xmodmap key specification, the character sent by the key with Mode_switch is in the third column after the = sign, and with Mode_switch+Shift in the fourth column. (The first two columns are for the key with no modifiers and with Shift.) You can use a keysym directive to rebind the key that now sends n regardless of its keycode:
keysym n = n N ntilde Ntilde
The names on the right are in fact keysym names. You can find a list of these in
/usr/include/X11/keysymdef.h, e.g. the line #define XK_Ntilde 0x00d1 means there's a keysym called Ntilde that corresponds to Unicode character U+00D1. There are characters that don't have a keysym name; you can use the unicode number instead.
! U+2030 is PER MILLE SIGN, U+2031 is PER TEN THOUSAND SIGN
keysym 5 = 5 percent U2030 U2031
Note that if you're shifting modifiers around on systems of ~2009–2011 vintage, you might run into an X_SetModifierMapping bug. Often, but not always, using clear Lock will work around the bug.
AltGrkey (i.e. a key that makes some character keys insert a different character, never mind that it's the right Alt key or not)? – Gilles 'SO- stop being evil' Apr 29 '11 at 22:37