Why can’t I map—using any of the *map
commands (nmap
, imap
, etc.)—the Ctrl+0 through Ctrl+9 key strokes? In fact, it appears that some of them, like Ctrl+3, are bound to ^[
at the X Window level. How can I make Vim override those default bindings?
That is, if I do imap <C-3> fancystuffhere
, typing Ctrl+3 in Insert mode puts me into Normal mode, instead of inserting 'fancystuffhere'.
I’m using X11 on Linux.
On MS-Windows, if the mswin. vim file is used, then CTRL-V is mapped to paste text from the clipboard. In this case, you can use CTRL-Q or CTRL+SHIFT+V instead of CTRL-V to escape control characters. In the above command to enter a single ^V, you have to press Ctrl and v.
<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.
Both Vim and gVim use byte queue instead of keypress event queue, so that values from 0x40 (@
) to 0x5F (_
), including the 0x41–0x5A (A
–Z
) 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With