I'm pretty new to vim, and I'm starting to discover it, and seeing how important the ctrl key is. I've seen that many remap the caps lock key to ctrl and escape at the same which seems really useful, but the problem is I've already remapped caps lock as backspace a long time ago. So I was thinking if I could remap my caps lock to both backspace and ctrl. I don't need the escape key because I can use ctrl+[.

I'm not sure how this would work because I sometime long press caps lock (ie backspace) to delete many character, and seeing online the solution to remap ctrl and esc to caps lock would be use ctrl when the key is long pressed and escape when the key is released. In my case I'd need long press for ctrl and backspace when released, so I won't be able to delete many character with one press. I was thinking that I could put a one second timer when pressing caps lock, and if I don't get an input while pressing it, it will act as if I'm long pressing backspace, and if I release it before the one second it will also act as backspace. So ctrl would only be activated when pressing caps lock and pressing another key within the one second time.

I don't know if this is even achievable or no.

If possible I'd prefer if I could make this change only take place when I'm in vim (I'm also okay with it now being only in vim, but prefer it only in vim). I use WSL with Ubuntu if this makes any difference.

  • 1
    Welcome to Vi and Vim! While Vim does have ability to do key mappings, it can only do so with keystrokes it can detect (which is not the case with Caps Lock) and if two keystrokes produce the same key code it can't distinguish them from each other (for example, Esc and Ctrl+[, or your Caps Lock remapped to backspace vs the actual backspace.) So usually you need to do these remappings at the O.S. level (in your case, it seems there are two O.S.'s involved.) Not sure if you'll be able to get your O.S. to detect Vim is running and do a different remapping then...
    – filbranden
    Commented Sep 20, 2020 at 2:39
  • Okay if it's impossible to do in vim, how can I do it from the OS then? I'd prefer it only in vim, because this is the only place where I need the ctrl key, but if it can't be done then I'm alright with it Commented Sep 20, 2020 at 3:27
  • 1
    it's possible on some keyboards supporting QMK, like Ergodox with "dual function key". ergodox-ez.com/#dualfunctionkeys Commented Sep 20, 2020 at 8:48
  • 1
    It's not Windows it's Ubuntu (via WSL) so you might try Ask Ubuntu or Unix&Linux rather than SuperUser. Isn't there a *nix equivalent to Windows AutoHotKey...autoit maybe? (You can't use AutoHotKey in any simple way because it can't easily determine what program your running inside of WSL.)
    – B Layer
    Commented Sep 20, 2020 at 11:16
  • 1
    Autokey is what I was thinking of. I guess there's also one called IronAHK, too. Dunno if either can detect CapsLock, though. (If you were using gvim OTOH AutoHotKey would be a simple solution...I use it myself for the same purpose.)
    – B Layer
    Commented Sep 20, 2020 at 11:21

1 Answer 1


I managed to do what you wanted to do by using hack in PowerToys which has Keyboard Manager utility. Read carefully to understand what's going on here :D

PowerToys side:

  1. Remap CapsLock to some unused keycode: I used Ctrl+F7 (F31)
  2. Remap Ctrl+F7 to Backspace system-wide ("In all apps")
  3. Remap Ctrl+F7 to some other unused keycode (Ctrl+F8) for your terminal (in my case windowsterminal). You can find name of the terminal's process by issuing tasklist in cmd.
  4. Remap another unused keycode (Ctrl+F9) to Ctrl for your terminal or system-wide. PowerToys won't remap this for terminal only but system-wide it works.

Vim side:

  1. Remap Ctrl+F8 to Ctrl+F9 (that is mapped to Ctrl) in normal mode.
  2. Remap Ctrl+F8 to Backspace in insert mode.

Now I use CapsLock as Backspace in my system (which is very convenient) and use it as Ctrl in vim.

Hope this helps.

  • It's a little uncomfortable not able to use e.g. CapsLock+w in browser to close the tab but I think using caps as backspace is more useful and I'll get used to it.
    – никта
    Commented Aug 4, 2021 at 13:54
  • I also had to remap F32 to Backspace in zsh: 1. open shell 2. find which keycodes correspond to F32 and Backspace in zsh: showkey -a and press F32 and Backspace 3. put mapping in .zshrc: e.g. bindkey -s '^[[19;5~' '^?'
    – никта
    Commented Aug 4, 2021 at 14:04
  • 1
    Welcome to Vi and Vim!
    – D. Ben Knoble
    Commented Aug 4, 2021 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.