sponsor Vim development Vim logo Vim Book Ad

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

 tip karma   Rating 19/12, Viewed by 1178 

created:   May 29, 2003 8:18      complexity:   basic
author:   George Harrison      as of Vim:   6.0

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.

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


This works on Red Hat and on WindowsNT.


 rate this tip  Life Changing Helpful Unfulfilling 

<<Replace with NO Typing | abbreviations only on shortcut >>

Additional Notes

[email protected], May 29, 2003 13:02
<netrw.vim> will accept a colon for ports with ftp, too:
   ftp://[user@]machine[[:#]port]/path/to/file
jaldri1 at gl dot umbc dot edu, June 6, 2003 10:04
Mind blowing!  But, don't to add username@; vim treats it as part of the hostname (i.e. "Unknown host username@host").  {Tested on Win2k}
[email protected], June 13, 2003 7:18
Hmm, you're right, somewhere along the way the "user@" got disabled.  I've uploaded v33 under http://www.erols.com/astronaut/index.html#vimlinks_scripts which fixes that problem.
dougvim at claar dot org, July 16, 2003 13:19
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
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo