How can the Ctrl+0 through Ctrl+9 key bindings be mapped in Vim?

Both Vim and gVim use byte queue instead of keypress event queue, so that values from 0x40 (@) to 0x5F (_), including the 0x41–0x5A (AZ) range) have corresponding control characters (you can get their codes by subtracting 0x40 from their value). Because of this, no characters above and beyond this range can be used together with C- (Ctrl).

It is also the reason why C-S- (Ctrl+Shift) for alphanumeric keys does not work even in gVim—functional keys generate more then one byte, so <C-S-F1> may work. Replacing <C-3> with <Esc> is done by terminal; you can try mapping it in almost any GUI application and see that <Esc> does not get mapped.


The way I accomplish this on windows is to use Autohotkey and remap Ctrl+1, Ctrl+2, etc. to Ctrl+F1, Ctrl+F2, etc.

I know you’re on Linux, so it doesn’t apply for you, but thought I’d mention it for anyone else interested.

Tags:

Vim