1

I recently found that when running Vim in GNU Screen, I have to press Escape twice to get out of insert mode.

Beyond just googling or asking in forums, I would like to see the code behind Vim executing so I can try to see what is going on myself.

How could I get a print out of what happened in Vim when I pressed the Escape key the first time? Maybe it would show that it received the key press and what command it ended up corresponding to.

Julius Hamilton
  • 269
  • 1
  • 9
  • Is anything displayed if you hit ctrl-v before esc? – B Layer Sep 12 '21 at 11:25
  • If I press ctrl-v I see ^v in the bottom right of the screen. Then after pressing Escape twice like normal the characters ^[ have been written into the text file where the cursor was. – Julius Hamilton Sep 12 '21 at 16:14
  • Wait, in Insert mode you hit ctrl-v then esc and see ^[...okay that's, normal. But then you only have to hit esc one more time to leave Insert mode? Because if your bug was present in this scenario you'd have to press it twice (for a total of three escs). Weird. – B Layer Sep 12 '21 at 16:25
  • Or are you still in Insert mode after the second esc? – B Layer Sep 12 '21 at 16:32
  • No, after two escapes, I leave insert mode. But someone linked me to some posts on a different question of mine. It seems it's a known bug with a known solution. Screen creates a delay on the Escape key for some reason. – Julius Hamilton Sep 12 '21 at 18:02
  • I have an alternative solution for you: switch to tmux. ;) – B Layer Sep 12 '21 at 20:06
  • Why do you prefer tmux? – Julius Hamilton Sep 12 '21 at 20:57
  • I've barely used screen so I'm not going to disparage it but tmux is supposedly more user-friendly and "modern". Definitely has better copy/paste functionality (paste buffers). You could check out something like https://superuser.com/questions/236158/tmux-vs-screen ... but take everything with a grain of salt since people, obviously, let their personal biases get the better of them sometimes. FWIW, I like tmux a lot and use it any time I'm using a terminal (emulator). – B Layer Sep 12 '21 at 21:24
  • In addition tmux usually correctly handles things like this escaping, though you might have to fiddle with some settings for timings – D. Ben Knoble Sep 12 '21 at 22:34
  • Just to add my 2 cents on screen/tmux: On a workstation machine tmux is clearly superior to work as a terminal multiplexer/session saver/etc but if you work with remote server most of the time only screen is available and if you need to run a command which takes a long time to execute screen is the right tool because it's almost everywhere (I think it's a posix tool) while it's unlikely that you'll find tmux on your server. So depending on the context "switch to tmux" might not be the best solution :) – statox Sep 13 '21 at 14:45
  • If you want to get into the nitty-gritty of things you can also use strace for example: touch /tmp/sv; tail -f /tmp/sv; followed by something like strace -ttt -e 'trace=open,read,write' -o /tmp/vs vim - you'll get the core sequences written to terminal. – Moba Jul 02 '22 at 14:08
  • regarding the original problem (the need to press escape twice): i fixed it by clearing the mouse variable: set mouse= (of course, i don't use a mouse in vim). – aleksandr barakin Jun 21 '23 at 12:21

1 Answers1

1

For running and debugging vim, see :help terminal-debug. More likely, though, screen is eating the first escape for some reason, so vim never sees it (or, screen is holding the escape, waiting to determine if an escape sequence is coming—you can test for this by waiting for a few seconds after a single escape press. If this is the issue, you need to configure screen's timeout.)

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65