0

This question dovetails from How do I get the numpad to work in vim using iterm2 on osx with term=xterm? and How do I get the numpad to work in vim using iterm2 on osx with term=xterm? but I couldn't find elements described in those respective answers.

I am accessing a Linux box through VNC from a Windows box.

On the Linux box, through this VNC session, I'm editing in Vim, and in insert mode, when I type '/' and '*' from the numeric keypad (i.e. to start a C-style comment), the characters 'o' and 'j' are inserted instead (specifically, a carriage return seems to be inserted, then the 'o' or 'j' is inserted at the first tab stop).

The questions and answers that I noted seem MacOs-specific; e.g. between the terminal running on the Linux box and VNC's Preferences, I couldn't find any reference to "xterm with Numeric Keypad".

Can someone advise how to fix this problem in my described environment? I'm unclear if the source of this behavior is Vim, the terminal, or VNC.

Here are $TERM, Vim version, and .vimrc, if they're relevant:

>vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Dec 21 2016 15:22:28)

>echo $TERM
screen-256color

>cat ~/.vimrc
set backspace=indent,eol,start
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
filetype plugin indent on
autocmd FileType make set noexpandtab shiftwidth=4 softtabstop=0
set cino+=(0
set statusline=
set statusline +=\[%n] "buffer number
set statusline +=\%F   "File
set statusline +=%=%l/%L "currentLine/totalLine
set statusline +=%4v "virtual column
set laststatus=2
set t_Co=256
colorscheme torte
set number
"let g:netrw_liststyle = 3
syntax on

Update: One other probably relevant factor: I am running tmux atop my bash shell. My .tmux.conf:

>cat ~/.tmux.conf 
unbind C-b
set -g prefix C-a
bind C-a send-prefix
set-window-option -g mode-keys vi
set -g set-titles on
set-window-option -g automatic-rename off
set-option -g allow-rename off
0

PS: I got this info on net and couldn’t find the source link now.

  1. Create the following file in some common location:

    $ cat fix_numpad 
    ! initialization, 
    ! Ensure that we have all keysyms we're going to use assigned to something. 
    
    keycode any = KP_Insert 
    keycode any = KP_End 
    keycode any = KP_Down 
    keycode any = KP_Next 
    keycode any = KP_Left 
    keycode any = KP_Begin 
    keycode any = KP_Right 
    keycode any = KP_Home 
    keycode any = KP_Up 
    keycode any = KP_Prior 
    keycode any = KP_Delete 
    
    ! Set the keypad to numeric mode. 
    ! You may need to adjust KP_Next/KP_Prior; possible alternatives 
    ! are KP_Page_Down/KP_Page_Up or just Next/Prior. 
    ! just Next. 
    keysym KP_Insert = KP_0 
    keysym KP_End    = KP_1 
    keysym KP_Down   = KP_2 
    keysym KP_Next   = KP_3 
    keysym KP_Left   = KP_4 
    keysym KP_Begin  = KP_5 
    keysym KP_Right  = KP_6 
    keysym KP_Home   = KP_7 
    keysym KP_Up     = KP_8 
    keysym KP_Prior  = KP_9 
    keysym KP_Delete = KP_Decimal
    
    $
    
  2. Assign the new mappings

    $ xmodmap fix_numpad
    

NOTE: You can add this to your ~/.vnc/xstartup file so that your mappings are always retained.

  • Please try to find the source, and edit your answer to provide a link to it. – G-Man Sep 8 '17 at 19:51
  • This looked promising, but alas, made no difference: the described problem is unchanged after creating a file with your posted content, and adding "xmodmap fix_numpad" to my ~/.vnc/xstartup. – StoneThrow Sep 29 '17 at 18:19
  • It is working flawlessly in my machine and here is my mappings: $xmodmap xmodmap: up to 4 keys per modifier, (keycodes in parentheses): shift Shift_L (0x32), Shift_R (0x3e) lock Caps_Lock (0x42) control Control_L (0x25), Control_R (0x6d) mod1 Alt_L (0x40), Alt_R (0x71), Meta_L (0x9c) mod2 Num_Lock (0x4d) mod3 mod4 Super_L (0x73), Super_R (0x74), Super_L (0x7f), Hyper_L (0x80) mod5 Mode_switch (0x8), ISO_Level3_Shift (0x7c) – m_r_nadh Oct 3 '17 at 13:08
0

The question implies that you're using xterm, and want to turn the application keypad mode to normal (while it has been set to application). For xterm, you can always turn the application modes on/off through a menu entry in the "VT Options" menu (control-middle-mouse click):

Those menu entries are selected (with a checkmark) when they are in application mode.

xterm uses the keycode information to tell it if a keypad key is pressed, and uses the normal/application mode to decide what to send for that key.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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