Wikia

Vim Tips Wiki

Editing files on an ftp server listening on a non-standard port

Talk0
1,610pages on
this wiki
Revision as of 00:16, May 9, 2010 by JohnBeckett (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 480 Printable Monobook Previous Next

created May 29, 2003 · complexity basic · author George Harrison · version 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.

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

This works on Red Hat and on Windows.

CommentsEdit

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

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

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!

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

Advertisement | Your ad here

Around Wikia's network

Random Wiki