3

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
2
  • I have the same problem accessing a linux box from another linux box over vnc, and running vim within tmux. All of the factors need to be in place to see the issue, removing vnc / tmux / vim from the equation makes everything work. Temporarily removing both .tmux.conf and .vimrc makes no difference. By recording it as a macro, I discovered that the actual keystrokes that vim is receiving are ^[Oj. Commented Aug 7, 2019 at 10:31
  • Investigation results: / and * do the same thing outside of vnc, when numlock is off. However, I tried turning numlock on within vnc (both via xset and passing through system keys), and although numlock is definitely on (number keys themselves work), / and * still have this weird behaviour. Commented Aug 7, 2019 at 11:16

4 Answers 4

2

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.

3
  • Please try to find the source, and edit your answer to provide a link to it. Commented Sep 8, 2017 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
    Commented Sep 29, 2017 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
    Commented Oct 3, 2017 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.

0

The only way around this that I've found is to modify the TERM environment variable within tmux:

setenv TERM xterm

(I'm in tcsh, much to my dismay)

However, this is NOT a recommended long-term solution. The tmux devs say display issues are likely to occur. It is behaving for me at the moment, but this is definitely going to be a "when required" thing: I would love to hear a better solution.

0

i am using x11vnc as server and tigervnc as viewer. same problem.

i have fixed it with setxkbmap -option 'numpad:microsoft'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .