Reduce the delay after ESC in ncurses
By chys on September 26th, 2009In ncurses-based programs, the default delay after the ESC key is way too long. (Such a delay is necessary to differentiate the ESC key from function keys.)
There seems to be no such delay in VIM. But with strace, we can find that VIM actually delays, but for only 25 milliseconds, shorter than 100ms – the minimal time interval that human can perceive:
read(0, "\33"..., 4096) = 1
select(6, [0 3 5], NULL, [0 3], {0, 0}) = 0 (Timeout)
gettimeofday({1253979790, 537775}, NULL) = 0
select(6, [0 3 5], NULL, [0 3], {0, 25000}) = 0 (Timeout)
If 25ms works reliably for VIM, so should it do for other programs. There seems to be no functions setting this interval in ncurses, but we can directly modify the global variable ESCDELAY. Ncurses also accepts the environment variable also named ESCDELAY, so we may also want to honor the user’s choice:
if (getenv ("ESCDELAY") == NULL)
ESCDELAY = 25;
Not confident in its portability, I detect this undocumented (it seems) feature with cmake in tiary (my project).
Update (Feb. 22, 2010): It’s preferable to use the function set_escdelay.
No related posts.

THANK you. It seems this is the only page on the entire internet with a solution to this problem.
This trick also works with the curses python module, just execute
export ESCDEALY=25
before running the python script. Modifying os.environ from the python script itself would also work, I guess.
So glad I found this page, couldn’t understand why I was getting this behavior.
Thanks!
[...] you’re academically interested, go to http://en.chys.info/2009/09/esdelay-ncurses; for more [...]