51

How can I delete a whole word to the right in Linux Bash Shell command line?

Such as this:

  • Ctrl + U = Delete left of the cursor
  • Ctrl + K = Delete right of the cursor
  • Ctrl + W = Delete word on the left

I want to know a shortcut to delete a whole word on the right, no matter where the cursor is in the word. It is just like in Vim opt it is:

daw

And I want to the same result on the Bash command line.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Victor Lee
  • 2,467
  • 3
  • 19
  • 37

2 Answers2

81

Use Esc + D or Alt + D to delete the word on the right.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tshiono
  • 21,248
  • 2
  • 14
  • 22
  • 4
    This moves the word to the right of the cursor into a ring buffer. The last added element can be accessed via Ctrl+y. The possibly existing further elements in the ring buffer can then be called up via repeated Esc+y. – Cyrus Dec 29 '18 at 07:22
  • Only `Esc+D` works for me. Which is OK. But how do I change to or add `Alt+D`? – Multifix May 10 '22 at 08:28
  • For Mac users, it's Ctrl^ + D – notClickBait Dec 11 '22 at 03:18
5

You can try Ctrl + K to delete from the cursor to end of the line (all on the left side of the cursor), and Ctrl + U to delete from the cursor to the start of the line (all to the right side of the cursor).

Also, I find the nice blog post Bash Shortcuts For Maximum Productivity covering a handful of Bash shortcut, and you may want to give it a read.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131