Reputation: 12187
Bash uses readline, and readline can delete the word to the right of the cursor with "kill-word".
The problem is in recognizing the keypress of control-delete. When I press them in bash, "5~" is output on the screen. I could just bind for this, but it would mean that one day I need to type "5~", and it deletes a word to the right instead! So I'd much rather discover the correct control sequence.
I have googled, and quite a few resources discuss the "delete" key, but none that I've found discuss "control-delete" key. I've experimented with many variations, but nothing works.
The worst is the hours I've spent on this tedious, mindless grind, when it really should be a non-problem.
EDIT: It's through X, so maybe there's a solution with xev and xmodmap
Upvotes: 3
Views: 4411
Reputation:
Alt+D deletes one word to the right of the cursor Ctrl+W deletes one word to the left of the cursor (both are based on Emacs, I believe)
Upvotes: 4
Reputation: 328624
What you see is not the whole truth. It's probably <ESC>5~
or something like that. Try Ctrl-V Ctrl-Delete. The Ctrl-V means "do not interpret the next thing".
So binding <ESC>5~
that should be pretty safe.
Upvotes: 5
Reputation: 8066
On my machine, pressing Ctrl-V, Ctrl-Delete outputs this:
^[[3;5~
The ^[
escape character can be replaced with \e, so you can then use bind like this for bash (in your ~/.bashrc
for example):
bind '"\e[3;5~":kill-word'
Or, you can add the following to your ~/.inputrc
so Ctrl-Delete does kill-word in any program that uses readline:
"\e[3;5~": kill-word
This will bind only the Ctrl-Delete key, you don't have to worry about what will happen if you need to type 5~.
Upvotes: 15
Reputation: 3250
Ctrl-W deletes words.
Ctrl-u deletes lines.
They're based on Emacs (M-w and M-u).
Upvotes: 0
Reputation: 399881
If you type ^Q^V (that's Control-Q followed by Control-V, releasing the Control key between them is fine), and then press Control-Delete, do you get the output you mentioned? I just tried it, and at least using Putty I don't get a response at all. Perhaps the behvior is different on an actual Linux console, though.
For other keys, readline prints a longer sequence, often including a special "command sequence introduction" character, which is hard to type by mistake. Try it, and see if you get a longer sequence with the ^Q^V command (which is, btw, called quoted-insert).
For example, if I press ^Q^V and then Delete (without control held down), readline prints ^[[3~
. This tells me I can bind stuff to the Delete key by saying \e[[3~
. It seems highely likely that the CSI character is present for you, but you're not seeing it since you're not asking readline to quote the input properly.
Upvotes: 2