3

i have mapped my caps lock key to ctrl with the following command under linux:
setxkbmap -option ctrl:nocaps I really like this mapping and want to keep it, but I also would like to map the caps lock key to Escape when I am inside vim. But when I try to map it with :map <C> <Esc> or similar it does not seem to work, presumably because the ctrl key is special and needs a second key to to trigger an key event.

Is there any way I can achieve the above?

user400332
  • 107
  • 9

2 Answers2

3

Dave is right, you can't. However, there are lots of alternatives to remap the escape key. I personaly use ` which is close (on my keyboard) to the capslock key :-) (as ' is pretty useless , you can remap ' to `)

noremap ' `
noremap ` <Esc>
mb14
  • 22,276
  • 7
  • 60
  • 102
  • It is true that there are lots of alternatives. Myself I have the Tab key mapped to Escape, which means I can do instead of hitting Escape because in Vim Control + i is equivalent to the Tab key. This is quite an ok solution for me personally.. – user400332 Jul 31 '10 at 17:31
2

No. The control, shift and alt keys are handled differently at the hardware and OS levels - they do not generate keycodes but add modifiers to the keycodes generated by other keys. This means that they cannot be mapped within Vim.

Dave Kirby
  • 25,806
  • 5
  • 67
  • 84