2

I am attempting to use Vim via a serial console and every time I launch it, vim sends ESC= and instructs the console to enable Application Keypad Mode and my numpad stops working.

How do I stop it doing this? I've seen multiple answers that say "just turn it off in the settings" but Vim keeps turning it back on again!

3
  • Welcome to Vi and Vim!
    – filbranden
    Commented Jan 10, 2022 at 20:57
  • Do you have $TERM set to vt520? Or to something else like xterm or screen or linuxor vt100? Please edit the question and include the output of echo $TERM (in your shell) or :set term? (in Vim). Thanks!
    – filbranden
    Commented Jan 10, 2022 at 20:58
  • @filbranden Yeah I have everything (TERM, locale, stty etc) configured correctly
    – Lexi
    Commented Jan 11, 2022 at 16:57

1 Answer 1

2

Try unsetting 't_ks' and 't_ke' in your vimrc:

" Prevent Vim from setting application keypad mode.
set t_ks= t_ke=

If you'd like, you can do that conditionally, based on the TERM=vt520 setting:

" Prevent Vim from setting application keypad mode on a VT520.
if &term ==# 'vt520'
  set t_ks= t_ke=
endif

These sequences are used by Vim to start and end "keypad transmit" mode.

Vim documentation also mentions those in this help section and, in particular, recommend disabling them (setting them to an empty string) in cases where they cause trouble:

Some termcap entries are wrong in the sense that after sending 't_ks' the cursor keys send codes different from the codes defined in the termcap. To avoid this you can set 't_ks' (and 't_ke') to empty strings. This must be done during initialization, otherwise it's too late.

2
  • 1
    Apologies for the delay, I was away for a few days. That fixed it thanks, but I don't really understand why it was doing it in the first place? That help section doesn't explain it.
    – Lexi
    Commented Jan 15, 2022 at 15:56
  • 1
    Sometimes it's a terminfo/termcap bug that lists these sequences for a vt520 even if they're not the most appropriate... Vim also has some hardcoded "guesses" of what will work for some specific $TERM settings, that it will for most part match by name... A VT520 is not really common these days, so it's not surprising to find it's not completely well supported!
    – filbranden
    Commented Jan 15, 2022 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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