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.
The Linux kernel generates a code each time a key is pressed on a keyboard. That code is compared to a table of keycodes
defining a figure that is then displayed.
This process is complicated by Xorg
, which starts its own table of keycodes
. Each keycode
can belong to a keysym
. A keysym
is like a function, started by typing a key. Xmodmap
allows you to edit these keycode-keysym
relations.
To get the current keymap table using Xmodmap
use:
xmodmap -pke
This will print out the full table in the following format:
keycode <keycode#> = <boundkey> <boundkey>
Before moving anything around be sure to backup the original keycode
layout using xmodmap -pke >> $HOME/Xmodmap.orig
This will place the file Xmodmap.orig
in your users home directory.
Tip: There are also some predefined keycodes (e.g. XF86AudioMute
, XF86Mail
). Those keycodes can be found in: /usr/include/X11/XF86keysym.h
You can also also edit the keys: Shift
, Ctrl
, Alt
and Super
(there always exists a left and a right one (Alt_R=AltGr
)).
Here's a quick example of how your configuration would look if you wanted to swap CTRL
and Super
(Windows Key):
keycode 255 =
!add Shift = Shift_L Shift_R
!add Lock = Caps_Lock
add Control = Super_L Super_R
!add Mod1 = Alt_L Alt_R
!add Mod2 = Mode_switch
!add Mod3 =
add Mod4 = Control_L Control_R
!add Mod5 =
(the !
is used to comment / ignore the line. in this example only Super
and Control
keys get adjusted)
This configuration would be saved in $HOME/.Xmodmap
and loaded with
xmodmap ~/.Xmodmap
You could also start this with xwindows by adding it to your ~/.xinitrc
And if things get hairy you can always revert back to Xmodmap.org
.
Any bindings for applications that rely on these keys would also be moved. So make sure that everything remains bound so you don't lose any functionality. It's a tug-of-war match.
Best Answer
There are two line editors at play here: the basic line editor provided by the kernel (canonical mode tty line editor), and bash's line editor (implemented via the readline library). Both of these have an erase-to-previous-word command which is bound to Ctrl+W by default. The key can be configured for the canonical mode tty line editor through
stty werase
; bash imitates the key binding that it finds in the tty setting unless overridden in its own configuration.The
werase
action in tty line editor cannot be configured. It always erases (ASCII) whitespace-delimited words. It's rare to interact with the tty line editor — it's what you get e.g. when you typecat
with no argument. If you want fancy key bindings there, you can run the command under a tool like rlwrap which uses readline.Bash provides two commands to delete the previous word:
unix-word-rubout
(Ctrl+w or as set throughstty werase
), andbackward-kill-word
(M-DEL
, i.e. Esc Backspace) which treats a word as a sequence of alphanumeric characters in the current locale and_
. If you want Ctrl+Backspace to erase the previous sequence of alphanumeric characters, don't setstty werase
, and instead put the following line in your.inputrc
:Note that this assumes that your terminal sends the Ctrl+H character for Ctrl+Backspace. Unfortunately it's one of those keys with no standard binding (and Backspace in particular is a mess for historical reasons).
There's also a symmetric command
kill-word
which is bound toM-d
(Alt+D) by default. To bind it to Ctrl+Delete, you first need to figure out what escape sequence your terminal sends, then add a corresponding line in your.inputrc
. Type Ctrl+V then Ctrl+Delete; this will insert something like^[[3;5~
where the initial^[
is a visual representation of the escape character. Then the binding isIf you aren't happy with either definition of a word, you can provide your own in bash: see confusing behavior of emacs-style keybindings in bash