开发者

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

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜