7

I use bash in Windows, both in Cygwin and in Git Bash (part of Git for Windows). In bash unlike in the Windows cmd.exe Esc does not clear the line, only Ctrl + U. How can I make clear the line also?

Thanks!

2
  • You may find that the console will interfere with any attempt to resolve this. Jun 16, 2011 at 16:38
  • Try this. If it works, I'll post it as an answer.
    – evan.bovie
    Jun 16, 2011 at 16:58

1 Answer 1

14

I don't have a Cygwin or Git for Windows install handy to test this, but here's the Unix answer:

Create a file in your (cygwin) home directory named ".inputrc", and add this line to it:

Escape: unix-line-discard

On my favorite Unix variant, Control-u is mapped to unix-line-discard, which deletes everything before the cursor. If you want it to delete the whole input line, including anything that may be to the right of the cursor, use "kill-whole-line" instead of "unix-line-discard".

Note that your bash line editing mode might eat the Escape. Bash on my system defaults to vi-style line editing mode (set -o vi), and as you may know, vi is all about the Escape key, so when I try this I have to hit Escape twice because the first one gets eaten by the vi-style editing mode. I'm not an emacs guy so I don't know what the emacs-style line editing mode will do with an Escape keypress.

Note also that the .inputrc file is read when the shell starts, so after editing your ~/.inputrc, close your shell and open a new one to see if the changes worked.

5
  • Awesome! Been trying to do this for a while on Mac OS X too. The point about the line editing mode helped tremendously because in the various attempts to get this to work I probably skipped right over a working solution because I was only hitting escape once.
    – Josh
    Aug 12, 2012 at 22:11
  • I'm using git bash on Windows (MINGW64). Using .inputrc with Escape: unix-line-discard works - but it isn't instant - when I press the Esc key it takes about 500ms for the line to be cleared. Any idea?
    – Dai
    Jun 19, 2021 at 22:20
  • This is useful, but for me Escape: kill-whole-line works even better. See unix.stackexchange.com/a/30991 . Apr 5, 2023 at 14:58
  • 1
    @GarretWilson My answer already suggested that option for those who'd prefer it.
    – Spiff
    Apr 5, 2023 at 15:01
  • Oops, sorry I didn't see it @Spiff , because you used quotes ("kill-whole-line") instead of code (kill-whole-line). I had so many tabs open and was quickly scanning so many posts at the same time that my eyes didn't catch it. 😅 Apr 5, 2023 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .