When I hit the <s-f2>
key to execute my nnoremap <s-f2> :set number!
mapping Vim opens its "Insert" mode above (O
) and types the 1;2Q
string. In order to see the entire terminal key code – not eaten up half-way by the "Normal" mode – I hit <c-v><s-f2>
in "Insert" mode and get ^[O1;2Q
, where ^[
is the <esc>
character.
Even after reading the "Mapping fast keycodes in terminal Vim" I don't understand why the ^[O1;2Q
terminal key code is not mapped to the <s-f1>
Vim code. Therefore I defined the following function in my ~/.vimrc
file:
function! s:Mod_fix_shift_fkey()
let a=0
let b='PQRS'
while a < 4
exec 'set <s-f' . (a + 1) . ">=\eO1;2" . b[a]
let a+=1
endwhile
endfunction
By calling it I fix the shifted function keys from <s-f1>
to <s-f4>
and the mapping bound to <s-f2>
suddenly works.
Can someone explain?
Also I had to fix the shifted function keys from <s-f5>
to <s-f12>
like:
"...
let a=5
let b='1517181920212324'
let c=0
while a < 16
exec 'set <s-f' . a . ">=\e[" . b[c : c + 1] . ';2~'
let a+=1
let c+=2
endwhile
"...
And from <c-s-f1>
to <c-s-f4>
and <c-s-f5>
to <c-s-f12>
the control-shifted function keys like:
" ...
exec 'map <esc>O1;6' . b[a] ' <c-s-f' . (a + 1) . '>'
" ...
exec 'map <esc>[' . b[c : c + 1] . ';6~ <c-s-f' . a . '>'
" ...
^[O1;2Q
terminal key code isn't mapped to the<s-f1>
Vim code in the first place without any further ado. – Tim Friske Dec 14 '12 at 13:34gnome
has says that^[O1;2Q
is the sequence for thekf14
capability, which is the F14 key. It is common—though not exactly standard—to interpret F14 as Shift-F2; Vim does not appear to pick this up out of terminfo. The lack of standardization is why you need to use the “wildcard” syntax (or your looping technique) to let Vim know which sequences to expect. – Chris Johnsen Dec 15 '12 at 00:10