I'll focus on Ctrl+Delete first.
The zsh command to delete a whole word forwards is called kill-word
. By default it is bound to Alt+D.
How to make Ctrl+Delete do it too depends on which terminal emulator you are using.
On my system, this works in xterm and Gnome Terminal:
bindkey -M emacs '^[[3;5~' kill-word
and for urxvt, you should do:
bindkey -M emacs '^[[3^' kill-word
If that doesn't work, try typing Ctrl+V Ctrl+Delete to see what the value is on your system.
You could even add both of those together to your .zshrc
, or use the output of tput kDC5
instead of hard-coding the sequence.
Ctrl+Backspace seems harder.
On my system, pressing that is the same as pressing just Backspace.
If yours is the same, I think your best option is to use Alt+Backspace or Ctrl+W instead.
Ctrl+W is the standard "kill word" (aka werase
).
Ctrl+U kills the whole line (kill
).
You can change them with stty
.
-bash-4.2$ stty -a
speed 38400 baud; 24 rows; 80 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc -xcase
iflags: -istrip icrnl -inlcr -igncr -iuclc ixon -ixoff ixany imaxbel
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl -onocr -onlret -olcuc oxtabs -onoeot
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = <undef>;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
-bash-4.2$ stty werase ^p
-bash-4.2$ stty kill ^a
-bash-4.2$
Note that one does not have to put the actual control character on the line, stty
understands putting ^
and then the character you would hit with control.
After doing this, if I hit Ctrl+P it will erase a word from the line. And if I hit Ctrl+A, it will erase the whole line.
Best Answer
Here's a snippet from .zshrc i've been using:
I recall this was the original source: http://www.zsh.org/mla/users/2001/msg00870.html