I sometimes need to work on remote server which does not have x11 installed and thus I cannot use vim with its full features. I want to work on remote server with the gvim installed to my local machine. What is not convenient is that I need two hops to access my server through some middle machine. That means I can only access server like this: local -> middle -> server.

How could I do it please ?

===== Edit: Here is the specific case: I have to access my remote server via middle server, and I have no way to bypass the middle server.

I do not have a home directory at the middle server, so I cannot configure and use the middle server. It only plays the role of some entrance.

I do not mind whether I have to use gvim, I am considering gvim because it has built-in clipboard function which is better than the terminal vim. I can compile terminal vim from source, but I do not have x11 in both the remote server and the middle server.

The core problem is how could I copy contents from the remote vim?

  • 1
    Note that gVim is not Vim with its full features: you can have a terminal Vim with its full features. Now for your problem, maybe you could try to use a remote file system like SSHFS to mount the server on your local machine (I think it is possible to do it with a hop but I never tested it)
    – statox
    Commented May 6, 2019 at 8:48
  • I don't have any extensive experience with ssh, but I would say you're better off with terminal Vim which is more robust than its GUI counterpart anyway. But if you're really devoted then you could maybe look for something similar to what Emacs does with Tramp which is basically using scp etc. under the hood.
    – 3N4N
    Commented May 6, 2019 at 9:45
  • @klaus Thanks, the problem with terminal vim is that: I cannot copy the contents out if I open a file in the remote server, since the server has no x11 installed and there is a ssh hop between my local machine and the remote server. Do you have any suggestions about using the terminal version vim? Commented May 6, 2019 at 10:21
  • 1
    Use netrw to locally access files using scp/sftp. Configure ssh to work properly using the ProxyJump configuration setting Commented May 6, 2019 at 11:01
  • 1
    well if scp is disabled, can you use sftp? Commented May 6, 2019 at 16:21

1 Answer 1


In theory, it's fairly easy. I practice, there are a few gotcha's. Let's walk through this step by step, and I'll tell you what to look for. Once you validate that everything is correct, you ought to be able to do this lickity-split.
Note: I use Red Hat/CentOS. You may have to make slight variations in commands for your environment.

On "local" make sure xhost is set correctly. Easy way:
[me@local]$ xhost +

For convenience, check your DISPLAY variable:
[me@local]$ echo $DISPLAY You should see something like :0 or :0.1
(More later)
Next, use ssh with X-Display forwarding:
[me@local]$ ssh -X middle -l me
Alternately: ssh -X me@middle

Now, here it is important to ensure that your DISPLAY variable is set correctly. On some machines, the login files are configured to set your DISPLAY variable for you. This will break the X-Display forwarding!!
[me@middle]$ echo $DISPLAY The correct setting will look like this:
localhost:10 or even
The incorrect setting will look something like this: *starting_hostname*:0.0
If you have an incorrect setting, you cannot manually change the DISPLAY environment back. You must find where your login scripts on the "middle" host are changing it and leave it the default.

Third, ssh using X-Display forwarding into server:
[me@middle]$ ssh -X me@server
Check your DISPLAY variable again. The same caveat as above applies here. It must be localhost:[number]

At this point, check that your remote display is working correctly by starting any GUI program and validate that screen appears on the local box.

Once you are sure everything is configured, you can run these commands:
[me@local]$ xhost + [me@local]$ ssh -X me@middle [me@middle]$ ssh -X me@server [me@server]$ gvim my_filename

Additional info:
Port 6000 needs to be open between all of the boxes. That is the X-Display forwarding port.

The X-Display programs & libraries need to be installed on "server." (OS Dependent, can't help you here). IF you program (gVIM) calls the "draw a box api" and the "server" OS doesn't know what that is, it will never work.
(Really what happens is, "server" application says "Draw a box with these coordinates." The "server" X-window system says "OK. But, I don't have a monitor ... oh, wait, I'll just draw the box on the 'localhost' monitor."

"server" and "local" have to have compatible X-windowing systems. I've seen issues where Solaris or AIX talking to a CentOS box doesn't always work.

Unless you are using IP addresses in lieu of hostnames, each of your machines need to be able to resolve all 3 host names to an IP address. Usually, I just ensure that all 3 host/IP names in /etc/hosts. This sounds odd, but I have seen this be an issue. And, FWIW, add FQDN & Short Hostname to /etc/hosts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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