Vim by default maps <F1> to bring up help. I'd like to map <S-F1> (shift + F1) to close the help using the :helpclose
command.
I'm having trouble with this simple task, running inside a Gnome terminal (v 3.30.2 according to Help/About).
First, I start vim with vim -u NONE
. I use ^V to show the sequences generated from <F1> and <S-F1>:
Press F1: ^[OP
Press S-F1: ^[[1;2P
~
~
~
I then ask Vim about <F1> using:
:set <F1>?
it replies:
t_k1 <F1> ^[OP
So apparently we are on the same page for <F1>. And it works! If I press <F1> I get a help split.
Then I ask vim about <S-F1> in the same way, and it says,
E846: Key code not set: <S-F1>?
Then I ask about all the keys with :set termcap and I get a bunch of info, including all the unshifted F-keys, but no shifted keys.
Determined to continue anyway, I choose to tell vim about what my terminal does (square brackets are keys I press, spaces added here for clarity):
:set <S-F1>= [Ctrl-V] [Shift-F1]
:set <S-F1>=^[[1;2P [Enter]
Then when I ask again, I get the expected answer?
:set <S-F1>?
<S-F1> ^[[1;2P
Finally, I try something super basic:
:map <S-F1> :echomsg "Shift Eff One!"<CR>
When I press <S-F1> in my empty window in normal mode, I get:
E353: Nothing in register "
I suspect that this is because I haven't deleted or yanked anything, and my escape sequence "...P" is trying to paste. Which means that my keystroke mapping didn't work.
What am I doing wrong?
F1
throughF4
versusF5
and up in VT100 terminal emulation... Some terminals prefer to encode Home, End and the F1 to F4 function keys using shorter CSI letter encodings (Try<S-F5>
... it should work for you if your system is like mine.) Hopefully, someone can shed some better light on this.<S-F1>
after setting the escape sequence for it. One thing to watch out is that^[
is actually the Esc character. Your post describes the right sequence to get this right, so I'm guessing that's not why it didn't work for you... Still, you could use an alternative approach such as:execute "set <S-F1>=\e[1;2P"
which doesn't depend on the special character and might work better in a vimrc file, for instance...