2

Literal terminal code of <f4> is:

^[OS

result of set <f4> is:

t_k4 <F4>        ^[[14;*~

They are totally different, unlike results of f5-f12 (which are the same except the modifier related sequence).

Both of following command will trigger <f4>

call feedkeys('^[OS')
call feedkeys('^[[14~')

I also need to add extra setting to make <c-f[1-4]> and <s-f[1-4]> work properly:

...
set <f16>=^[[1;2S
map <f16> <s-f4>

set <f28>=^[[1;5S
map <f28> <c-f4>

Why are f1-f4 special, what's the relationship between their terminal code and vim's t_xx key codes ?

I'm using vim8.1-1432 on ubuntu16.04.

  • 1
    For what it's worth, pressing F4 in vi in my git-bash issues ^[OS, while pressing F4 in vi in my CentOS terminal accessed via Putty issues ^[[14~. So vi probably accepts both as synonyms if different terminals feed vi different strings to express the same key, which would explain the identical behaviour of the two feedkeys commands. – joanis Jun 10 '19 at 18:12
1

:h xterm-function-keys

An xterm can send function keys F1 to F4 in two modes: vt100 compatible or
not.  Because Vim may not know what the xterm is sending, both types of keys
are recognized.  The same happens for the <Home> and <End> keys.
            normal                      vt100 ~
    <F1>    t_k1    <Esc>[11~   <xF1>   <Esc>OP     *<xF1>-xterm*
    <F2>    t_k2    <Esc>[12~   <xF2>   <Esc>OQ     *<xF2>-xterm*
    <F3>    t_k3    <Esc>[13~   <xF3>   <Esc>OR     *<xF3>-xterm*
    <F4>    t_k4    <Esc>[14~   <xF4>   <Esc>OS     *<xF4>-xterm*
    <Home>  t_kh    <Esc>[7~    <xHome> <Esc>OH     *<xHome>-xterm*
    <End>   t_@7    <Esc>[4~    <xEnd>  <Esc>OF     *<xEnd>-xterm*

When Vim starts, <xF1> is mapped to <F1>, <xF2> to <F2> etc.  This means that
by default both codes do the same thing.  If you make a mapping for <xF2>,
because your terminal does have two keys, the default mapping is overwritten,
thus you can use the <F2> and <xF2> keys for something different.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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