Peter's Blog

Redefining the Impossible

Using VIM to edit files via ssh


If you have a file on an ssh enabled server that you want to edit with VIM and you don't want to mess around with ftp you can use VIM's ftp support.

However, I find the support for scp to be more useful. Having installed Cygwin and open ssh I have also acquired the scp command. VIM knows about this and can use it to edit files.

Suppose I want to edit the file 'interesting.txt' on the server 'stuff.com'? I use the VIM command:

:e scp://peter@stuff.com/interesting.txt

and start editing. When I am finished I just write the file normally:

:w

Because I have already created an ssh key on stuff.com (as shown here) I am not hastled for passwords.

Very nice for quick .css tweeks, editing drupal modules etc. I can edit the file locally in a windows GUI and upload it to nice secure linux server. Best of both worlds.

Downsides?

  1. Win32 vim leaves a silly dos box with a 'Hit any key to close this window...' message on it when reading the file.
  2. Have to know the exact path to the file.

Jachym Says:

over 3 years ago

What about gvim under Linux? I never got it work :-/ Vim from xterm work's fine.

Peter Says:

over 3 years ago

I don't use X Windows, I use MS Windows for GUI stuff. I have used gvim under X in the past with no problems. You don't describe what problems you had, what linux distribution and version you use, what version of vim you are trying to use and how you got hold of it (e.g. binary rpm or build from source). I have found vim/gvim easy to build, both in Gentoo linux and under windows. You have to build it yourself to get python support. Building it is also the best way to get a version that is compatible with the rest of your system. Peter

Jeremy Says:

over 3 years ago

Good tip, though I had to put // before the file or I'd get a path not found error.

Peter Says:

over 3 years ago

I tried it again and it works as I described.

Peter

Anonymous Says:

over 2 years ago

You can also "edit" a directory to browst through it's contents:

:e scp://peter@stuff.com//etc

You can also specify a path at Vim startup:

gvim scp://peter@stuff.com//file/to/edit

Oliver Charles Says:

about 1 year ago

A bit late on the train here, but did you but VIm into non-compatible mode? I had to do that before I could :e scp://whatever. Just do ":set nocompatible" and you're good to go :)

daniel Says:

5 months ago

I know its bit late but i did read it this site and thought this maybe helpful for the next.

if you connected with vim or gvim thru scp://user@hostname/project_dir you can enter ':E' and you get a nice basic explorer view of the directory and can browse it thru.

Comments are Closed