How do I remove the remaining part of a word in the shell?

I would like to know if there is a key binding for removing the remaining part of a word in the shell.

Here I mean "remaining" as what stays on the right-side of the line cursor.

Example (_|_ is the cursor):

> mv _|_john.csv ~/.hidden
... CTRL-something ...
> mv ~/.hidden

A sort of "light" version for Ctrl+K (which drops the whole trailing chars 'til newline).


bash uses readline(3) for line editing that defines only alphanumerics as word constituent characters.

Now, the key-binding for kill-ing the next word is M-d if you are from the emacs world i.e. use Esc+d or Alt+d.

Now, as john.csv is composed of two words by definition, so you need to press the keys twice.


Alt+d will remove the remaining part of a word. But as a . ends the word you'll need to press it two times to remove john.csv.


If you have set your editing mode to vi (with set -o vi), you can use the delete command.  First, type Esc to get into command mode.  Then dw will delete a short word — either a sequence of consecutive alphanumeric characters, or a sequence of consecutive non-alphanumeric (non-blank) characters, whichever comes first.  In your example, if you type dw, it will delete john and leave you with mv _|_.csv ~/.hidden.  A second dw will delete the ., and a third will delete csv   (i.e., csv and the space after it).

If the “word” (filename) to be deleted is short enough that you can readily count the short words it comprises, you can streamline this by typing 3dw.  But probably the better solution is to type dW (with a capital “W”) to delete a long word — a sequence of consecutive non-blank characters (without regard to whether they are alphanumeric) and the following sequence of consecutive blanks.