I used Putty to remote to Linux machine, and when I use vim to open a file it always delays and display message PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused. How can I fix it?

  • As vim shouldn't require X server for anything, could it be that vim is actually an shell alias for some GUI enabled version of it? Please post the output of alias vim. You don't mention which distro is being used, but it also could be that the vim found in the path is a symbolic link to something else than the text-mode version, so please also post the output of ls -la $(which vim) – zagrimsan Sep 23 '15 at 10:17
  • 1
    @zagrimsan I'm sorry to have to contradict you, but Vim absolutely requires X server access in many circumstances. Most notably for the GUI, but even the console Vim can try to contact the X server for a number of things, such as handling X11 selection events, clientserver, etc. – Heptite Sep 23 '15 at 21:01
  • @zagrimsan: This is result of your command: lrwxrwxrwx 1 root root 21 Nov 1 2013 /usr/bin/vim -> /etc/alternatives/vim what's problem with vim version I use? – Khong Son Sep 24 '15 at 1:14
  • @Heptite I personally don't use vim so I thought it would be textmode-only and only the other derivatives like gvim, vim-gnome, vim-gtk etc need X. If that is the case, OP needs to set up X11 Forwarding with Putty with e.g. XMing or otherwise or configure vim so that it doesn't require X in which I'm sure you Heptite could help :) – zagrimsan Sep 24 '15 at 2:56

You can either set up X forwarding, or give Vim an option not to try to contact the X server (note that it's an uppercase X):

vim -X

However, usually Vim does not try to connect to an X server unless it believes one is available; somehow your DISPLAY environmental variable is getting set somewhere.

  • I check DISPLAY variable, it is localhost:20.0. Is it correct? – Khong Son Sep 24 '15 at 5:37
  • It could be set in Putty configuration under Connection->SSH->X11 (perhaps "Use X11 Forwarding" is checked). – zagrimsan Sep 24 '15 at 5:45
  • @KhongSon : There's no way for us to know. I'm guessing that putty is trying, and failing to set up X forwarding. – Heptite Sep 24 '15 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.