In bash, I press ctrl+v to start verbatim insert. In the verbatim mode, I press the Esc key and bash shows ^[
. I redirect it to file esc
.
Also in the verbatim mode, I press ctrl key with [ key, and bash shows ^[
. I redirect it to file ctrl
.
Next, I compare the two files, and they are the same!
$ echo '^[' > esc
$ echo '^[' > ctrl
$ diff esc ctrl
$
Why do Ctrl+[ and Esc produce the same content?
Is ^[
here the C0 and C1 control codes? If so, the wiki article says ^[
is Escape, so why is ctrl+[ also Escape?
The root problem is that I want to check and create a key binding.
(zsh)$ bindkey -L
...
bindkey "^['" quote-line
...
So do I need to type ESC+'
or ctrl+[+'
?
od -a
, then Ctrl-V Enter Enter Ctrl-D: you will see a “cr” (the verbatim Enter) followed by a “nl” (the translated Enter). – Edgar Bonet Oct 17 '22 at 21:20stty -a
tells you what your terminal driver expects. Note that bash (and probably every program using libreadline) does not rely on the terminal driver (it sets it to raw mode), and accepts both Ctrl-? and Ctrl-H irrespective of the setting of the “erase” character. – Edgar Bonet Oct 17 '22 at 21:20