How to map <c-[> and <c-{>?

How can I map <c-[ and <c-{>?

I tried:

map global normal "<c-[>" ": echo -debug [<ret>"
map global normal "<c-{>" ": echo -debug {<ret>"

but it doesn’t work. I tried both Kakoune v2020.01.16 and git master.

I use xterm and X.

For historical reasons, <c-[> is the same as the Escape key, which you can’t remap because it’s kind of important to Kakoune. <c-{> doesn’t have a special ASCII code, but in most terminals that key combination probably also sends an Escape to Kakoune.

Someday somebody may write a non-terminal-based UI for Kakoune, in which case those key mappings would probably work fine. Right now, however, I think you’re out of luck.

And what about <c-]> and <c-}>?

I can’t map those either. <c-]> in ASCII is GS (group seperator), so it should not conflict with any other key.

I can’t map <c-]> or <c-}>, but I can do this:

:map global normal ␝ ": echo got ^]<ret>"

…where the special symbol is how Kakoune displays the ASCII group separator character, and is typed (at the : prompt) with <c-v><c-]> (that is, the Ctrl-V prefix makes Kakoune take the next character literally, whatever it is).

Unfortunately, I can’t (easily) figure out what’s going on here. So far as I can tell, when a GS byte is being parsed as a key name, it should be canonicalized into something like <c-}>. so mapping GS and mapping <c-}> should do the same thing. However, that doesn’t appear to be the case.

Likewise, when Kakoune receives GS from the terminal, it should be parsed into <c-}> again. But clearly this isn’t happening.

You mean <c-]>?

The code you linked to checks if key < 27, but GS is 29. So it seems Kakoune mishandles control characters 28 to 31.

As for <c-}>, it seems xterm sends a GS for it too, so it’s indistinguishable from <c-]>. Is there a way to change that?