Vim Tips Wiki
m (Reverted edits by 217.157.197.89 (talk) to last version by JohnBot)
 
Line 30: Line 30:
 
This works on Red Hat and on Windows.
 
This works on Red Hat and on Windows.
   
  +
==Comments==
<span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">==Comments== {{script|id=1075|text=netrw.vim}} will accept a colon for ports with ftp, too: ftp://[user@]machine[[:#]port]/path/to/file ---- This script is great, but beware!</span> == Kommentarer == ((script | id = 1075 | tekst = netrw.vim)) vil acceptere et kolon for havne med ftp også: ftp:// [bruger @] maskine [[:#] port] / sti / til / fil ---- Dette script er godt, men pas på!</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">It does not check to see if it really wrote your file!</span> Det behøver ikke tjekke for at se om det virkelig skrev din fil!</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">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.</span> Hvis du for eksempel, bruger du en kilde kontrolsystem, og glemmer at tjekke filen ud, inden den ændrer det, vil du miste dit arbejde.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">(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.</span> (Gee, jeg spekulerer på, hvor han ved, at ...) Jeg sendte en revideret kopi af scriptet til forfatteren, der kontrollerer status for ftp-sagen (da det er det eneste tilfælde, jeg kan bruge), men enten han ikke få det , han er travlt, han kunne ikke lide mine ændringer, eller han arbejder på at gøre det arbejde for andre protokoller ... Jeg tøver med at indsende dem uden hans velsignelse, det er den første vim script, jeg nogensinde har mucked med.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">It also checks to see if the read worked.</span> Den kontrollerer også at se, om de læste arbejdede.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">I've put diffs from v33 below.</span> Jeg har lagt diff fra v33 nedenfor.</span> <span onmouseover="_tipon(this)" onmouseout="_tipoff()"><span class="google-src-text" style="direction: ltr; text-align: left">I hope that works! <pre> 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 </pre> ----</span> Jeg håber, der virker! <pre> D: \ Vim \ vim62 \ plugin> diff netrw.v33 netrw.vim 391a392, 395> "Hvis ikke-tom, viser fejlmeddelelsen> hvis getline (1)! ~" ^ $ "> echoerr getline (1)> endif 433a438, 442>> "Hvis ikke-tom, viser fejlmeddelelsen> hvis getline (1)! ~" ^ $ "> echoerr getline (1)> endif 625a635, 636> lad l: mod = & mod "Gem ændring tilstand fil> 723a735> lad l: mod = 0" Antag det virkede 741a754, 759>, hvis getline (1) = ~ "^ $"> Lad l: mod = 0 "Ingen besked => det virkede > ellers> "Output fejlmeddelelsen> echoerr getline (1)> endif 772a791, 796>, hvis getline (1) = ~" ^ $ "> Lad l: mod = 0" Ingen besked => det virkede> ellers> "Output fejlmeddelelsen> echoerr getline (1)> endif 784a809> lad l: mod = 0 "Antag det virkede 818a844> lad l: mod = 0" Antag det virkede 829a856> lad l: mod = 0 "Antag det virkede 842c869 <hvis a: firstline == 1 & & a: lastline == line ("$") ---> hvis en: firstline == 1 & & a: lastline == linje ("$") & & l: mod == 0 843a871, 872> ellers> sæt mod </ pre> ----</span>
 
  +
{{script|id=1075|text=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!
  +
  +
<pre>
  +
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
  +
</pre>
  +
  +
----

Latest revision as of 00:16, 9 May 2010

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.

Comments[]

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