Kill the CAPS LOCK!
The Caps Lock key can do wonders to wreak havoc in VI. You’re in command mode, minding your own business, when all of a sudden all hell breaks loose. All because you pressed the caps lock key instead of the shift key.
For a long while I was reluctant to follow the plethora of tutorials on how to kill the caps lock key. The reason is that there are several cases where I thought it was very beneficial to actually use it to, well, lock the caps. For example, by tradition, definitions in C/C++ are written in all capital letters. I finally figured out how to get along without the evil key, as I will explain below:
g~w - capitalize one word
g~~ - capitalize the entire sentence
gU{motion} - capitalize motion
I still have some open issues. For example, to capitalize the word I just wrote, I have to go backwards (‘b’) and then capitalize it (‘g~w’) and then go back to insert mode (‘A’). I’ll be happy to learn of better options, options that take into account that I despite having to configure my setup. Nonetheless, I’m now much better off than I was with the occasional caps lock accident.
You can now make the caps lock key do something else, such as behave as a shift key or an esc key.
-
In OS-X - see this serverfault (stackoverflow sibling) page.
-
In Linux - Vim Tip 166
-
In Windows - Map_caps_lock_to_escape_in_Windows
Further Reading:
- Programming with Vi - Tips for using VI as a programming editor.
- Programming Editors - Why I started learning VI.
- Configurability - Why I hate to have to configure software.
- Source Code Highlighting - How to use VI to highlight source code in Blogger.