13

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.

alfredodeza
  • 261
  • 2
  • 6
  • 3
    Get rid of caps lock, you don't need it. If you ever need to type in all caps for more than 60 sec drop a burden in your shift key. – sidyll Jul 26 '11 at 12:52
  • 3
    I'm specifically saying that I do not want to do that, so no point in suggesting I should get rid of it. –  Jul 26 '11 at 13:01
  • 2
    I find the CapsLock key so easy to hit that I remapped it to Escape. Works for me. :) – dash-tom-bang Jul 26 '11 at 17:42
  • 1
    Along with converting my caps lock to Escape, it's also a Control. Yes, it's both an escape and a control *at the same time*! In linux, you do can do so via `xmodmap -e "add Control = Escape"`. Hope you enjoy. :-) – evaryont Jul 27 '11 at 05:41
  • [CapSee](http://www.threemagination.com/capsee/) does the job on OS X. Not the answer you were looking for, but it happens to be the right answer most Apple users. – earlio Feb 13 '14 at 07:34

1 Answers1

4

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.

  • 2
    what language is that? I would prefer to have VimScript/VimL to make Vim take care of that (updating my question) –  Jul 26 '11 at 12:49
  • 1
    That's for AHK (Automation hotkey scripting) so no use for you. Tried to look from google and couldn't find anything vim specific for your problem :/ –  Jul 26 '11 at 12:59
  • 3
    The idea is good but how can I put this in my .vimrc, for example? How do I use this with vim? =| – Eduardo Lucio Jun 19 '17 at 22:18
  • Hahaha! Oh, that's just too funny. You really couldn't make it up. Configuring vim is like doing a Rubics cube with chopsticks. – markling Apr 14 '21 at 12:56