Reputation: 29178
I am working with Cygwin/Mintty/Vim.
With <C-v>
I see that <C-S-c>
is encoded <83>
. This mean vim can read it and I can map it using the map command.
Unfortunately if I try:
:inoremap <C-S-c> foobar
it doesn't work...
How can I make it work and why vim refuses to map Unicode keystokes?
Same question for <C-S-F1>
. If I execute this command:
:inoremap <C-S-F1> foobar
I will get something like this:
[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~[20;5~
Where F1
is [1;5P
and F9
is [20;5~
Upvotes: 3
Views: 3576
Reputation: 172768
Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab>
/ <C-I>
, <CR>
/ <C-M>
/ <Esc>
/ <C-[>
etc. (Only exception is <BS>
/ <C-H>
.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.
Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8
But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.
Upvotes: 1
Reputation: 30428
Vim apparently does not support exotic key combinations involving Control (<C-…>
). That includes F1 – though your other attempted mapping ShiftC is supported (and is equivalent to Control with just C). From a post by Tony Mechelynck on a forum thread “Mapping ctrl-; (ctrl semicolon)”:
The only printable keys which can reliably be used with Ctrl, with predictable results, in cooked mode on any OS, are those defined by ASCII, and that means the following AND NO OTHERS:
- ASCII characters 0x40 to 0x5F (i.e. uppercase A to Z, plus the six nonalpha characters at-sign, left-bracket, slash, right-bracket, [caret] and underscore), where Ctrl subtracts 0x40, thus mapping them to 0x00 to 0x1F respectively. This explains why Ctrl-[ means Esc, Ctrl-I means Tab, Ctrl-M means Enter, etc.
- Lowercase letters, whose Ctrl counterpart is the same as for the corresponding uppercase (thus Ctrl+letter and Ctrl+Shift+letter are always the same for a given letter)
- In addition, Ctrl-? is mapped to 0x7F (DEL).
Vim may or may not see other Ctrl-combinations, but that depends on the terminal, and in most cases it won't see them, or confuse them with something else such as the same key without Ctrl.
As for your <C-S-c>
mapping, I’m not totally sure why you can see <C-S-c>
with <C-v>
but you can’t map it. When I test in MacVim (a GUI), I get the character ^C
when I try <C-v><C-S-c>
, and :inoremap <C-S-c> foobar
works. When I test in OS X’s Terminal, the Terminal swallows the keystroke and beeps, with both <C-v>
and :inoremap
. In both cases, <C-v>
’s behavior is consistent with :inoremap
’s, so I don’t know why you are seeing the discrepancy.
Upvotes: 4