Aswin Anand
Aswin Anand

Reputation: 545

Vim remap F10 key

I use Vim 7.3 on FreeBSD. I connect to this machine through Putty. When working on Vim, I'm unable to remap F10 key to do something I want. In my .vimrc, I did the following:

nmap <F10> :!ls<CR>

Then I did, "source $MYVIMRC" to load the changes in .vimrc. When I press F10 after this, it prints ^[[21~ instead of the executing the map. I tried all combination of noremap but nothing works.

Remapping this to other function keys is not an option because they are mapped for other uses.

Just FYI, in Putty configuration options, under Terminal->Keyboard, I have set the "Function keys and keypad" option to "Linux".

Any suggestion to get this to work?

Upvotes: 3

Views: 2014

Answers (1)

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143334

It sounds like your termcap/terminfo and/or the value of $TERM you're using are preventing Vim from recognizing the character sequence your terminal is sending for F10 as F10.

The easy workaround is to map the character sequence. In your .vimrc, type the following:

nmap <CTRL-V><F10> :!ls<CR>

Where <CTRL-V><F10> is pressing CTRL-V followed by F10. This will result in something like ^[[21~ appearing in your buffer. That's okay, this mapping should work (at least with that terminal).

The "right" fix would be to change the value of $TERM, your termcap or terminfo database such that Vim knows that ^[[21~ is F10. Setting $TERM to xterm may work.

Upvotes: 5

Related Questions