CTRL+_ is used to do UNDO in console; is it possible to map that another key combination like CMD + Z?
1 Answer
Yes, but that depends on your shell. In bash, you have to use bind:
$ bind '\C-t':undo
This will bind Ctrl-t to undo. Note that you cannot bind Ctrl-z in most terminal emulators. Refer to help bind for more information.
If you want the current list of all key bindings, use bind -P | grep -v "not found".
In zsh, you have to use bindkey:
$ bindkey '\C-t' undo
Keep in mind that you probably want to remove the old bindings for whatever key you'll choose. For example, \C-t is bound to transpose-chars.
In case you're wondering where all those combinations come from: Emacs. See man 1 bash, section "Readline Command Names" for more information.
-
You actually can bind
Ctrl-zinzsh. Also, this does not depend on the terminal emulator, but on the shell. While a terminal emulator might preventCtrl-zfrom being used, I think it unlikely that any terminal emulator actually does do this, as this is shortcut is generally used to sendSIGSTOPto the running process.Adaephon– Adaephon2016-10-10 13:53:33 +00:00Commented Oct 10, 2016 at 13:53 -
1The "inability" to bind Ctrl+z or Ctrl+c is because the terminal intercepts these and sends signals instead, thus the shell does not see these characters. But if you bind Ctrl+z (or Ctrl+c) and reconfigure the terminal (e.g.
stty susp ^Y intr ^U) then the binding(s) will work.Kamil Maciorowski– Kamil Maciorowski2022-08-09 05:54:00 +00:00Commented Aug 9, 2022 at 5:54 -
1@Adaephon, that's
SIGTSTPsent to the foreground process group / job, not "SIGSTOPsent to the running process".Stéphane Chazelas– Stéphane Chazelas2022-08-09 06:05:57 +00:00Commented Aug 9, 2022 at 6:05