Binding F1 to ESC in VIM

linux-mint, vim

Solution

It may be that your keyboard isn't producing the keycode that Vim translates to `<F1>`. In Vim, go into insert mode, and type Ctrl-v. Then press F1. The string that you just inserted is the string that needs to go on the left-hand side of your `map` command. It might be `<x-F1>` or something similar. You can do this to insert the key name directly in your `.vimrc` file.

Remember to restart Vim after editing your `.vimrc` file.

Regardless of whether you get this working, you might like to swap your Esc and Caps Lock keys, which is quite a popular thing to do among Vim users. You can't do that within Vim, you need to edit your X configuration to achieve it. The Vim tips wiki tells you how.

Problem

Evening, I got a Lenovo T400 laptop, and the F1 is in a stupid place, and keep hitting it instead of hitting Esc to get change modes with VIM. I did some googling, and tried adding ``` map <F1> <Esc> imap <F1> <Esc> ``` to my ~/.vimrc file, but to no avail... If I can't do this with a vimrc, is there a way to change it at the linux/system level? Using Linux Mint 14 MATE -- Answer: The terminal application has it's on keyboard shortcuts defined. Under Edit -> Keyboard Shortcuts you can disable the help. Then the map/imap above will work fine. You can also edit the keyboard settings in the main system keyboard preferences. Open that up and go to Layouts -> Options and play with the Caps Lock key behaviour. You can disable it, or even bind it to ESC.

Original source