I'm using NixOS with X11 and don't have administrator privileges. AltGr is working, but some of the characters it produces aren't useful to me, such as º and ª, and I'd like to replace them with a custom set of characters like {, [, ], and @. What's the right way to change these key mappings using only files or tools available in my home directory?
2 Answers
If you only have access to your home directory, system-wide keyboard configuration files may be off-limits, but an X11-level remapping should still work for your own session. Keep the custom configuration in your home directory and load it when your graphical session starts.
You can do this with xmodmap, and it normally doesn’t require root access. First, export your current mappings with `xmodmap -pke > new_config`. Edit the resulting file, changing the symbols assigned to the relevant keycodes. For example, each line may look like `keycode 38 = a A a A ae AE ae`; the first entries represent the key by itself and with Shift, while later entries cover modifier combinations such as AltGr. After editing it, apply the layout with `xmodmap new_config`. You can place the command in your X session startup, such as `.xinitrc`, so the mapping is loaded automatically.

Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux