Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #542 - Edit remote files locally via SCP/RCP/FTP

Created: August 27, 2003 11:10 Complexity: intermediate Author: Roberto Version: 6.0 Karma: 117/36 Imported from: Tip#542

I'm frequently editing files remotely, but if the network traffic is tight, then a normal VIM session turns into a tortuous event. The solution to that was right under my nose: VIM's Network-Oriented File Transfers (:help netrw).


Instead of editing the file remotely, it can be transfered from the host server, to a local copy, edited and then sent back when done. I know that you can do this manually, but it's a hassle, besides, if it can be done automatically, why not go for that? :)


Assuming you have the following installed and properly configured:


1. VIM

2. netrw.vim (afaik comes in all recent vim installs)

3. scp, rcp, ftp or ftp+


Then to use, all you need to go is specify the protocol, user, host and path to the file you want to edit:


vim scp://konimi@vim.org//var/www/html/rtc_functions.php

gvim scp://konimi@vim.org//var/www/html/tips/add_tip.php


Every time you write the file (:w etc.) the file will get copied over to the source and you will be brought back to your session for further editing.


If you already have an open session, then just issue the following commands:


To read/load up a file: :Nread scp://konimi@vim.org//var/www/html/rtc_functions.php

To write the file back: :Nwrite scp://konimi@vim.org//var/www/html/rtc_functions.php


That's it! You'll be editing at local speed.

Comments

Soon after I had posted this item, I stumbled into VimTip337 from Matthew Weier O'Phinney. Don't want to post a similar Tip so as soon as I figure out how to delete this Tip, I will.


rob--AT--machorro.net , August 27, 2003 11:18


There's no way to delete a tip, sorry to say.

<netrw.vim> also supports rsync, fetch, dav, and rcp.


cec--AT--NdjOinnSi.gPsfAc.nMasa.gov , August 27, 2003 12:53


I tried this but it keeps asking me for my password any time I save the file and at the end when I close it

semovrs--AT--concord.edu , February 9, 2005 17:52


To avoid having to enter a password every time, you can use a pair of keys generated with ssh-keygen or puttygen. From what I understand, ssh-agent is also useful for this, but I've never tried it myself.

xyborx {at] xyborx.dk , March 15, 2005 5:36


The more recent netrw (see [/scripts/script.php?script_id=1075 vimscript#1075]) has, under help for netrw-list-hack, an url to http://hacks.oreilly.com/pub/h/66 which helps one set up no-password ssh/scp etc.

NdrOchip--AT--ScampbellPfamily.AbizM - NOSPAM , March 25, 2005 11:56


Is there anyway that I can use ctags with this plugin.

mubeenj--AT--gmail.com , July 7, 2006 2:53


Advertisement