12 April 2011

Removing the delay in switching Vim modes in tmux.

I've had a real annoyance with console Vim for a while now, which I just haven't been able to figure out. Today I did.

When you're in insert mode, you hit escape to leave and go back to normal mode. However, due to the way that terminals often map escape characters, when you hit escape, the terminal can wait around for a second, just in case you wanted to press another key and complete the escape mapping. But, this means that every time I wanted to leave insert mode, I was having to wait for around a second. If I didn't, then Vim instead inserted some sort of symbol like


instead of doing

Esc d d

to leave insert mode and delete the current line.

I tried a few things, including reducing Vim's timeoutlen, which appeared to have no effect.

This really interrupted my flow, and led me to use graphical Vim much more than console Vim, since the problem didn't happen there. But today I found that it wasn't happening outside of tmux at all. So, must be tmux's problem.

The solution lies in telling tmux not to wait. I stuck the following in my .tmux file:

set -sg escape-time 0

And now hitting escape exits insert mode instantly, even in tmux!

Categories: All articles Vim tmux