Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map CAPS LOCK key in VIM?

Tags:

vim

map

capslock

I'm using GVIM under Windows. And want to map CAPSLOCK to Ctrl+^

Any way to do this?

Btw, I see tons of samples over the web how to swap CAPS and Esc using registry hack, but none of them use VIM map command, instead external tools and registry changes.

like image 378
Evgenyt Avatar asked Feb 01 '10 12:02

Evgenyt


People also ask

What does Caps Lock do in Vim?

vim - Software Caps Lock : vim online. This plugin enables a software caps lock. This is advantageous over a regular caps lock in that normal mode commands, other buffers, and other applications are unaffected. The default mapping is <C-G>c but if you use this feature regularly, you will probably want a shorter one.

How do I turn off Caps Lock in Vim?

Instead, when in insert mode, press Ctrl- ^ (hold down Ctrl and press ^ – the 6 key on US keyboards) to toggle "Caps Lock" on or off.


2 Answers

Linux? With X, use xmodmap to alter the key mapping, e.g.

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' 

Will map Esc to the CapsLock key. Google for more examples.

like image 151
Dan Andreatta Avatar answered Sep 28 '22 11:09

Dan Andreatta


If your intention is just to avoid working outside of Vim, you can put these lines in your .vimrc:

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

The first line maps escape to the caps lock key when you enter Vim, and the second line returns normal functionality to caps lock when you quit.

This requires Linux with the xorg-xmodmap package installed.

like image 26
rsoren Avatar answered Sep 28 '22 13:09

rsoren