Search code examples
macosbashvimmacvimiterm2

How to find the correct combination for a key's ESC sequence in iTerm2


I have been trying to fix a terminal emulator behaviour in a situation where MacVim is running in iTerm2. I have the following key combinations assigned to individual actions in my Vim setup:

F10, action_A
CTRL-F10, action_B
SHIFT-F10, action_C

When I use those combinations in iTerm2 with Vim, SHIFT-F10 is interpreted correctly as action_A. However, the emulator is not able to distinguish between CTRL-F10 and F10 because of the esc sequence issue.

What I have noticed is that iTerm2 is configured to send Esc+[21;2~ whenever SHIFT-F10 is pressed. So by assigning the same sequence to CTRL-F10 I managed to force SHIFT-F10 and CTRL-F10 to perform action_C and F10 to perform action_A.

This proves that by sending the right esc sequence, one should be able to force iTerm2 to distinguish between different keys.

The question is: If SHIFT-F10 is associated with Esc+[21;2~ how do we find what CTRL-F10 is associated with? How do I find the esc sequence that represents CTRL-F10? or maybe the Hex Code? (as iTerm2 provides the option of sending a Hex Code to the terminal session)


Solution

  • Control-F10 could be sent as "\e[21;5~", using the action 'Send text with special chars'. Complete answer is here: how do I know what CTRL-F10 is associated with?