Search code examples
vimsshcygwingnu-screen

GNU Screen and vim - connect over ssh from different hosts, certain buttons (e.g. <ENTER>, ^[ ) don't work correctly


Both clients are Windows 7 using cygwin to connect to an Ubuntu machine.

From ClientA I connect via ssh to the Ubuntu machine, start a screen session, and open vim. Then I type :E to open the netrw directory listing. Pressing <ENTER> on the directories navigates and all is good in the world. I disconnect from the Screen session.

From ClientB, I connect via ssh and resume the screen session, vim is already open. I press <ENTER> on a directory and instead of opening the directory, it moves the cursor down one line. It's as if I've pressed j or <DOWN>. Pressing ^M does the same thing. None of the directories can be navigated to. Also, if I have a file open and I'm in insert mode, I have to press escape twice to return to normal mode.

Still on CLientB, I quit vim :q (yes, enter works when typing : commands). I then reopen vim and use netrw again :E. Now everything works the way it's supposed to: pressing <ENTER> navigates directories, and when I'm editing files I only need to press ^[ or escape once for it to work.

If I disconnect from ClientB and connect again with ClientA, then vim doesn't work properly again until I exit vim and start it again.

I have tried typing :set to see all of the set options, but there is no difference between these settings when vim is started while connected from ClientA or ClientB.

What is going on and how can I fix it?

Thanks!


Solution

  • In cygwin I needed to go to Options > Terminal and make sure both clients were set to the same type (e.g. xterm-256color).

    Different terminal types use different escape sequences for the keys and the mismatch was causing the problem.