Whenever I press the escape key (ESC), bash ignores the next character that I type. Is that normal? It is very annoying, because I have a habit of pressing escape redundantly from using vim, where I use it to return from insert mode to normal mode.

Why does bash behave this way and how can I turn it off?

  • How quickly after the Escape key do you press the next key? – roaima Mar 2 at 16:41
  • It doesn't matter. It is literally that any next key is ignored, no matter the timing. – stimulate Mar 2 at 16:46

That is the normal/expected behaviour for an ANSI terminal.

When you type Esc the terminal starts processing an eventual ANSI escape sequence (if you went on typing [ and then A the cursor would go up).

So, after Esc the terminal waits for the next character in the sequence, if it does not belong to a know sequence then it stops processing, but both Esc and the next character you typed will be lost (they were part of an illegal sequence, and so the are dropped).

How to stop it? One thing you could do is change the inter character timeout for the terminal by calling for example timeout() from a program. See this:

While interpreting an input escape sequence, wgetch sets a timer while waiting for the next character. If notimeout(win, TRUE) is called, then wgetch does not set a timer. The purpose of the timeout is to differentiate between sequences received from a function key and those typed by a user.

  • Thanks! This explains it. I am using fish now. – stimulate Mar 2 at 18:33
  • bash doesn't use that call (and this is probably a duplicate, once you locate the correct information). – Thomas Dickey Mar 2 at 21:53

Check your bashrc file and look for a line set -o vi and change to set -o emacs if there is still issues and your using a terminal emulator like alacrity that has its own built in vim mode you may have to change the emulators config also.

EDIT: This is the most common way it is set but if you have an inputrc file can also be used to set vi mode if you have an inputrc file the command there would be set editing-mode vi if that file and line exist just comment out or remove the line.

  • Thanks, but neither .bashrc, .bash_profile, or .profile have this line. Running set -o emacs directly doesn't change it either. – stimulate Mar 2 at 16:50
  • What terminal emulator are you using? – Jason Croyle Mar 2 at 16:50
  • Alacritty github.com/alacritty/alacritty – stimulate Mar 2 at 16:51
  • Also check if you have an inputrc file added to my original answer. – Jason Croyle Mar 2 at 16:51
  • 1
    Alacrity has a built in vi mode that is what is causing this not bash. – Jason Croyle Mar 2 at 16:52

Pressing escape followed by another key is (in many terminal emulators) handled as an alternatave means by which to send the Alt+Key keystroke. For example Esc,A is the same as Alt+A. As such, it is not unusual for the first keystroke after pressing escape to be "lost" as it is in fact not being lost, but not sent in the manner which you might be expecting it to be.

  • Fish shell doesn't show this behavior... – stimulate Mar 2 at 17:24
  • 1
    This question is tagged Bash, not Fish. – DopeGhoti Mar 2 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.