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.

  • 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

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

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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