2

Specs:

  • Vim 8.0 patch 500
  • gnome-terminal 3.18.3 on Ubuntu 16.04 running Unity

Function keys in my vim slightly misbehave, however, in an annoying way: I can't completely use them in my macros. After much trial and error I have given up and think I need help here. Please? :)

Mapping Function keys works

  • nmap <F2><F2> :echo 'works!'<CR>
  • also works: nmap <Leader>2 <F2><F2>

But if I record a macro with function keys in it, it sometimes works, sometimes not. This is what I get when I record a macro with an <F9> in it:

  • The macro is typed as "w<F9>p (put style invocation of something with register w)
  • replaying the macro however, leads to the invocation of my ex command at the receiving end of the mapping with v:register set to a
  • Pasting the macro register yields "w�k9p, which vim renders as vim rendering of pasted macro register and which xxd tells me is the byte string 2277 806b 3970
  • Typing <C-V><F9> in insert mode yields ^[[20~ and I think that is what vim is also expecting to see when <F9> is used in a mapping. It is also what I see when I type F9 into plain cat.

Many of my mappings involve function keys and I want to fix this once and for all. My attempts to date involved the following:

nmap ?k9 <F9>

where the ? is the literal pasted <80> thingy from before. Upon loading that file again, the bracketed representation did not appear again; however, I have confirmed with xxd that the exact byte representation of the symbol in .vimrc is still 80.

Another one through the use of

set <F9>=^[[20~

(inserted literally with <C-V> as you'd expect)

To no avail. Please help me so that I can use the F9 key in a macro! thanks!


Edit 1:

In GVim, I get the exact same behavior. This means, it is not the fault of my terminal emulator, right?

Your Answer

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

Browse other questions tagged or ask your own question.