Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect Caps Lock in a Vimrc Function

Tags:

vim

capslock

When editing code in Vim, I will often use caps lock when writing stuff in ALL CAPS. However, I often forget to turn off caps lock when I'm done with the capitalized portion. This causes no end of pain (since, ie, j moves down, but J joins the current line with the line below).

Usually, I want to turn off caps lock when I exit insert mode. How can I add something to my .vimrc so that it will either turn caps lock off when exiting insert mode? Alternately, how could I add something to my .vimrc so that it will alert me (status line? beep? any alert is fine) if I have caps lock on when exiting insert mode?

Thanks!

like image 225
Sam King Avatar asked May 10 '12 08:05

Sam King


1 Answers

Like all other applications, Vim / GVIM sits atop the terminal / window manager abstractions, and therefore has no direct access to the underlying raw keyboard functions. So getting Caps Lock information would involve messy and platform-specific hacks.

Instead, I would advise you to use Vim features to "emulate" Caps Lock within Vim, as this doesn't have the problems you've mentioned. Have a look at the article Insert-mode only Caps Lock, which explains this in detail.

like image 163
Ingo Karkat Avatar answered Oct 15 '22 12:10

Ingo Karkat