Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible in the unix terminal to change the keys so that when I press for instance , then _ gets printed?

And if so, how do I go about doing that?

(I'm on Ubuntu, by the way.)

share|improve this question
    
Do you want to do this in all terminal windows? Or only in a specific terminal window (e.g. by invoking the terminal emulator with a special configuration file or command-line option)? Or in all applications? –  Gilles Mar 20 '12 at 16:36
    
I want to be able to change what gets written when i type in the terminal. And that means, whenever I start the terminal.. that's a window who will receive my keyboard input in this new way. –  Hermann Ingjaldsson Jan 22 '13 at 13:21
add comment

3 Answers

To quote from here:

Custom table

You can create your own map and store it in your home directory (i.e. ~/.Xmodmap). Print the current keymap table into a configuration file:

xmodmap -pke > ~/.Xmodmap

Make the desired changes to ~/.Xmodmap and then test the new configuration with:

xmodmap ~/.Xmodmap

To activate your custom table when starting Xorg add the following:

~/.xinitrc
if [ -f $HOME/.Xmodmap ]; then
    /usr/bin/xmodmap $HOME/.Xmodmap
fi

Alternatively, edit the global startup script /etc/X11/xinit/xinitrc.

Test changes

You can also make temporary changes for the current session. For example:

xmodmap -e "keycode  46 = l L l L lstroke Lstroke lstroke"
xmodmap -e "keysym a = e E"

Also:

See man xmodmap for more details.

EDIT:

To clarify: the xmodmap ~/.Xmodmap may be used in many places, not just when starting Xorg. For example, I have these two functions in my ~/.bashrc:

   # map caps to esc

   mapcaps(){
      xmodmap -e "clear lock"
      xmodmap -e "keycode 0x42 = Escape"
      echo mapcaps: caps-lock set to Escape via xmodmap
   }
   unmapcaps(){
      xmodmap -e "keycode 0x42 = Caps_Lock"
      xmodmap -e "add lock = Caps_Lock"
      echo unmapcaps: caps-lock set to caps-lock via xmodmap
   }

This is so I can dynamically map Caps to Esc.

Really there is no limitation. Feel free to call xmodmap from ~/.xinitrc, ~/.bash_profile, from a custom script, etc.

share|improve this answer
    
if [ -f $HOME/.Xmodmap ]; then - I guess when xorg is started, on many systems nobody is logged in, since they use a graphical login, so $HOME might not set. –  user unknown Mar 20 '12 at 21:08
    
If that is the case, one can always manually activate the custom keymap with xmodmap ~/.Xmodmap. In fact, I have this very command in my ~/.xinitrc file, so that it only runs when I start my window manager (in this case dwm). The downside to this is that the custom keymap is not enabled when using pure X. Still, having the ability to call xmodmap whenever is a great advantage which allows much flexibility. You can put the xmodmap command wherever, including ~/.bash_profile, which guarantees that there is a user logged in. –  Bryan Garza Mar 20 '12 at 21:15
    
Yes, or if it is a single user machine, like most desktops, put the file into /etc/.Xmodmap or reference /home/herrmann/.Xmodmap. –  user unknown Mar 20 '12 at 21:35
    
I find this very confusing actually. So I make a Xmodmap file in my home directory (there is no such file currently, im using L-Ubuntu 11.04). So how do I for instance, make that file turn 'A' into 'B'? –  Hermann Ingjaldsson Jan 22 '13 at 13:20
    
It would be something like keycode 38 = e E e E. View your current keymap with xmodmap -pke. –  Bryan Garza May 13 '13 at 17:08
add comment

To be honest I have never tried to do what you are trying. I have added alternate key bindings (key combination) for a terminal (non-X) before though.

You can see your key bindings with: showkey or showkey -s

You will use the related programs to do the additional research and modifications.

loadkeys dumpkeys keymaps setkeycodes

For me to make the change in Slackware it is pretty easy I spent some time looking around in Ubuntu but did not find the same files /usr/share/kbd/keymaps/i386/qwerty/*map.gz files. Though I only had access to a live booted Ubuntu system. You might fare better.

share|improve this answer
add comment

If you want to do this in the X Windowing System, you can use Xmodmap. I've never had a grip on the syntax, so find a working example, and go from there.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.