How to map Caps Lock to Esc for Vim in macOS?

Viewed 2804

I use vim to develop on my mac and I updated to Mountain Lion yesterday. I was using http://pqrs.org/macosx/keyremap4macbook/ this to remap the escape key's function to caps lock to switch between edit and insert modes. I can't really functionally develop in vim without this and it doesn't seem to work in Moutain Lion. I really need a solution soon!

Thanks a lot guys.

2 Answers

You can achieve the same using the accessibility features of macOS. A usage example:

  1. Map Caps Lock to Esc;
  2. Map double Shift to Caps Lock.

To achieve (1) go to Settings > Keyboard > Special keys. In the appeared dialog set the desired mappings.

To achieve (2) go to Settings > Accessibility > Keyboard > Hardware > Activate lock keys.

So now if you have taps on you'll even have a logo on your screen notifying you about that.

NB. These are system-wide settings, not only for vim, but I believe it doesn't make a lot of sense to have a special mapping only for one editor, it will only make things more confusing.

NB. The Settings names could differ slightly for you, since I had to translate them from Dutch. Use some fuzzy logic to get to the right place.

Related