Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
    
thanks very much - this was bugging me – cwd Jul 5 '12 at 18:30
    
@Daniel: can you take a look at superuser.com/questions/731427/how-do-i-send-ctrl-in-iterm2 ? – eugene Mar 20 '14 at 14:59
    
Thanks @Daniel. I am trying to get the hex codes for other key combinations (C-M-<char>) in this thread, but it isn't clear to me what those hex codes would be. Your input on that thread would be extremely helpful – Amelio Vazquez-Reina Sep 8 '14 at 15:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .