6

I would like to map my CapsLock to Escape. How do I represent CapsLock in .vimrc?

I know to map space to a command I would do something like this:

:map <space> viw

How would I map CapsLock to Escape without doing a registry hack - I'm looking for a Vim command?

If that is not possible without a hack or additional software I would like to assign the shortcut jj to ESC in .vimrc . I'm currently doing this:

inoremap jj <esc>

However if I'm in visual mode this does not work. How could I make jj emulate the escape key?

  • 1
    Are you wanting this in X, the console or both? Also, please look at my edits and format your last edit as per the site styles. – jasonwryan Nov 2 '14 at 0:30
9

I don't think you can map CapsLock from within Vim. You remap it within X using setxkbmap:

setxkbmap -option caps:swapescape

For remapping in the console, if your distro uses systemd, you can use a custom keyboard layout in /etc/vconsole.conf as described on the Arch Wiki, and for other init systems see this U&L answer.

  • I updated my question – Rajeshwar Nov 2 '14 at 0:27
  • 3
    How do you set it so both are escape? – Justin Thomas Sep 2 '16 at 22:50
0

inoremap means insert mode non-recursive map. vnoremap is visual mode non-recursive map. So vnoremap jj <esc> is what you want.

0

You can use a call to xmodmap on Vim startup to map Capslock to Escape. The modification can be reverted once you leave Vim. Add the following lines to your .vimrc:

au VimEnter * silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
au VimLeave * silent! !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Caps_Lock'

However, this will lead to problems if you have multiple Vim sessions. Once you close one of them, the modification is reverted for all of them, since xmodmap operates globally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.