Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Inspired by this question. I would like to remap Caps Lock to escape, but only when I am in vim. I would like to keep Caps Lock untouched while not in vim.

share|improve this question
Does it matter to you if it is remapped system wide when vim is opened? – Seamus Jun 9 '10 at 19:32
@Seamus: It wouldn't be ideal, but it would be better than a persistent system-wide remap. – Matthew Pirocchi Jun 10 '10 at 4:40
Then you can write a shell script wrapper for vim, that uses xmodmap to change your key bindings. The settings would persist system wide until you quit vim. You would have to also store the total number of open vims somewhere persistent so that you dont change the mappings back until after all of the vims are closed. You would also have to find some one who knows what they are doing with bash (not me, unfortunately). – Seamus Jun 10 '10 at 20:26
up vote 3 down vote accepted

If modifier keys are pressed they are not passed to applications by the OS before any other key is pressed.

Therefor it is not possible to map a single capslock, shift or ctrl key press in applications without remaping it globaly.

share|improve this answer

This may not be the answer you're looking for, and I don't want to start a religious debate, but this is what emacs is good for. As with emacs, you can remap keys and write your own extensions for it.

I don't think this is possible right off the bat with vim.

share|improve this answer
Are you sure that emacs itself can remap caps lock? I don't think a press of caps lock will normally be relayed to an application, but that it will simply modify what is sent afterwards. Otherwise, I agree: with vim, as with emacs, it's possible to implement extensions that use custom keymappings. – intuited Jun 8 '10 at 21:30

I tried doing the same thing and could not find a way to do it. It seems that Vim doesn't see CapsLock as a modifier key, so you can't create a mapping for it.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .