Bash/zsh: Undo erase backwards (ctrl+w)

In Bash and Zsh ctrl+w erases backwards from where the cursor is. Is it also possible to undo what I had erased?

Thanks!


Solution 1:

Undo it's like this : ctrl + _

Solution 2:

It's ctrl + /

ctrl + y (or _) pastes what's in the buffer. The buffer get's filled by things like ctrl + w. You can paste it in different places multiple times, so it's not an "undo". ctrl + / is undo, and you can execute it multiple times to undo every previous action.

Solution 3:

This below shortcut key does the job of undo the erased string by ctrl+w,

ctrl+y

Solution 4:

ctrl+w does not delete but cuts everything in front of the cursor. Therfore you can yank/paste it with ctrl-y assuming you did not move the cursor. ctrl+_ actually restores the line itself.