You are not logged in.

#1 2011-01-02 19:33:40

cmtptr
Member
Registered: 2008-09-01
Posts: 135

[SOLVED] wacky urxvt+vim+numpad issues

I recently switched to urxvt from xterm to see what all the fuss is about.  I've noticed that when I'm in vim, my number pad keys (when numlock is off) don't behave as intended.  When I hit the Home (7) key, rather than returning to the beginning of the line it appears to open a new line above the current (as if shift+o were pressed), and insert a lowercase 'w'.  All of the other numberpad keys behave similarly, but inserting the following characters:

PgUp (9): *see below
Up (8): x
Home (7): w
Right (6): v
(5): u
Left (4): t
PgDn (3): *see below
Down (2): r
End (1): q
Ins (0): p

*PgUp and PgDn keys seem to erase and un-erase (?) a magical buffer consisting only of characters entered by other misbehaving numberpad keys.

I have not noticed strange behavior with these keys in other applications.  Also, the codes for these keys already appear in my /etc/inputrc:

[corey@sariss ~]$ cat
Ins: ^[[2~
Ins: 
End: ^[[8~
End: 
Down: ^[[B
Down: 
      
PgDn: ^[[6~
PgDn: 
Left: ^[[D
Left: 
Right: ^[[C
Right:  
Home: ^[[7~
Home: 
Up: ^[[A
PgUp: ^[[5~
PgUp: 
^C

The keyboard I'm using is on an MSI MS-1651 laptop.  Any suggestions would be greatly appreciated.

Last edited by cmtptr (2011-01-09 08:38:04)

Offline

#2 2011-01-06 04:27:05

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED] wacky urxvt+vim+numpad issues

You could re-map your keys to do what you want.

(Incidentally, my machine does the same thing as yours when pressing the key pad 'home' key.  It adds a new line above the current line and prints a 'w'.)

The command to remap your keyboard keys (as far as the X Window system is concerned) is 'xmodmap'.

For example, to remap the key pad 'Home' key to be the same as the other 'Home' key, put the following line in your .xinitrc file:

xmodmap -e "keycode 79=Home KP_7"

This assumes that your key pad 'Home' key generates key code 79 on your system (that's what it does on mine).

You can determine what key code is applicable on your machine by running

xmodmap -pk | more

Look for the keysym 'KP_Home' (key pad home) in the 3rd column and see the corresponding key code in the first column.

Last edited by rockin turtle (2011-01-06 06:15:35)

Offline

#3 2011-01-08 20:02:36

cmtptr
Member
Registered: 2008-09-01
Posts: 135

Re: [SOLVED] wacky urxvt+vim+numpad issues

rockin turtle wrote:

You could re-map your keys to do what you want.

(Incidentally, my machine does the same thing as yours when pressing the key pad 'home' key.  It adds a new line above the current line and prints a 'w'.)

The command to remap your keyboard keys (as far as the X Window system is concerned) is 'xmodmap'.

For example, to remap the key pad 'Home' key to be the same as the other 'Home' key, put the following line in your .xinitrc file:

xmodmap -e "keycode 79=Home KP_7"

This assumes that your key pad 'Home' key generates key code 79 on your system (that's what it does on mine).

You can determine what key code is applicable on your machine by running

xmodmap -pk | more

Look for the keysym 'KP_Home' (key pad home) in the 3rd column and see the corresponding key code in the first column.

That's exactly what I needed, thanks!  Any chance I could read a full explanation of what's going on here?  Why is this necessary, and why do I notice it only in vim and only when using urxvt?

Thanks again.

Offline

#4 2011-01-09 05:15:17

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED] wacky urxvt+vim+numpad issues

Well, I can try to explain, but my expertise is limited - so what I say may be incorrect.

As I understand it, X Window System somehow associates a number called a 'keycode' with each key on your keyboard.  When you press a key, X determines the keycode, then translates this number to a different number called a 'keysym', which then gets sent to the application such as urxvt or vim.

X uses this mechanism to allow you to easily change Locales.  The keyboard always generates the same keycode for each key, but different Locales translate to different keysyms.

It turns out that the 'Home' key and the 'Key Pad Home' key not only have different keycodes (naturally), but they also each have their own keysyms.  This way a given application can determine which 'Home' key the user has pressed, and can potentially have different behavior for the different keys.

The X Window System also has textual mnemonics defined for these keysyms that the xmodmap utility uses when remapping these keysyms.  For instance, the 'Home' key has the mnemonic 'Home', and the key pad 'Home' key has 'KP_Home'.

What

xmodmap -e "keycode 79=Home KP_7"

does, is tell X to translate keycode 79 to the keysym 'Home' instead of 'KP_Home'. (It also tells X to translate keycode 79 to keysym KP_7 when Numlock is active.)

Most likely, there is a way to configure urxvt to do this translation; although, offhand I don't know how.  The same is probably true for vim, it has millions of configuration settings.  The xterm you were using before was most likely already configured to do this translation.

Other applications that work as you expect, obviously, are written to handle both the 'Home' and 'KP_Home' keysyms.

Last edited by rockin turtle (2011-01-09 05:23:36)

Offline

#5 2011-01-09 08:37:07

cmtptr
Member
Registered: 2008-09-01
Posts: 135

Re: [SOLVED] wacky urxvt+vim+numpad issues

rockin turtle wrote:

Well, I can try to explain, but my expertise is limited - so what I say may be incorrect.

As I understand it, X Window System somehow associates a number called a 'keycode' with each key on your keyboard.  When you press a key, X determines the keycode, then translates this number to a different number called a 'keysym', which then gets sent to the application such as urxvt or vim.

X uses this mechanism to allow you to easily change Locales.  The keyboard always generates the same keycode for each key, but different Locales translate to different keysyms.

It turns out that the 'Home' key and the 'Key Pad Home' key not only have different keycodes (naturally), but they also each have their own keysyms.  This way a given application can determine which 'Home' key the user has pressed, and can potentially have different behavior for the different keys.

The X Window System also has textual mnemonics defined for these keysyms that the xmodmap utility uses when remapping these keysyms.  For instance, the 'Home' key has the mnemonic 'Home', and the key pad 'Home' key has 'KP_Home'.

What

xmodmap -e "keycode 79=Home KP_7"

does, is tell X to translate keycode 79 to the keysym 'Home' instead of 'KP_Home'. (It also tells X to translate keycode 79 to keysym KP_7 when Numlock is active.)

Most likely, there is a way to configure urxvt to do this translation; although, offhand I don't know how.  The same is probably true for vim, it has millions of configuration settings.  The xterm you were using before was most likely already configured to do this translation.

Other applications that work as you expect, obviously, are written to handle both the 'Home' and 'KP_Home' keysyms.

That makes sense.  Based on what you explained, I'm going to guess that xterm did a translation as you described, while urxvt simply handles both Home and KP_Home keysyms appropriately.  When I'm in vim, however, urxvt just passes the keysym through and so vim is the one misbehaving.  I wouldn't have noticed it in xterm because of xterm pre-translating the keysym before it passes it to vim.

I really appreciate your help!  Thanks again.

Offline

#6 2011-08-04 21:00:27

ms
Member
From: Bandung, Indonesia
Registered: 2010-07-28
Posts: 81
Website

Re: [SOLVED] wacky urxvt+vim+numpad issues

(I know this thread has been marked solved, I just want to give an example of solution)

Thanks for question and help, I recently just switch from gnome-terminal to urxvt-unicode and got the same problem.

I will try to give an example of solution using xmodmap, note that the keycode may be different on your system.

  1. Create or modify "~/.Xmodmap" file with its content is like below,

    keycode 63 = KP_Multiply
    keycode 79 = Home KP_7
    keycode 80 = Up KP_8
    keycode 81 = Prior KP_9
    keycode 82 = KP_Subtract
    keycode 83 = Left KP_4
    keycode 84 = KP_5
    keycode 85 = Right KP_6
    keycode 86 = KP_Add
    keycode 87 = End KP_1
    keycode 88 = Down KP_2
    keycode 89 = Next KP_3
    keycode 90 = Insert KP_0
    keycode 91 = Delete KP_Decimal
    keycode 112 = Prior
    keycode 117 = Next
  2. In "~/.xinitrc", X session startup, file load your xmodmap configuration file

    ...
    xmodmap ~/.Xmodmap
    ...

--
I just add this problem and solution to troubleshooting section in rxvt-unicode wiki.

Offline

#7 2011-11-29 15:23:54

ferda
Member
Registered: 2010-02-05
Posts: 67

Re: [SOLVED] wacky urxvt+vim+numpad issues

A cleaner solution to this problem would probably be editing your ~/.Xdefaults for urxvt instead of changing the keymap for the whole system.

In order to get the numpad working in my zsh+urxvt+vim setup I had to add these lines:

URxvt.keysym.KP_Add:    +
URxvt.keysym.KP_Subtract: -
URxvt.keysym.KP_Multiply: *
URxvt.keysym.KP_Divide  : /
URxvt.keysym.KP_Decimal : .
URxvt.keysym.KP_Separator : ,
URxvt.keysym.KP_1:      1
URxvt.keysym.KP_2:      2
URxvt.keysym.KP_3:      3
URxvt.keysym.KP_4:      4
URxvt.keysym.KP_5:      5
URxvt.keysym.KP_6:      6
URxvt.keysym.KP_7:      7
URxvt.keysym.KP_8:      8
URxvt.keysym.KP_9:      9
URxvt.keysym.KP_0:      0

(see http://wiki.neo-layout.org/ticket/182)

Last edited by ferda (2011-11-29 15:24:33)

Offline

Board footer

Powered by FluxBB