Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: remapping Shift-Cmd-Opt-Ctrl to Escape

Tags:

vim

It seems like this article by Steve Losh has been making the rounds, and in short, it led me to remap Caps Lock to F19, and at the system level, to remap F19 to Shift-Command-Ctrl-Alt, thus giving me an entire namespace for my own keyboard shortcuts.

The problem is I enjoyed using Caps Lock as my escape key in Vim. I tried :map <M-C-D-S> <esc>, but upon sourcing, hitting caps lock doesn't do anything. I'm guessing it's because Vim expects an actual key to be pressed with the modifiers.

My question is: is it possible to have Vim read Shift-Cmd-Ctrl-Alt as Escape?

like image 322
Josh Whittington Avatar asked Apr 27 '26 20:04

Josh Whittington


1 Answers

No, you can't map four modifiers. Not even three, Not even two. And, well… not even one.

"Modifiers" are called "modifiers" for a reason: they are used with normal keys to "modify" their meaning. The Shift, Alt, Cmd and Ctrl keys don't do anything on their own and Vim rightfully does nothing but wait for further keypresses when you hit them.

Additionnaly, Vim's input mechanism is a bit "old school", most probably to keep it consistent over the multiple platforms it may run on. It won't register more than one modifier with a normal key. That means that, if the terminal doesn't eat them up (which it does), you can only do <C-…> or <S-…>. The Alt key is not really a working solution because of how many terminal emulators deal with it and the Cmd key is Mac-only and only works in MacVim anyway.

At that point, if you are ready to mash four keys together to emulate the function of only one key (which in itself is rather silly), you might as well simply use <C-c> which, AFAIK, works everywhere. Your left hand will thank you.

like image 173
romainl Avatar answered Apr 30 '26 21:04

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!