iTerm2 – How to Remap Control+e to Escape+Control+e

iterm2keyboardmacmacos

I have set up a few custom keyboard shortcuts in iTerm2 to easily move the cursor around with the arrow keys, but now I'd like to remap Ctrl+E to be Esc, Ctrl+E because Bash 4.2 no longer auto-expands variables using the Tab key.

I know I've done the first part correctly in choosing the keyboard shortcut to remap, but I don't understand how to look up the correct escape sequence (or hex codes) to send in the bottom section:

Picture.png

I reference they keyboard codes but that wasn't much help.

How can I remap this, and how can I look up the codes in the future? (No luck with Google)

Update

@db – thanks. To save others trouble I also found a cool util Key Codes.app which can be used to find key codes:

Picture.png

Best Answer

Use the following: Send Hex Codes: 0x1B 0x05

  • Escape is ASCII 27 (it's often written as octal \033 if your shell doesn't know \e).

  • Ctrl-[Character] combinations result in the ASCII code corresponding to the character's position in the alphabet. Well-known examples are^H for ASCII 8 (Backspace), ^C for ASCII 3, End of Text, or ^D for ASCII 4, End of Transmission, and likewise, pressing ^E results in ASCII 5 — so that hex code needs to be sent instead.

You can even use this (I cannot imagine a real use case, but let's not care about that) to replace pressing Enter (Line Feed) by ^J, or pressing Tab by ^I. See here for more information about control characters.

Related Question