2

My environment

MacOS:

Catalina 10.15.5 (19F101)

VSCode:

Version: 1.45.1
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:33:47.663Z
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 19.5.0

VSCode Vim:

v1.14.5

Issue

Often times, when I press the caps lock key in insert mode or command mode, I forget to press it again to turn it off when we enter normal mode, and that can cause a lot of trouble.

So there is a solution for it for the regular vim that you use in a terminal.
https://vim.fandom.com/wiki/Insert-mode_only_Caps_Lock

Question

What I've tried that didn't work

  • Since VSCode supports ..vimrc, I created it and put this code, but it didn't work. (This works with regular vim in the terminal)
for c in range(char2nr('A'), char2nr('Z'))
  execute 'lnoremap ' . nr2char(c+32) . ' ' . nr2char(c)
  execute 'lnoremap ' . nr2char(c) . ' ' . nr2char(c+32)
endfor
autocmd InsertLeave * set iminsert=0
Gama11
  • 24,825
  • 7
  • 56
  • 81
KIYZ
  • 273
  • 2
  • 8
  • How about switching `Caps Lock` to `ESC` or `CTRL` and the `ESC` key to `Caps Lock`? I almost never need `Caps Lock`, so the 'far away' `ESC` key seems perfect for this :) – okket Feb 17 '21 at 14:39
  • @okket I use vim for editing a lot of sql files and by style I choose uppercase sql. I run into this issue a lot... really just need to figure out a way to toggle capslock off when escape is pressed, while retaining normal capslock functionality in normal mode. – spencer741 Feb 17 '21 at 14:50
  • It doesn't seem like there is a "toggle capslock" command or anything similar for vscode. I don't have a lot of experience in vscode bindings... perhaps there is an easy solution that we are missing here... See: https://github.com/Microsoft/vscode/issues/13312#issuecomment-753669065 – spencer741 Feb 17 '21 at 14:54
  • Personally, I'd use an script or plugin that autoformats the SQL queries for me, see here for some good pointers for VIM https://stackoverflow.com/a/8577782/2955999. But I can understand the need for Caps Lock in general, e.g. when dealing with a lot of SQL outside of VIM. – okket Feb 17 '21 at 15:25
  • Honestly at this point, I have forced myself to either use shift or explicitly remember to press turn capslock off before I escape to normal mode. – spencer741 Feb 18 '21 at 05:18

1 Answers1

1

Maybe sedleds and an autocmd like

autocmd InsertLeavePre * !setleds\ -caps

untested

I tried with import pyautogui ; pyautogui.press('CAPSLOCK') and that toggles the caps key, but I have not found a way how to detect if capslock is 'locked' or not. It would otherwise work with linux, windows and macos as it seems.

MaxC
  • 341
  • 2
  • 9