Vim – Is Capslock on

capslockvim

When I work with Vim I almost never look at my keyboard (like it should be!) and this is great, but sometimes, unknowingly I hit the CapsLock key and causes me to yell at my screen.

Because, you know, j is not the same as J in normal mode (and so on).

So instead or mapping CapsLock to say Ctrl I want to display an error message that will warn me in normal mode if this is the case.

Is there a way for Vim to tell if you have CapsLock enabled?

Note: I prefer a VimScript/VimL solution for portability and because I want Vim to notify me and not depend on the actual system.

Best Answer

You can use a script like this:

; INDICATE WHEN THE CAPS LOCK IS ON WITH A SCREEN MESSAGE
Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption
Gui, Font, caf001e s30 bold ,Verdana ;changes font color, size and font
Gui, Color, af001d;changes background color
Gui +LastFound  ; Make the GUI window the last found window for use by the line below.
WinSet, TransColor,af001d
Gui, Add, Text, ,CAPS LOCK ON
; TOGGLE THE GUI ON AND OFF
~capslock::
   if(0==GetKeyState("capslock","T")){
      Gui,  hide
   }else{
      if(guilocation>0){
         guilocation=0
         Gui, Show,x600 y800 NoActivate
      }else{
         guilocation=1
         Gui, Show,x600 y400 NoActivate
      }
   }
return 

Taken from Here. Now Vim will display CAPS LOCK ON whenever your caps lock is on

Update: And that's a script for AHK (Automatic hotkey scripting language). According to this conversation it is impossible to create a behaviour your're descripting using only vim.

Related Question