I have a Debian 10.0 system. It has zsh 5.7.1 (x86_64-debian-linux-gnu). In ZSH prompt, I type
foo bar baz
Then I type alt + backspace two times. The words baz
and bar
get deleted and only foo
remains.
Then I type ctrl + / two times to undo the deletions. The words baz
and bar
reappear.
How is ctrl + / working as the undo command? I don't see it defined anywhere?
$ echo / | grep -E "/|undo" # just testing my regex
/
$ bindkey -l
.safe
command
emacs
isearch
main
vicmd
viins
viopp
visual
$ bindkey -M .safe | grep -E "/|undo"
$ bindkey -M command | grep -E "/|undo"
$ bindkey -M emacs | grep -E "/|undo"
"^X^U" undo
"^Xu" undo
"^_" undo
I also have a macOS Catalina 10.15.7 with zsh 5.7.1 (x86_64-apple-darwin19.0) and ctrl + / does not do anything there.
Best Answer
There's no control character for Control+/, so there's no natural choice of character or character sequence that the terminal can send. Many terminals send
^_
, i.e. the same character as Control+_. This includes xterm, rxvt, konsole and all terminals based on the vte library (Gnome Terminal, Mate Terminal, lxterminal, Terminator, …), but not macOS's built-in Terminal application.You can see what your terminal sends by typing Ctrl+V then Ctrl+/. Ctrl+V means “insert the next character literally” (even if it would be otherwise interpreted as a command).
(For the role of the terminal, see How do keyboard input and text output work?)
^_
is the shortcut for undo in Emacs and applications with Emacs-inspired keyboard shortcuts.