I’m an avid vim user and have started to write some SQL code recently. I like to write my SQL statements in CAPS and sometimes forget to switch CapsLock ‘off’ and I then quickly wreak havoc on my code before I realise what’s happening.
I have so far not found any way to tell whether the CapsLock key is on other than looking at my keyboard (which requires me to look away from the screen which I consider a big delay).
Ideally I would like vim to automatically change my background colour whenever CapsLock is ‘on’ but I’d be willing to settle for some other on-screen indicator of CapsLock status as a compromise.
The best I can give you is to have vim toggle the background color whenever the CAPSLOCK key is hit in vim.Vim can’t detect the CAPSLOCK key alone. What I can give you is a mapping so you can use some other key (in this example, F3) to act like the CAPSLOCK key for insert mode, and change the background color when all-caps is on. Hopefully this will give you the functionality you need.
Put the following in your ~/.vimrc or in the appropriate ~/.vim/ftplugin/<filetype>.vim :
This borrows some from Tim Pope’s capslock.vim.
If you really want to use the CAPSLOCK key for this, depending on your platform, there’s a bunch of free apps that let you remap your CAPSLOCK key to something else, so you could set it up so that when you hit CAPSLOCK, vim (and everything else) got F3. Or whatever. This would interfere with other apps getting the CAPSLOCK key though (unless the key-remapper app is clever), so that could be troublesome.