0

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?

1

^[ 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

  • 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
6

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.

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.