Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My terminal setup is gnome-terminal + tmux + zsh with vi bindings.

In applications like vim or even in the zsh's command line vi editing mode, I need to frequently hit the ESC key but there is a small delay before the effects of this key take place. See GNU Screen makes Vim ESC key slow

After some experimentation, I found that hitting ESC key and immediately another key (say b) has the same effect as hitting Alt+b. I don't know why this is the case (probably for legacy reasons when there was no Alt? I don't know). Either way, I have two Alt keys and I don't want this behaviour with my ESC key. I have tried with C+[ and its the same problem with that too.

I'm not sure who is responsible for this, gnome-terminal or tmux or my OS itself (Ubuntu Natty). Any ideas on how to address this would be great.

Update: I checked without tmux on a different terminal (LXTerminal) and the delay is present there too.

share|improve this question

3 Answers 3

up vote 20 down vote accepted

Here's an actual fix. Add the following to .tmux.conf:

set -s escape-time 0
share|improve this answer
    
Spot on! Thank you very much Vincent. –  Shrikant Sharat Nov 29 '11 at 14:41
    
Brilliant, thanks! Had a delay leaving insert mode in vim and hadn't really thought it might have been tmux interfering. This did the trick –  actionshrimp May 26 '13 at 12:09

The delay is caused by the input routines that may have to decide wether a function key was pressed or not. For this the input routine starts a timer whenever it reads in an ESC character. Characters that are read from the input before the timer runs out (let's say a tenth of a second) are then interpreted as ESC sequence of a function key and this ESC-sequence will be compared with known strings of ESC secuences from the terminfo or the termcap data base (depends on which low level routines are used).

Of cource this is annoying for applications where ESC is used on its own, but I don't know of any workaround for this.

Regarding your question with the behaviour of ESC a = Meta a:

Meta keys were not available with all keyboards. As a workaround it was often allowed to use the ESC key to be pressed before the other key.

share|improve this answer
    
Thank you for the explanation ktf. The delay is not present in gvim, only in the terminal (I checked without tmux and the delay is still there). –  Shrikant Sharat Oct 23 '11 at 17:51
    
gvim does not suffer from this problem, because it gets the information which key was pressed from the X11 server (so it does not have to parse ESC sequences). –  ktf Oct 24 '11 at 8:19
    
Ok, so I need to make my gnome-terminal behave the same way then. –  Shrikant Sharat Oct 24 '11 at 8:42
    
the gnome-terminal is not the problem - the problem described affects only programs running on a terminal (or in a Terminal emulation) and has to parse function keys. You will experience the same behaviour, if you try xterm or KDE-Terminal for instance. –  ktf Oct 24 '11 at 9:57
2  
"Meta keys were not available with all keyboards. As a workaround it was often allowed to use the ESC key to be pressed before the other key." Perhaps even predating that, ttys often only had seven-bit data interfaces; there was no eighth "meta bit", so you had to send an ESC for Meta. And nowadays UTF-8 is widespread, so even with eight-bit connections you can't use the high bit for Meta. –  Chris Page Oct 24 '11 at 18:57

While this may not directly fix your issue, I have found that I can use <Ctrl> c to exit out of insert mode. This can also be used to exit tmux's screen scrolling (which can be invoked using <leader> PgUP)

share|improve this answer
1  
I wouldn't recommend using <C-c> to exit out of insert mode in regular use since it doesn't run the InsertLeave autocommand which some plugins might be watching for. See :h i_CTRL-C. –  Shrikant Sharat Jan 27 '13 at 8:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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