[vim/vim] Function keys print <F2>, <F3>, etc in insert and command modes (#3036)

206 views
Skip to first unread message

grr

unread,
Jun 18, 2018, 4:26:40 PM6/18/18
to vim/vim, Subscribed

When I press a function key in insert or command modes , , etc. is printed. I tested with vim 8.1 on MacOS and vim 8.0 on Ubuntu with vim -u NONE -N. If I set compatible, it prints terminal sequences to the screen. vim 7.4 does not experience either of these behaviors and acts as expected- pressing a non-mapped function key does not print anything.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Christian Brabandt

unread,
Jun 19, 2018, 1:34:15 AM6/19/18
to vim/vim, Subscribed

Closed #3036.

Christian Brabandt

unread,
Jun 19, 2018, 1:34:16 AM6/19/18
to vim/vim, Subscribed

sounds like a configuration issue.
Please ask user questions on the vim_use mailinglist or use vi.stackexchange.com. This here is a bug tracker for problems with Vim. We cannot provide individual help here. Closing.

grr

unread,
Jun 19, 2018, 5:41:21 AM6/19/18
to vim/vim, Subscribed

How is this a configuration problem -u NONE was used and it occurs on different vim versions on different os's on different machines with different keyboard types?

Christian Brabandt

unread,
Jun 19, 2018, 5:56:12 AM6/19/18
to vim/vim, Subscribed

what keys like <f1> or <alt> send, is very much dependent on your system, the terminal/gui being used and probably other factors I do not know about. So you would have to first figure out, how those factors differ between your systems and then try to understand how that differs between Vim versions. You did not mention much details here, so I expect a configuration issue. Nevertheless, I would expect, that if a key like <f1> is typed, it also inserts <f1> into the buffer instead of behaving like no keypress. But we are much guessing here, we need more details to decide whether this is a bug or a configuration issue.

Bram Moolenaar

unread,
Jun 19, 2018, 6:43:28 AM6/19/18
to vim/vim, Subscribed

If you have a non-mapped function key the expected behavior is to insert whatever byte sequence that key produces. Vim doesn't know what key you pressed, thus will insert whatever it got.
If Vim does recognize a function key (or another key that doesn't have a predefined meaning) it will insert a standard code, instead of the terminal-dependent escape sequence. That's all working as intended.

Tony Mechelynck

unread,
Jun 19, 2018, 6:46:50 AM6/19/18
to vim/vim, Subscribed

To make sure that, let's say, the F5 key sends nothing (and in particular not <F5>) in Insert, Replace or Command-line modes, make it explicitly do nothing, e.g.

:map! <F5> <Nop>

OTOH, using Ctrl-V F5 in Insert mode will give you <F5> in gvim and whatever termcap codes your terminal uses for F5 when running in console mode. All this is normal and expected.

Best regards,
Tony.

grr

unread,
Jun 19, 2018, 7:02:49 AM6/19/18
to vim/vim, Subscribed

If you have a non-mapped function key the expected behavior is to insert whatever byte sequence that key produces. Vim doesn't know what key you pressed, thus will insert whatever it got.
If Vim does recognize a function key (or another key that doesn't have a predefined meaning) it will insert a standard code, instead of the terminal-dependent escape sequence. That's all working as intended.

Is this new behavior? I tested vim 7.4 on macOS and Linux and they don't exhibit the behavior. It's just annoying when accidentally hitting a single function key and it produces four characters that must be backspaced over to undo. I have now mapped FN 2-12 to <Nop>, but if this is expected behavior now, are all users are expected to add this to their vimrc? Or is there some benefit to having vim insert these codes?

Tony Mechelynck

unread,
Jun 19, 2018, 8:15:29 AM6/19/18
to vim/vim, Subscribed

Even if you haven't mapped them, you might still want to talk about them; or if you hit them by mistake, to know what Vim saw.

Myself, I don't have this problem because almost all my F and Shift-F keys are mapped in most modes to do something useful to me. (I added those mappings a few at a time ever since I've been using Vim.) I'm even starting to get to the point where I might have to use ² ³ ù µ £ é § è ç à (provided natively as standard or shifted keys by my Belgian AZERTY keyboard) as {lhs} for my next Normal-mode mappings.

Of course, YMMV.

Best regards,
Tony.

K.Takata

unread,
Jun 22, 2018, 5:16:11 AM6/22/18
to vim/vim, Subscribed

I tried this with Vim 7.3.1314 on Windows (both GUI and CUI).
When I pressed F2 key, the four characters <, F, 2 and > were inserted literally (on command mode and insert mode). So this behavior is not changed at least on Windows.
I haven't checked on other platforms.

elgar328

unread,
Oct 30, 2021, 1:28:03 PM10/30/21
to vim/vim, Subscribed

When I press a function key in insert or command modes <F2>, <F3>, etc. is printed. I tested with vim 8.1 on MacOS and vim 8.0 on Ubuntu with vim -u NONE -N. If I set compatible, it prints terminal sequences to the screen. vim 7.4 does not experience either of these behaviors and acts as expected- pressing a non-mapped function key does not print anything.

I am having exactly the same problem.
(keyboard : happy hacking keyboard hybrid type-s)
(Oracle cloud server, Ubuntu 20.04, vim 8.1, ssh remote access environment)

fn+h supposed to print *, but print .
fn+j supposed to print /, but print .
fn+n supposed to print +, but add a new line above the cursor and print l.
fn+m supposed to print -, but print .

I formatted linux but that didn't solve it. Thanks for the vim version information regarding this error. I am considering using vim 7.4 version.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Reply all
Reply to author
Forward
0 new messages