Index: src/winio.c =================================================================== --- src/winio.c (revision 5765) +++ src/winio.c (working copy) @@ -331,6 +331,7 @@ int parse_kbinput(WINDOW *win) { static int escapes = 0, byte_digits = 0; + static bool mac_escape = FALSE; int *kbinput, retval = ERR; meta_key = FALSE; @@ -391,7 +392,21 @@ retval = parse_escape_sequence(win, *kbinput); break; case 2: - if (get_key_buffer_len() == 0) { + if (mac_escape) { + /* An "ESC ESC [ X" sequence from Option+arrow. */ + if (*kbinput=='A') + retval = KEY_HOME; + else if (*kbinput=='B') + retval = KEY_END; + else if (*kbinput=='C') + retval = sc_seq_or(do_next_word_void, 0); + else if (*kbinput=='D') + retval = sc_seq_or(do_prev_word_void, 0); + else + retval = ERR; + mac_escape = FALSE; + escapes = 0; + } else if (get_key_buffer_len() == 0) { if (('0' <= *kbinput && *kbinput <= '2' && byte_digits == 0) || ('0' <= *kbinput && *kbinput <= '9' && byte_digits > 0)) { @@ -463,6 +478,9 @@ retval = *kbinput; } } + } else if (*kbinput=='[') { + /* This is an iTerm2 sequence: ^[ ^[ [ X. */ + mac_escape = TRUE; } else { /* Two escapes followed by a non-escape, and * there are other keystrokes waiting: combined