How to delete a whole word on the right in Linux Bash Shell command line

Viewed 17832

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.

2 Answers

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

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.

Related