Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressing ESC need one second to switch mode in tmux or screen #2035

Closed
bigeagle opened this issue Feb 21, 2015 · 31 comments
Closed

Pressing ESC need one second to switch mode in tmux or screen #2035

bigeagle opened this issue Feb 21, 2015 · 31 comments
Labels
closed:question issues that are closed as usage questions tui

Comments

@bigeagle
Copy link

Hi,
With version c48f835, when nvim runs inside tmux or screen, pressing ESC needs more than one second to switch mode. If you type ESC and press a key quickly, there appears some latin-1 characters in ther terminal. For example, when in insert mode, and i wanna switch to normal mode and switch back, so i type esc i, then an é was inserted.

Cheers,
Justin

@bigeagle
Copy link
Author

By setting set -sg escape-time 0 in .tmux.conf can work around this problem.

@tarruda
Copy link
Member

tarruda commented Feb 21, 2015

@bigeagle what escape-time value were you using before?

@bigeagle
Copy link
Author

It's the default value, I'm not sure but I believe it's near 1 second.

@bigeagle
Copy link
Author

The default value is 500 milliseconds

@tarruda
Copy link
Member

tarruda commented Feb 21, 2015

Nvim now uses libtermkey for parsing keys, that means alt key combinations are detected by default. So, if you have a 500 ms escape time and press esc+i, tmux will immediately send ^[i which is interpreted by libtermkey as alt+i.

Vim does not detect alt combinations in terminals by default(source), so when it receives ^[i which doesn't match any terminfo key sequence, it will parse as the keys esc and i separately.

If you want to avoid this kind of problem, use a low escape-time value(I dont recommend 0), personally I use 10 milliseconds.

@bigeagle
Copy link
Author

Older versions without libtermkey works, there is a delay of mode switching but key sequence is still right (esc i would not be alt-i). Maybe we need a patch for libtermkey?

Setting escape-time is fine but at those who use default conf would be confused.

Cheers,

@tarruda
Copy link
Member

tarruda commented Feb 21, 2015

Maybe we need a patch for libtermkey?

libtermkey is working correctly, esc+i is just how most terminals represent alt + i. The difference is that alt is now recognized automatically.(The old method doesn't work anymore, you cant use set <a-i> ^[i for example).

It would be good if the library had the option to disable alt recognition though(cc @leonerd)

@mxaddict
Copy link

I had a similar issue with this and I had a really hard time finding this issue that explained what was the cause and the FIX, I would suggest we add this as a known issue somewhere easy to find? maybe readme? or wiki?

NOT for me (I already fixed it of-course), but I think it would help future tmux + vim users that switch to NVIM 😈

@justinmk
Copy link
Member

@mxaddict Added to list of sanity checks #1202

@mxaddict
Copy link

Nice 👍

@justincampbell
Copy link

I ran into this, and just assumed it was a bug in Neovim since it started happening right after upgrading. I had switched backed to vanilla Vim, thinking I would try Neovim again after this is fixed.

Then, @iamjarvo pointed me to this issue. I'm not sure how I would have found this otherwise, including buried in a README or elsewhere. Maybe a post-install message?

justincampbell added a commit to justincampbell/.dotfiles that referenced this issue Mar 3, 2015
Fixes compat with Neovim: neovim/neovim#2035
@felipecrv
Copy link
Contributor

I ran into this. I press ESC more than I should (paranoid), so everything seemed broken to me.

bgourlie added a commit to bgourlie/dotfiles that referenced this issue Jul 3, 2015
@petRUShka
Copy link

Confirm problem with latest git-version of neovim

@fwalch
Copy link
Member

fwalch commented Jul 8, 2015

FWIW, this is listed on the FAQ page.

@goerz
Copy link

goerz commented Jul 19, 2015

Are there any potential drawbacks of the escape-time 0 tmux setting?

@justinmk justinmk added closed:question issues that are closed as usage questions tui labels Aug 19, 2015
@justinmk
Copy link
Member

This is covered by #1202. Other than that, this is not actionable unless we change our input logic. That's a larger discussion that is covered by other issues.

jayroh added a commit to jayroh/dotfiles.new that referenced this issue Sep 21, 2016
Setting tmux to ignore the escape key fixes these issues. See:

neovim/neovim#2035

For more info. Specifically:

neovim/neovim#2035 (comment)
@justinmk
Copy link
Member

justinmk commented Oct 16, 2016

The relevant tmux setting is now checked by :CheckHealth.

And the FAQ. https://github.com/neovim/neovim/wiki/FAQ#esc-in-tmux-or-gnu-screen-is-delayed

@fiesh
Copy link

fiesh commented Dec 28, 2016

I think setting the escape-time is a workaround, but a buggy one at best. It can (and does) happen that both the escape key and the following key are sent in the same IP packet.

Also, I sometimes have the escape-not-recognized issue when working locally, without tmux. Is this related to this or an entirely different issue?

Thanks for the great work!

@leonerd
Copy link
Contributor

leonerd commented Dec 28, 2016

It can (and does) happen that both the escape key and the following key are sent in the same IP packet.

It's exactly that sort of timing-related issue that I hope to fix by doing terminal keyboard stuff better. Currently we don't quite have the architecture in neovim to support that, but it's definitely on my list of things to get working better. It can be done without timing information, provided the application and the terminal can both support it.

@justinmk
Copy link
Member

justinmk commented Mar 8, 2017

For anyone finding this issue in the future, see the FAQ:

https://github.com/neovim/neovim/wiki/FAQ#esc-in-tmux-or-gnu-screen-is-delayed

@fiesh
Copy link

fiesh commented Mar 8, 2017

Is there a ticket that remains open until the problem is actually fixed per what @leonerd said?

@justinmk
Copy link
Member

justinmk commented Mar 8, 2017

No. That requires advanced terminal features.

@fiesh
Copy link

fiesh commented Mar 8, 2017

Sure, but this means the bug that even on local terminal sessions, escape is sometimes ignored, just remains?

@justinmk
Copy link
Member

justinmk commented Mar 8, 2017

I don't know what bug you're talking about. Every single time someone claims this it ends up being a misconfigured 'ttimeoutlen' or tmux escape-time.

I do plan to rework 'ttimeoutlen' so that users are less likely to run into issues.

@fiesh
Copy link

fiesh commented Mar 8, 2017

OK, thanks, I'll keep that in mind!

damireh added a commit to damireh/dotfiles that referenced this issue May 2, 2017
Pressing ESC in vim in tmux took more than a seconds and was annoying as
fuck

neovim/neovim#2035 (comment)
@mjkelly
Copy link

mjkelly commented Aug 26, 2017

@justinmk Is it worth mentioning in the FAQ that you can also use ^C to get out of insert mode? It's not a fix, but it seems to avoid the issue fairly well.

@justinmk
Copy link
Member

@mjkelly CTRL-C is different than ESC, e.g. it cancels mappings and autocmds. Why not set the tmux escape-time option as mentioned?

@mjkelly
Copy link

mjkelly commented Aug 27, 2017

@justinmk Ugh, I didn't realized it cancelled mappings and autocmds. Thanks for clarifying. (I thought it would be a nice way to avoid the tmux issue and the fact that the esc key is in different places on different keyboards.)

@arcseldon
Copy link

Great help, thanks.

@scoop206
Copy link

I'm running tmux 2.6 and the way to do this now appears to be

set-option -sg escape-time 0

@neovim neovim locked as resolved and limited conversation to collaborators May 11, 2018
@justinmk
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed:question issues that are closed as usage questions tui
Projects
None yet
Development

No branches or pull requests