How to use GVIM to edit a remote file?

Viewed 24568

I use GVIM on Ubuntu 9.10. I'm looking for the right way to configure GVIM to be able to edit remote files (HTML, PHP, CSS) by for exemple ftp.

  • When i use :e scp://username@remotehost/./path/to/file i get: error detected while processing BufEnter Auto commands for "*":E472: Command failed.
  • When i open a file on remote via Dolphin or Nautilus, i cannot use other files with NERDTree.
  • Finally when i edit on remote a file via Dolphin the rights are changing to access interdit.

So how to use GVIM to edit remote files like on my localhost?

10 Answers

There is one way and that is using the remote host's copy, using SSH to forward the X11 client to you, like so:

user@local:~/$ ssh -X user@host
...
user@host:~/$ gvim file

The latter command should open gvim on your desktop. Of course, this relies on the remote host having X11 / gnome / gvim installed in the first place, which might not be the solution you're looking for / an option in your case.

Note: X11 forwarding can be a security risk.

In order for netrw to work seamlessly, I believe you need to not be in compatibility mode.

Try

:set nocompatible

then

:edit scp://host/path/to/file

EDIT: Key authentication is not necessary for opening files over ssh. Vim will prompt for password.

It would be useful to note if netrw.vim was loaded by vim when it started.

:echo exists("g:loaded_netrwPlugin")

For opening files over ssh, you need your local machine's public key in the server's authorized keys. Following help section in vim documentation explains it pretty well.

:help netrw-ssh-hack

Quick way to export public key would be by using ssh-copy-id (if available).

ssh-copy-id user@host

And have a look at netrw documentation for network file editing over other protocols.

:help netrw

HTH.

According to the docs BufEnter is processed after the file has been read and the buffer created, so my guess is that netrw successfully read the file but you have a plugin that assumes the file is on the local filesystem and is trying to access it, e.g. to run ctags.

Try disabling all your plugin scripts except the default Vim ones, and then editing the file.

Also, try editing a directory to see if netrw can read that - you need to put the / on the end so that netrw knows it is a dir.

I didn't think you were going to be able to directly edit a remote file using GVIM running locally. However, as others have pointed out, this is defintiely possible. This looks very interesting; I will check this out. I will leave the rest of my post up here, in case it is useful to anyone else, as an alternative method. This method will work even if you don't have SSH access to the file (ie, you only have FTP, or S3, or whatever).

You may get that effect, though, by tying GVIM into a graphical file transfer application. For example, on OS X, I use CyberDuck to transfer files (FTP, SFTP, etc). Then, I have it configured to use GVIM as my editor, so I can just double-click on a file in the remote listing, and CyberDuck will download a copy of that remote file, and open it in GVIM. When I save it in GVIM, CyberDuck uploads the file back to the remote host.

I'm sure that this functionality is not unique to CyberDuck, and is probably present in most nicer file transfer utilities.

Related