Skip to main content

Linux: Vim Freezing

I had a problem with Vim freezing, and I finally figured out why. If you log into a Linux machine with X11 forwarding turned on, but without an X server, vim hangs when you try to start it. So do various other commands.

I recently switched from an Ubuntu laptop to a MacBook Pro running OS X. In my .ssh/config, I had:
Host my-server-name

ForwardX11 yes
When I sshed in from my Linux box, things were fine. However, when I sshed in from my Mac, things were broken. There are three workarounds:
  1. Don't enabled X11 forwarding. X11 forwarding is enabled for ssh by either the -Y or -X flags or by the ForwardX11 configuration variable.
  2. If you do enable X11 forwarding, make sure you start an X11 server first and then log in with a fresh xterm or terminal window so that the DISPLAY environmental variable is properly set.
  3. Pass -X to vim so that it doesn't try to connect to the X server. Vim will not be able to alter the window title or the clipboard. It was surprising to me that vim will try to connect to the X server even if you're not using gvim. This approach won't fix other applications that may rely on X in unknown ways.