I have a settings and a zsh session

~ bindkey | grep help    
"^[H" run-help
"^[h" run-help

Why when i press "Control + [ + h" word under cursor removes and nothing happens, but if i press "Alt + h" man page opens correctly?


^[ actually means Escape character. Check here: https://en.wikipedia.org/wiki/ASCII

In your case it seems your ALT key works as a synonym for Escape key: https://en.wikipedia.org/wiki/Alt_key

| improve this answer | |
  • No. Other bindkeys with Ctrl works normal. – Pavel Patrin Apr 26 '16 at 7:24
  • What you mean "with Ctrl"? Can you give an example? – alpert Apr 26 '16 at 7:36
  • "^W" backward-kill-word. Ctrl + W removes previous word. – Pavel Patrin Apr 26 '16 at 7:43
  • 1
    Man, single ^ means Ctrl and ^W works with Ctrl + W, but ^[ is a special character on its own so it is not Ctrl + [. – alpert Apr 26 '16 at 7:45
  • @alpert ^[ in fact does mean Ctrl + [, you can just not combine it with other characters by pressing them at the same time. – Adaephon Apr 26 '16 at 9:26

Try pressing Control+[ immediately followed by h.

Terminals do not send key presses directly to the shell (as in Control was pressed/released). Instead the terminal sends character sequences depending on keys pressed. The keys in a sequence are to be pressed - well - in sequence, not all at once. The big exception to this are the Control-keys and the Alt-keys which are pressed at the same time with other keys to create a specific sequence.

As you already know/noticed ^ is used as symbol for the Control-key, but it only has this meaning in conjunction with the following character. ^A means Control+a or Control+A, the key sequence is the same for upper and lower case characters in combination with Control (that is also the reason why terminals often use Control+Shift+SOMEKEY for their own, not shell-related shortcuts).

^[ literally means Control+[. It is also sent by the Escape. So ^[a means Control+[ followed by a (lower case!). Additionally, the Alt-key also sends the ^[ sequence followed by the key it was pressed with. So Alt+a also sends ^[a. Alt+Shift+a sends ^[A.

So for your example you can press either of these ('+' means "at the same time", ',' means "in sequence"):

  • for ^[h
    • Alt+h
    • Escape,h
    • Control+[,h
  • for ^[H
    • Control+[,Shift+h
    • Alt+Shift+h
    • Escape,Shift+h

Special keys like PgUp, Backspace, Return or KP_Enter also send key sequences. These often depend on the terminal emulator. You can use the quoted-insert or vi-quoted-insert widgets to show the key sequence. By default they is bound to ^V in their respective modes. So pressing Control+v followed by the key combination in question will show the sequence you can use for bindkey. For termite on my machine I get:

  • PgUp: ^[[5~, which is also Control+[,[,5,~ or Escape,[,5,~ or Alt+[,5,~
  • Backspace: ^?, which is also Control+?
  • Return: ^M, which is also Control+m
  • KP_Enter: ^[OM, which is also Control+[,Shift+o,Shift+m or Alt+Shift+o,Shift+m

In theory the key sequences can be arbitrarily long and complicated. For example with:

bindkey '^[xfooba^r' run-help

Alt+x,f,o,o,b,a,Control+r will run the run-help widget.

There is a bit of a limit as zsh only waits a certain time for another character, before it accepts a multi-character sequence. This timeout can be configured in the KEYTIMEOUT parameter in hundredths of seconds. The default is 40, so 0.4 seconds.

| improve this answer | |
  • what does ^[^[[D mean? It was in bindkey '^[^[[D' emacs-backward-word. – blueray Jul 14 at 15:24
  • 1
    @blueray This translates to the sequence Control+[, Control+[, [, D, which is the same as Esc, Esc, [, D. Depending on the terminal there are some other key combinations that send the same sequence. Esc, [, D is the sequence (usually?) sent by the Left key. So pressing Esc, Left should have the same effect. In some terminal emulators you can even press Alt+Left to achieve the same effect (for me this works with urxvt but not with xterm or termite, which send ^[[1;3D instead). – Adaephon Jul 21 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.