To expand on Ignacio Vazquez-Abrams's answer a little, you can get (almost) Windows-like behaviour from the Esc key in bash by binding the kill-whole-line
to Esc with the following command
bind '"\e":kill-whole-line'
If you add the line to your ~/.inputrc
file, the binding will persist between sessions.
Note, however, that this is very non-standard, as bash actually uses the Esc key as another modifying key (like a non-persistent Alt or Ctrl). If you look at the list of existing key bindings (with bind -P
), you will likely see several commands bound to key-combinations that start with "\e" (e.g.
"\eb": backward-word
which sets up the combination Esc + B to move the cursor back to the most recent word-beginning – rather like Ctrl + ←, except that you have to keep releasing Esc (as well as B, of course) if you want to do it more than once in a row).
And that explains why I said that the behaviour you get is almost Windows-like: when you press Esc, bash checks to see if you're using it in combination with another key; so, if you bind it to kill-whole-line
, there's a bit of a delay between pressing (or rather, releasing) Esc and bash clearing the line for you.
However, if you don't care about any of that, and would rather live with the delay than retrain yourself to a different keystroke, it can be done.
(Note: much of the information here I got as a result of reading – and following the links in – this answer.)