Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up my .inputrc to perform a backwards unix-word-rubout but I'm currently failing at doing so.
I have M-w mapped in my .inputrc.

this does not work:

"\eu": universal-argument
"\ew":  "\eu-1\C-w"

nor does this:

"\ew":  "\e-1\C-w"

not even doing it interactively in the shell by pressing M-- followed by C-w works, i.e. it keeps deleting words on the left of the cursor.

PS I know there are other kill/rubout readline commands but i really would like to have the C-w behavior of killing words using space as separator, just backwards.

share|improve this question
You want to delete the word to the right of point? \ed kill-word – bsd Mar 28 '12 at 11:04
@bdowning nope, that doesn't quite use the same separator, kill-word is more granular. – Giuseppe Rota Mar 28 '12 at 12:44
up vote 2 down vote accepted

In brief, add the following lines to ~/.inputrc:

"\ew": kill-region
"\ea": '\e \C-] \ew'

where w and a characters could be changed to your will.

How does it work

Let's assign a key sequence to the kill-region readline command, for example Alt-w

"\ew": kill-region

then let's assign the following macro to another sequence, say Alt-a:

"\ea": '\e \C-] \ew'

that performs the following actions:


set the mark where the cursor is


search for a space and move the cursor there


kill the region between mark and cursor

share|improve this answer
I think you want character-search-backward, i.e. change \C-] to \e\C-]. – Mikel Mar 28 '12 at 15:51
@Mikel: no, I understand that with "backward" the OP means "in the reverse direction with respect to \C-w", and given that \C-w kill from the cursor to the previous space on the left, I built an analogous function to kill from the cursor to the next space on the right. – enzotib Mar 28 '12 at 15:58
yep @enzotib is right. Poor choice of words on my part. I'll try enzotib's solution and let you guys know. – Giuseppe Rota Mar 28 '12 at 16:05
Ah. OP wants kill-word, but using space as delimiter. :-) – Mikel Mar 28 '12 at 16:12
yeah, it works but has an issue with EOL, in that since it searches for a space it cannot find the end of line. But I guess there's no way around it, right? – Giuseppe Rota Mar 28 '12 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.