20

Delete one word backward:

Ctrl + w

Delete one word forward:

?

Can anyone answer the above or do I need to add a command to stty as I can see by running the following command:

stty -a

that the action associated with Ctrl + w is defined there.

GAD3R
  • 66,769
MarkMark
  • 583

1 Answers1

35

The key sequence is M-d in bash, i.e. Alt+D or Esc+D.

This invokes the kill-word Readline function:

kill-word (M-d)

Kill from point to the end of the current word, or if between words, to the end of the next word. Word boundaries are the same as those used by forward-word.

The above is taken from the bash manual.

Kusalananda
  • 333,661
  • It's M-d like in emacs when in emacs mode and dw or dW like in vi when in vi mode. – Stéphane Chazelas Aug 09 '18 at 12:44
  • @Kusalananda Thanks very much. I can confirm alt+d will delete the next word in front of the cursor in bash. – MarkMark Aug 09 '18 at 12:47
  • 1
    @Stéphane Chazelas Thank you, to be honest i'm very new to Linux/Vim I am having trouble understanding this notation M-d, I would interpret that as Shift+m+d but obviously this is incorrect. I can't see how M-d means the same as alt+d? – MarkMark Aug 09 '18 at 12:49
  • 5
    The M means "Meta". In general, X-y means "press the X key with y" as in "C-c is Control with c". Meta is generally the Escape or Alt keys. – Kusalananda Aug 09 '18 at 12:52
  • 1
    @Kusalananda Thanks very much for both your answers, very well written in a concise and informative manner, extremely helpful. Thank you – MarkMark Aug 09 '18 at 13:02
  • btw this is defined in readline not bash – ychaouche Aug 25 '22 at 11:29