0

There have been many postings on this issue but none have worked for me. I'm running vim 8.2 on linux ubuntu 20.04, which maybe why some of the postings haven't worked. Like many, I'd like to remap F1 to ESC. I first tried this in .vimrc

map <F1> <Esc>
imap <F1> <Esc>

But it didn't work. A suggestion on the web suggested that F1 was being mapped to something else, and proposed doing this while in insert mode in vi: CTRL V then F1. When I did this, the command returned \[OP. Then I tried putting these lines into .vimrc

map <\[OP> <Esc>
imap <\[OP> <Esc>

That didn't help either. I also tried, in desperation, the same command but omitting the \ and the \[ but neither worked either.

Can somebody offer another suggestion please? Surely there's some configuration file for vim that sets the F1 -> help binding in the first place that I can tinker with?

Thanks for any advice

7
  • I should think [n]noremap <F1> <esc> (and inoremap) would work. We have a post on debugging a mapping somewhere – D. Ben Knoble May 20 at 0:31
  • I wonder if your terminal even passes on the F1... If you're in Vim and in Insert mode, then type Ctrl+V followed by F1, does it insert any characters? Or is the terminal opening its help system when you press F1? If the latter, then you need to reconfigure the terminal (i.e. it's not really a problem in Vim, but in your terminal instead...) – filbranden May 20 at 1:45
  • What does :set <F1> return? Does it mention the same ^[OP you see when you enter it in Insert mode with Ctrl+V? – filbranden May 20 at 1:49
  • Thanks for your responses. The terminal is definitely opening vim's help menu not it's own. The command :set <F1> returns this: t_k1 <F1> ^[[11;*~ What should I then put inside my map command? – Leo Simon May 21 at 4:09
  • Since I couldn't get any of the proposed solutions to work, I used brute force, and deleted /usr/share/vim/vimXX/doc/help.txt. Obviously a completely crappy solution. vim reports an error when i hit F1 by mistake, but it's better than the even more infuriating alternative. – Leo Simon May 30 at 4:35

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.