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.

5
  • 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, 2011 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.
    – alfredodeza
    Jul 26, 2011 at 13:01
  • 2
    I find the CapsLock key so easy to hit that I remapped it to Escape. Works for me. :) Jul 26, 2011 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, 2011 at 5:41
  • 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, 2014 at 7:34

1 Answer 1

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.

4
  • 2
    what language is that? I would prefer to have VimScript/VimL to make Vim take care of that (updating my question)
    – alfredodeza
    Jul 26, 2011 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 :/
    – OsQu
    Jul 26, 2011 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? =| Jun 19, 2017 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, 2021 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .