Vim Tips Wiki
m (Update link to netrw script - is the last comment and diff still valid (anyone who uses netrw?)?)
(changing category to File Handling, adding integration category)
Line 88: Line 88:
 
, July 16, 2003 13:19
 
, July 16, 2003 13:19
 
----
 
----
  +
<!-- parsed by vimtips.py in 0.532360 seconds-->
 
[[Category:Usage]]
+
[[Category:File Handling]]
  +
[[Category:Integration]]

Revision as of 15:23, 1 November 2007

Previous TipNext Tip

Tip: #480 - Editing files on an ftp server listening on a non-standard port

Created: May 29, 2003 8:18 Complexity: basic Author: George Harrison Version: 6.0 Karma: 19/12 Imported from: Tip#480

Vim will edit files on an FTP server with the command:

e ftp://ftp.server/path/to/file/filename

But if you are using a virtual FTP server as in Bricolage to edit templates, the FTP server is listening on a non-standard port (typically 2121, but it can be something different).

In that case, the command would be

e ftp://ftp.server\#2121/path/to/file/filename. 

Note the "\#". The standard syntax for specifying a port number is to append #2121 to the server name, where "2121" is the port to connect to. But Vim treats an unescaped "#2121" as an alternate file reference and fails with the message "No alternate file name to substitue for '#'". Escaping the "#" causes Vim to treat is an another character in the string, and the connection works.

Click :help :edit and then search for "count" to find the syntax for editing alternate files.

This works on Red Hat and on WindowsNT.

Comments

netrw.vim will accept a colon for ports with ftp, too:

ftp://[user--AT--]machine[[:#]port]/path/to/file

cec--AT--NgrOyphSon.gPsfAc.nMasa.gov , May 29, 2003 13:02


This script is great, but beware! It does not check to see if it really wrote your file! If, for example, you are using a source control system, and forget to check out the file before modifying it, you will lose your work. (Gee, I wonder how he knows that...) I sent a revised copy of the script to the author that checks status for the ftp case (since that's the only case I can use), but either he didn't get it, he's busy, he didn't like my changes, or he's working on making it work for other protocols...I hesitate to submit it without his blessing; it's the first vim script I've ever mucked with. It also checks to see if the read worked. I've put diffs from v33 below. I hope that works!

==Doug Claar

D:\Vim\vim62\plugin>diff netrw.v33 netrw.vim
391a392,395
>     " If non-blank, show error message
>     if getline(1) !~ "^$"
>       echoerr getline(1)
>     endif
433a438,442
>
>     " If non-blank, show error message
>     if getline(1) !~ "^$"
>       echoerr getline(1)
>     endif
625a635,636
> let l:mod=&mod        " Save the modification state of file
>
723a735
>    let l:mod=0        " Assume it worked
741a754,759
>    if getline(1) =~ "^$"
>       let l:mod=0     " No message=>it worked
>    else
>       " Output the error message
>       echoerr getline(1)
>    endif
772a791,796
>    if getline(1) =~ "^$"
>       let l:mod=0     " No message=>it worked
>    else
>       " Output the error message
>       echoerr getline(1)
>    endif
784a809
>    let l:mod=0        " Assume it worked
818a844
>    let l:mod=0        " Assume it worked
829a856
>    let l:mod=0        " Assume it worked
842c869
<  if a:firstline == 1 && a:lastline == line("$")
---
>  if a:firstline == 1 && a:lastline == line("$") && l:mod == 0
843a871,872
>  else
>   set mod 

dougvim at claar dot org , July 16, 2003 13:19