Changeset 1f29650b for patches


Ignore:
Timestamp:
May 31, 2014, 5:49:35 PM (6 years ago)
Author:
William Harrington <kb0iic@…>
Branches:
clfs-3.0.0-systemd, master, systemd
Children:
f91c528
Parents:
6df80c0
Message:

Update vim branch update patch to patch level 316.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • patches/vim-7.4-branch_update-4.patch

    r6df80c0 r1f29650b  
    11Submitted By: William Harrington (kb0iic at cross-lfs dot org)
    2 Date: 2014-04-26
     2Date: 2014-05-31
    33Initial Package Version: 7.4
    44Origin: Upstream
    55Upstream Status: Applied
    6 Description: Contains all upstream patches up to 7.4.265.
     6Description: Contains all upstream patches up to 7.4.316.
    77
    88diff -Naur vim74.orig/.hg_archival.txt vim74/.hg_archival.txt
    99--- vim74.orig/.hg_archival.txt 1970-01-01 00:00:00.000000000 +0000
    10 +++ vim74/.hg_archival.txt      2014-04-27 05:20:57.181745403 +0000
     10+++ vim74/.hg_archival.txt      2014-06-01 00:42:48.067546692 +0000
    1111@@ -0,0 +1,5 @@
    1212+repo: 770908d1cb47c04be0aef5c173b17ab8be6b6476
    13 +node: 01f2b7e6b33ca4da4fbe2a5b8e9184ea2749d64e
     13+node: bed71c37618c11240596390f277d4f5e60d35ebc
    1414+branch: default
    15 +latesttag: v7-4-265
     15+latesttag: v7-4-316
    1616+latesttagdistance: 1
    1717diff -Naur vim74.orig/.hgignore vim74/.hgignore
    1818--- vim74.orig/.hgignore        1970-01-01 00:00:00.000000000 +0000
    19 +++ vim74/.hgignore     2014-04-27 05:20:57.188412237 +0000
     19+++ vim74/.hgignore     2014-06-01 00:42:48.107546590 +0000
    2020@@ -0,0 +1,74 @@
    2121+syntax: glob
     
    9595diff -Naur vim74.orig/.hgtags vim74/.hgtags
    9696--- vim74.orig/.hgtags  1970-01-01 00:00:00.000000000 +0000
    97 +++ vim74/.hgtags       2014-04-27 05:20:57.195079070 +0000
    98 @@ -0,0 +1,2990 @@
     97+++ vim74/.hgtags       2014-06-01 00:42:48.127546539 +0000
     98@@ -0,0 +1,3041 @@
    9999+004eb98eb3c30714cb6a24ec3e810275080a8413 v7-1-117
    100100+006e9c8a6a8ad354a5cb6adcce6ebfceddeb20ee v7-0079
     
    30873087+00acac0af680c2d8c82db5258474b121a5908926 v7-4-264
    30883088+8ec9d2196bee0c5108f2d2c196a660a7f4e5f29f v7-4-265
     3089+8f84e906d454a95d3167678a745dde9de442b604 v7-4-266
     3090+75f222d67cea335efbe0274de6340dba174c1e7e v7-4-267
     3091+1a5ed2626b26a982e307a206572121a557adf709 v7-4-268
     3092+81c26975e8f9dc7435353581346542409403f296 v7-4-269
     3093+c519c446c5488bfd48c93a03efae4ae3e0c1f162 v7-4-270
     3094+88b0571de4327ba5127a483493bd7d46e6a9850e v7-4-271
     3095+00228400629e28384f7f52556c3c119ba0d0a44d v7-4-272
     3096+747afb6a6de437131d9674e6b2bcc73d74863a89 v7-4-273
     3097+1ee3fc5b40ae94c2a7fc5a62bca38d4f730f9bb2 v7-4-274
     3098+8a3117a4887c1e12a1165c9719491f96753787d6 v7-4-275
     3099+a6b59ee633a355095e6473ec5e2a7d9088bfb853 v7-4-276
     3100+373204662d82e894b27ee76bc3319bc62c91f6ae v7-4-277
     3101+b4ce0e1fb5a67d7d6b0bca8eaa3edc2e94a085d8 v7-4-278
     3102+8e9db1f27a0063df023cc05a760fce73255dad24 v7-4-279
     3103+daf7e98675cf395e1ef96f8040567affb2782a11 v7-4-280
     3104+24c90f1fec859b54cf2b854b98c4c9e614c46061 v7-4-281
     3105+6d0a1132dd71c7f55f7ed53fe99e97c79bfd05a4 v7-4-282
     3106+aa99d04fa7e288a8580e3a5d4a9d6433a1572b48 v7-4-283
     3107+3c35ca9666e88a8024af6dab585b8e79ab295f83 v7-4-284
     3108+5cb1828fd0056de3c166e71fbafc67a74c57d7b1 v7-4-285
     3109+be19015ef43cc17825929206790696c2e716035d v7-4-286
     3110+66fe4908b649ba18426af6f69e8ccb01b487dcbd v7-4-287
     3111+7965cb6a435ae1ea331c7c2f8740d3d4c3625f3b v7-4-288
     3112+99374096a76b96d1128f5e6aa1fa92b4ba70fee9 v7-4-289
     3113+b871734bf54ea185dbd2cc759d86dbfbe21cde26 v7-4-290
     3114+b5972833add9de714f4651e26fd9ea63ec4a880c v7-4-291
     3115+60cdaa05a6ad31cef55eb6b3dc1f57ecac6fcf79 v7-4-292
     3116+10fc95f48546f438648b8357062e93c9c2c0a377 v7-4-293
     3117+fdea5ea9afd139ea59dee6bdb3f1675b8b882bdf v7-4-294
     3118+662ae48e7e246a63d38c9f3165b15b62252edaee v7-4-295
     3119+53b87d790574b6d19034fb3390987c22fb928c58 v7-4-296
     3120+81f5a056b2a582c8109da10cc538dc16a326a34d v7-4-297
     3121+156f891d520e93eab5d3ce02784660fb13a3b0d3 v7-4-298
     3122+daebf8ce66089c0c179fb436ceba359ef8d593d5 v7-4-299
     3123+1157079ca5f167bcf8746dfc52ea5a85e6c87a30 v7-4-300
     3124+8cb42aa3c4957a543e5dffe307475dbab969612f v7-4-301
     3125+df141c80ea3a1ffcbf82d05c1314675231fcfa75 v7-4-302
     3126+463ef551e9f62b63ac3f85f1f297b668b14bcd09 v7-4-303
     3127+fed2e0967f8133ba9a44b0701f151c8d88c4896a v7-4-304
     3128+63e7cc62402dffb180b40c04c63ceeb5f53957d7 v7-4-305
     3129+05e1d8afcc5e375bf708ccc9810e2fd1a5a8a3cf v7-4-306
     3130+06c10522d321d98874546b2a4d3b0ae145386f2e v7-4-307
     3131+e3d2b8d83bb30c428a051f50791e454fcbc080af v7-4-308
     3132+88a6e9f33822d33b6c32db578750c6c178c63f50 v7-4-309
     3133+ccac0aa34eeaf46dad4b831461a532fc3fe71096 v7-4-310
     3134+f6f7543043246107075f0d3739c471d51b7226da v7-4-311
     3135+66eead134d6800fd4cf2d5d4b135d300c933f09a v7-4-312
     3136+332a5c2b2956d9b18d85268a724d01deea27ec83 v7-4-313
     3137+4d7af1962d6ce61df65fdc5c86544a61951f9517 v7-4-314
     3138+646616b6ff4defcc7bef0b198b540f6d965a8126 v7-4-315
     3139+0fc665889e8f0af532cb4e3be2f0ff0421bf2fbc v7-4-316
    30893140diff -Naur vim74.orig/Filelist vim74/Filelist
    30903141--- vim74.orig/Filelist 2013-07-13 13:23:38.000000000 +0000
    3091 +++ vim74/Filelist      2014-04-27 05:20:57.198412485 +0000
    3092 @@ -80,10 +80,14 @@
     3142+++ vim74/Filelist      2014-06-01 00:42:48.197546361 +0000
     3143@@ -3,6 +3,7 @@
     3144 
     3145 # source files for all source archives
     3146 SRC_ALL =      \
     3147+               .hgignore \
     3148                src/README.txt \
     3149                src/arabic.c \
     3150                src/arabic.h \
     3151@@ -80,10 +81,15 @@
    30933152                src/main.aap \
    30943153                src/testdir/main.aap \
     
    31023161                src/testdir/test83-tags? \
    31033162+               src/testdir/test77a.com \
     3163+               src/testdir/test_*.vim \
    31043164                src/testdir/python2/*.py \
    31053165                src/testdir/python3/*.py \
     
    31073167diff -Naur vim74.orig/runtime/autoload/clojurecomplete.vim vim74/runtime/autoload/clojurecomplete.vim
    31083168--- vim74.orig/runtime/autoload/clojurecomplete.vim     2013-02-06 14:35:23.000000000 +0000
    3109 +++ vim74/runtime/autoload/clojurecomplete.vim  2014-04-27 05:20:57.231746647 +0000
     3169+++ vim74/runtime/autoload/clojurecomplete.vim  2014-06-01 00:42:49.274210286 +0000
    31103170@@ -1,20 +1,22 @@
    31113171 " Vim completion script
     
    31483208diff -Naur vim74.orig/runtime/autoload/getscript.vim vim74/runtime/autoload/getscript.vim
    31493209--- vim74.orig/runtime/autoload/getscript.vim   2013-04-17 13:40:44.000000000 +0000
    3150 +++ vim74/runtime/autoload/getscript.vim        2014-04-27 05:20:57.235080063 +0000
     3210+++ vim74/runtime/autoload/getscript.vim        2014-06-01 00:42:49.320876834 +0000
    31513211@@ -1,8 +1,8 @@
    31523212 " ---------------------------------------------------------------------
     
    31823242diff -Naur vim74.orig/runtime/autoload/netrw.vim vim74/runtime/autoload/netrw.vim
    31833243--- vim74.orig/runtime/autoload/netrw.vim       2013-05-19 03:28:33.000000000 +0000
    3184 +++ vim74/runtime/autoload/netrw.vim    2014-04-27 05:20:57.241746894 +0000
     3244+++ vim74/runtime/autoload/netrw.vim    2014-06-01 00:42:49.417543255 +0000
    31853245@@ -1,10 +1,10 @@
    31863246 " netrw.vim: Handles file transfer and remote directory listing across
     
    31883248-" Date:                May 18, 2013
    31893249-" Version:     149
    3190 +" Date:                Mar 20, 2014
    3191 +" Version:     151
     3250+" Date:                May 13, 2014
     3251+" Version:     152
    31923252 " Maintainer:  Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
    31933253 " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
     
    31973257 "               with or without modifications, provided that this copyright
    31983258 "               notice is copied with it. Like anything else that's free,
    3199 @@ -22,13 +22,7 @@
     3259@@ -22,13 +22,14 @@
    32003260 if &cp || exists("g:loaded_netrw")
    32013261   finish
     
    32063266- echo "***warning*** this version of netrw needs vim 7.3.465 or later"
    32073267- echohl Normal
    3208 - finish
    3209 -endif
    3210 +let g:loaded_netrw = "v151"
     3268+if v:version < 704 || !has("patch213")
     3269+ if !exists("s:needpatch213")
     3270+  echo "***sorry*** this version of netrw requires vim v7.4 with patch 213"
     3271+ endif
     3272+ let s:needpatch213= 1
     3273  finish
     3274 endif
     3275+let g:loaded_netrw = "v152"
    32113276 if !exists("s:NOTE")
    32123277  let s:NOTE    = 0
    32133278  let s:WARNING = 1
    3214 @@ -36,8 +30,9 @@
     3279@@ -36,8 +37,9 @@
    32153280 endif
    32163281 
     
    32243289 
    32253290 " ======================
    3226 @@ -49,7 +44,7 @@
     3291@@ -49,7 +51,7 @@
    32273292 "   0=note     = s:NOTE
    32283293 "   1=warning  = s:WARNING
    32293294 "   2=error    = s:ERROR
    32303295-"  May 01, 2013 : max errnum currently is 93
    3231 +"  Mar 04, 2014 : max errnum currently is 96
     3296+"  Apr 16, 2014 : max errnum currently is 97
    32323297 fun! netrw#ErrorMsg(level,msg,errnum)
    32333298 "  call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
    32343299 
    3235 @@ -104,7 +99,7 @@
     3300@@ -104,8 +106,8 @@
    32363301     hi link netrwMesgWarning WarningMsg
    32373302     hi link netrwMesgError   Error
    32383303    endif
    32393304-"   call Decho("(ErrorMsg) setl noma ro bh=wipe")
     3305-   setl noma ro bh=wipe
    32403306+"   call Decho("setl noma ro bh=wipe")
    3241     setl noma ro bh=wipe
     3307+   setl ro nomod noma bh=wipe
    32423308 
    32433309   else
    3244 @@ -200,6 +195,7 @@
     3310    " (optional) netrw will show messages using echomsg.  Even if the
     3311@@ -200,6 +202,7 @@
    32453312   let g:netrw_http_cmd = ""
    32463313  endif
     
    32503317 call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
    32513318 if !exists("g:netrw_scp_cmd")
    3252 @@ -260,6 +256,7 @@
     3319@@ -249,7 +252,7 @@
     3320 call s:NetrwInit("g:netrw_altv"        , &spr)
     3321 call s:NetrwInit("g:netrw_banner"      , 1)
     3322 call s:NetrwInit("g:netrw_browse_split", 0)
     3323-call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro")
     3324+call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
     3325 call s:NetrwInit("g:netrw_chgwin"      , -1)
     3326 call s:NetrwInit("g:netrw_compress"    , "gzip")
     3327 call s:NetrwInit("g:netrw_ctags"       , "ctags")
     3328@@ -260,6 +263,7 @@
    32533329 call s:NetrwInit("g:netrw_cursor"      , 2)
    32543330 let s:netrw_usercul = &cursorline
     
    32583334 call s:NetrwInit("s:didstarstar",0)
    32593335 call s:NetrwInit("g:netrw_dirhist_cnt"      , 0)
    3260 @@ -291,23 +288,19 @@
     3336@@ -291,23 +295,19 @@
    32613337 endif
    32623338 call s:NetrwInit("g:netrw_keepdir",1)
     
    32833359 call s:NetrwInit("g:netrw_list_hide","")
    32843360 " Default values - lh-lz ---------- {{{3
    3285 @@ -387,8 +380,17 @@
     3361@@ -323,7 +323,7 @@
     3362   if g:netrw_cygwin
     3363    let g:netrw_localcopycmd= "cp"
     3364   else
     3365-   let g:netrw_localcopycmd= "cmd /c copy"
     3366+   let g:netrw_localcopycmd= expand("$COMSPEC")." /c copy"
     3367   endif
     3368  elseif has("unix") || has("macunix")
     3369   let g:netrw_localcopycmd= "cp"
     3370@@ -335,7 +335,15 @@
     3371  let g:netrw_localmkdir= g:netrw_local_mkdir
     3372  call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
     3373 endif
     3374-call s:NetrwInit("g:netrw_localmkdir","mkdir")
     3375+if has("win32") || has("win95") || has("win64") || has("win16")
     3376+  if g:netrw_cygwin
     3377+   call s:NetrwInit("g:netrw_localmkdir","mkdir")
     3378+  else
     3379+   let g:netrw_localmkdir= expand("$COMSPEC")." /c mkdir"
     3380+  endif
     3381+else
     3382+ call s:NetrwInit("g:netrw_localmkdir","mkdir")
     3383+endif
     3384 call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
     3385 if exists("g:netrw_local_movecmd")
     3386  let g:netrw_localmovecmd= g:netrw_local_movecmd
     3387@@ -346,7 +354,7 @@
     3388   if g:netrw_cygwin
     3389    let g:netrw_localmovecmd= "mv"
     3390   else
     3391-   let g:netrw_localmovecmd= "cmd /c move"
     3392+   let g:netrw_localmovecmd= expand("$COMSPEC")." /c move"
     3393   endif
     3394  elseif has("unix") || has("macunix")
     3395   let g:netrw_localmovecmd= "mv"
     3396@@ -354,11 +362,19 @@
     3397   let g:netrw_localmovecmd= ""
     3398  endif
     3399 endif
     3400-call s:NetrwInit("g:netrw_localrmdir", "rmdir")
     3401 if exists("g:netrw_local_rmdir")
     3402  let g:netrw_localrmdir= g:netrw_local_rmdir
     3403  call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
     3404 endif
     3405+if has("win32") || has("win95") || has("win64") || has("win16")
     3406+  if g:netrw_cygwin
     3407+   call s:NetrwInit("g:netrw_localrmdir","rmdir")
     3408+  else
     3409+   let g:netrw_localrmdir= expand("$COMSPEC")." /c rmdir"
     3410+  endif
     3411+else
     3412+ call s:NetrwInit("g:netrw_localrmdir","rmdir")
     3413+endif
     3414 call s:NetrwInit("g:netrw_liststyle"  , s:THINLIST)
     3415 " sanity checks
     3416 if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
     3417@@ -387,8 +403,17 @@
    32863418 call s:NetrwInit("g:netrw_rename_cmd"    , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
    32873419 call s:NetrwInit("g:netrw_rm_cmd"        , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
     
    33033435 call s:NetrwInit("g:netrw_sepchr"        , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
    33043436 call s:NetrwInit("s:netrw_silentxfer"    , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
    3305 @@ -404,7 +406,7 @@
     3437@@ -404,7 +429,7 @@
    33063438 endif
    33073439 call s:NetrwInit("g:netrw_special_syntax"   , 0)
     
    33123444 call s:NetrwInit("g:netrw_timefmt","%c")
    33133445 if !exists("g:netrw_xstrlen")
    3314 @@ -434,6 +436,11 @@
     3446@@ -421,7 +446,6 @@
     3447 call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
     3448 call s:NetrwInit("g:netrw_win95ftp",1)
     3449 call s:NetrwInit("g:netrw_winsize",50)
     3450-if g:netrw_winsize ==  0|let g:netrw_winsize=  -1|endif
     3451 if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
     3452 " ---------------------------------------------------------------------
     3453 " Default values for netrw's script variables: {{{2
     3454@@ -434,6 +458,11 @@
    33153455 call s:NetrwInit("g:netrw_menu_escape",'.&? \')
    33163456 call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
     
    33243464 " BufEnter event ignored by decho when following variable is true
    33253465 "  Has a side effect that doau BufReadPost doesn't work, so
    3326 @@ -444,11 +451,18 @@
     3466@@ -444,11 +473,18 @@
    33273467 "  Netrw Initialization: {{{1
    33283468 " ======================
     
    33483488 au WinEnter *  if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
    33493489 
    3350 @@ -457,276 +471,43 @@
     3490@@ -457,276 +493,43 @@
    33513491 " ==============================
    33523492 
     
    36593799 "          indx:  == -1: Nexplore
    36603800 "                 == -2: Pexplore
    3661 @@ -737,7 +518,7 @@
     3801@@ -737,7 +540,7 @@
    36623802 "                      * If Hexplore or Vexplore, then this will override
    36633803 "                        g:netrw_winsize to specify the qty of rows or columns the
     
    36683808 "          style == 0: Explore     style == 1: Explore!
    36693809 "                == 2: Hexplore    style == 3: Hexplore!
    3670 @@ -747,26 +528,52 @@
     3810@@ -747,26 +550,52 @@
    36713811 "  call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%"))
    36723812   if !exists("b:netrw_curdir")
     
    37313871    let winsz= g:netrw_winsize
    37323872    if a:indx > 0
    3733 @@ -774,106 +581,106 @@
     3873@@ -774,106 +603,119 @@
    37343874    endif
    37353875 
     
    37383878+"    call Decho("style=0: Explore or Sexplore")
    37393879     let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
    3740      exe winsz."wincmd s"
     3880-    exe winsz."wincmd s"
     3881+    if winsz == 0|let winsz= ""|endif
     3882+    exe "noswapfile ".winsz."wincmd s"
     3883+"    call Decho("exe noswapfile ".winsz."wincmd s")
    37413884 
    37423885    elseif a:style == 1  "Explore!, Sexplore!
     
    37443887+"    call Decho("style=1: Explore! or Sexplore!")
    37453888     let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
    3746      exe "keepalt ".winsz."wincmd v"
     3889-    exe "keepalt ".winsz."wincmd v"
     3890+    if winsz == 0|let winsz= ""|endif
     3891+    exe "keepalt noswapfile ".winsz."wincmd v"
     3892+"    call Decho("exe keepalt noswapfile ".winsz."wincmd v")
    37473893 
    37483894    elseif a:style == 2  " Hexplore
     
    37503896+"    call Decho("style=2: Hexplore")
    37513897     let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
    3752      exe "keepalt bel ".winsz."wincmd s"
     3898-    exe "keepalt bel ".winsz."wincmd s"
     3899+    if winsz == 0|let winsz= ""|endif
     3900+    exe "keepalt noswapfile bel ".winsz."wincmd s"
     3901+"    call Decho("exe keepalt noswapfile bel ".winsz."wincmd s")
    37533902 
    37543903    elseif a:style == 3  " Hexplore!
     
    37563905+"    call Decho("style=3: Hexplore!")
    37573906     let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
    3758      exe "keepalt abo ".winsz."wincmd s"
     3907-    exe "keepalt abo ".winsz."wincmd s"
     3908+    if winsz == 0|let winsz= ""|endif
     3909+    exe "keepalt noswapfile abo ".winsz."wincmd s"
     3910+"    call Decho("exe keepalt noswapfile abo ".winsz."wincmd s")
    37593911 
    37603912    elseif a:style == 4  " Vexplore
     
    37623914+"    call Decho("style=4: Vexplore")
    37633915     let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
    3764      exe "keepalt lefta ".winsz."wincmd v"
     3916-    exe "keepalt lefta ".winsz."wincmd v"
     3917+    if winsz == 0|let winsz= ""|endif
     3918+    exe "keepalt noswapfile lefta ".winsz."wincmd v"
     3919+"    call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v")
    37653920 
    37663921    elseif a:style == 5  " Vexplore!
     
    37683923+"    call Decho("style=5: Vexplore!")
    37693924     let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
    3770      exe "keepalt rightb ".winsz."wincmd v"
     3925-    exe "keepalt rightb ".winsz."wincmd v"
     3926+    if winsz == 0|let winsz= ""|endif
     3927+    exe "keepalt noswapfile rightb ".winsz."wincmd v"
     3928+"    call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v")
    37713929 
    37723930    elseif a:style == 6  " Texplore
     
    37753933+"    call Decho("style  = 6: Texplore")
    37763934     exe "keepalt tabnew ".fnameescape(curdir)
     3935+"    call Decho("exe keepalt tabnew ".fnameescape(curdir))
    37773936     call s:RestoreBufVars()
    37783937    endif
     
    38644023    if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
    38654024     let b:netrw_curdir = prefixdir
    3866 @@ -882,30 +689,30 @@
     4025@@ -882,30 +724,30 @@
    38674026    endif
    38684027    let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
     
    39024061    if dirname =~ '^scp://' || dirname =~ '^ftp://'
    39034062     call netrw#Nread(2,dirname)
    3904 @@ -914,15 +721,17 @@
     4063@@ -914,15 +756,17 @@
    39054064     if dirname == ""
    39064065      let dirname= getcwd()
     
    39234082    if exists("w:netrw_bannercnt")
    39244083     " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
    3925 @@ -930,7 +739,7 @@
     4084@@ -930,7 +774,7 @@
    39264085     exe w:netrw_bannercnt
    39274086    endif
     
    39324091    " Jan 24, 2013: not sure why the following was present.  See P08-Ingelrest
    39334092 "   if has("win32") || has("win95") || has("win64") || has("win16")
    3934 @@ -946,30 +755,32 @@
     4093@@ -946,30 +790,32 @@
    39354094   " starpat=4: Explore **/filepat  (recursive descent search for filenames matching filepat)
    39364095   elseif a:indx <= 0
     
    39724131 "      call Dret("netrw#Explore")
    39734132       return
    3974 @@ -978,21 +789,23 @@
     4133@@ -978,21 +824,23 @@
    39754134      if indx < 0                        | let indx= 0                           | endif
    39764135      if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
     
    40024161 "      call Dret("netrw#Explore")
    40034162       return
    4004 @@ -1001,30 +814,30 @@
     4163@@ -1001,30 +849,30 @@
    40054164      if indx < 0                        | let indx= 0                           | endif
    40064165      if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
     
    40404199        exe "keepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
    40414200       catch /^Vim\%((\a\+)\)\=:E480/
    4042 @@ -1037,15 +850,17 @@
     4201@@ -1037,15 +885,17 @@
    40434202 
    40444203      elseif starpat == 2
     
    40624221 "       call Dret("netrw#Explore : no files matched pattern")
    40634222        return
    4064 @@ -1057,29 +872,31 @@
     4223@@ -1057,53 +907,55 @@
    40654224 
    40664225      elseif starpat == 3
     
    40954254-      sil! let @* = keepregstar
    40964255-      sil! let @+ = keepregstar
     4256-      sil! let @/ = keepregslash
     4257-"      call Dret("netrw#Explore : no files matched")
    40974258+      if has("clipboard")
    40984259+       sil! let @* = keepregstar
    40994260+       sil! let @+ = keepregstar
    41004261+      endif
    4101        sil! let @/ = keepregslash
    4102  "      call Dret("netrw#Explore : no files matched")
     4262+      sil! let @/ = keepregslash
     4263+"      call Dret("netrw#Explore : no files matched")
    41034264       return
    4104 @@ -1088,22 +905,22 @@
     4265      endif
     4266     endif  " if indx ... endif
    41054267 
    41064268     " NetrwStatusLine support - for exploring support
     
    41304292     if !exists("w:netrw_liststyle")
    41314293      let w:netrw_liststyle= g:netrw_liststyle
    4132 @@ -1117,22 +934,24 @@
     4294@@ -1117,22 +969,24 @@
    41334295     let w:netrw_explore_bufnr   = bufnr("%")
    41344296     let w:netrw_explore_line    = line(".")
     
    41604322     sil! unlet w:netrw_treedict
    41614323     sil! unlet w:netrw_treetop
    4162 @@ -1146,22 +965,22 @@
     4324@@ -1146,22 +1000,22 @@
    41634325   endif
    41644326 
     
    41904352       if s:explore_match == ""
    41914353        let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
    4192 @@ -1177,7 +996,7 @@
     4354@@ -1177,7 +1031,7 @@
    41934355      endif
    41944356      let prvfname= fname
     
    41994361    endif
    42004362    echo "<s-up>==Pexplore  <s-down>==Nexplore"
    4201 @@ -1186,47 +1005,76 @@
     4363@@ -1186,47 +1040,76 @@
    42024364    if exists("s:explore_match")  | unlet s:explore_match  | endif
    42034365    if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
     
    43014463   if a:sys
    43024464    let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
    4303 @@ -1264,28 +1112,44 @@
     4465@@ -1264,28 +1147,44 @@
    43044466   endif
    43054467    echohl None
     
    43594521 
    43604522   if type(a:fname) == 1
    4361 @@ -1294,7 +1158,7 @@
     4523@@ -1294,7 +1193,7 @@
    43624524    let fnamelist= a:fname
    43634525   else
     
    43684530   endif
    43694531 "  call Decho("fnamelist<".string(fnamelist).">")
    4370 @@ -1472,7 +1336,7 @@
     4532@@ -1471,8 +1370,29 @@
     4533       keepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
    43714534      endif
    43724535     endif
     4536+
     4537+   elseif b:netrw_method == 9
     4538+    " obtain file using sftp
     4539+"    call Decho("obtain via sftp (method #9)")
     4540+    if a:fname =~ '/'
     4541+     let localfile= substitute(a:fname,'^.*/','','')
     4542+    else
     4543+     let localfile= a:fname
     4544+    endif
     4545+"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1).shellescape(localfile)." ".shellescape(tgtdir))
     4546+    exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1).shellescape(localfile)." ".shellescape(tgtdir)
     4547+
    43734548    elseif !exists("b:netrw_method") || b:netrw_method < 0
    43744549-"    call Dfunc("netrw#NetrwObtain : unsupported method")
    4375 +"    call Dfunc("netrw#Obtain : unsupported method")
     4550+    " probably a badly formed url; protocol not recognized
     4551+"    call Dret("netrw#Obtain : unsupported method")
     4552+    return
     4553+
     4554+   else
     4555+    " protocol recognized but not supported for Obtain (yet?)
     4556+    if !exists("g:netrw_quiet")
     4557+     keepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
     4558+    endif
     4559+"    call Dret("netrw#Obtain : current protocol not supported for obtaining file")
    43764560     return
    43774561    endif
    43784562 
    4379 @@ -1492,553 +1356,407 @@
     4563@@ -1492,107 +1412,387 @@
    43804564    endif
    43814565   endif
     
    44474631-  call s:NetrwSafeOptions()
    44484632-  call s:RestoreCursorline()
    4449 -
    4450 -  " NetRead: interpret mode into a readcmd {{{3
    4451 -  if     a:mode == 0 " read remote file before current line
    4452 -   let readcmd = "0r"
    4453 -  elseif a:mode == 1 " read file after current line
    4454 -   let readcmd = "r"
    4455 -  elseif a:mode == 2 " replace with remote file
    4456 -   let readcmd = "%r"
    4457 -  elseif a:mode == 3 " skip read of file (leave as temporary)
    4458 -   let readcmd = "t"
    4459 -  else
    4460 -   exe a:mode
    4461 -   let readcmd = "r"
    4462 -  endif
    4463 -  let ichoice = (a:0 == 0)? 0 : 1
    4464 -"  call Decho("readcmd<".readcmd."> ichoice=".ichoice)
    4465 -
    4466 -  " NetRead: get temporary filename {{{3
    4467 -  let tmpfile= s:GetTempfile("")
    4468 -  if tmpfile == ""
    4469 -"   call Dret("netrw#NetRead : unable to get a tempfile!")
    44704633+" s:NetrwOptionRestore: restore options (based on prior s:NetrwOptionSave) {{{2
    44714634+fun! s:NetrwOptionRestore(vt)
     
    44854648+"   call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    44864649+"   call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
    4487     return
    4488    endif
     4650+   return
     4651+  endif
    44894652+  unlet {a:vt}netrw_optionsave
    44904653 
    4491 -  while ichoice <= a:0
    4492 -
    4493 -   " attempt to repeat with previous host-file-etc
    4494 -   if exists("b:netrw_lastfile") && a:0 == 0
    4495 -"    call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
    4496 -    let choice = b:netrw_lastfile
    4497 -    let ichoice= ichoice + 1
    4498 -
    4499 -   else
    4500 -    exe "let choice= a:" . ichoice
    4501 -"    call Decho("no lastfile: choice<" . choice . ">")
    4502 -
    4503 -    if match(choice,"?") == 0
    4504 -     " give help
    4505 -     echomsg 'NetRead Usage:'
    4506 -     echomsg ':Nread machine:path                         uses rcp'
    4507 -     echomsg ':Nread "machine path"                       uses ftp   with <.netrc>'
    4508 -     echomsg ':Nread "machine id password path"           uses ftp'
    4509 -     echomsg ':Nread dav://machine[:port]/path            uses cadaver'
    4510 -     echomsg ':Nread fetch://machine/path                 uses fetch'
    4511 -     echomsg ':Nread ftp://[user@]machine[:port]/path     uses ftp   autodetects <.netrc>'
    4512 -     echomsg ':Nread http://[user@]machine/path           uses http  wget'
    4513 -     echomsg ':Nread rcp://[user@]machine/path            uses rcp'
    4514 -     echomsg ':Nread rsync://machine[:port]/path          uses rsync'
    4515 -     echomsg ':Nread scp://[user@]machine[[:#]port]/path  uses scp'
    4516 -     echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
    4517 -     sleep 4
    4518 -     break
    4519 -
    4520 -    elseif match(choice,'^"') != -1
    4521 -     " Reconstruct Choice if choice starts with '"'
    4522 -"     call Decho("reconstructing choice")
    4523 -     if match(choice,'"$') != -1
    4524 -      " case "..."
    4525 -      let choice= strpart(choice,1,strlen(choice)-2)
    4526 -     else
    4527 -       "  case "... ... ..."
    4528 -      let choice      = strpart(choice,1,strlen(choice)-1)
    4529 -      let wholechoice = ""
    4530 -
    4531 -      while match(choice,'"$') == -1
    4532 -       let wholechoice = wholechoice . " " . choice
    4533 -       let ichoice     = ichoice + 1
    4534 -       if ichoice > a:0
    4535 -               if !exists("g:netrw_quiet")
    4536 -        call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
    4537 -       endif
    4538 -"        call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
    4539 -        return
    4540 -       endif
    4541 -       let choice= a:{ichoice}
    4542 -      endwhile
    4543 -      let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
    4544 -     endif
     4654-  " NetRead: interpret mode into a readcmd {{{3
     4655-  if     a:mode == 0 " read remote file before current line
     4656-   let readcmd = "0r"
     4657-  elseif a:mode == 1 " read file after current line
     4658-   let readcmd = "r"
     4659-  elseif a:mode == 2 " replace with remote file
     4660-   let readcmd = "%r"
     4661-  elseif a:mode == 3 " skip read of file (leave as temporary)
     4662-   let readcmd = "t"
    45454663+  if exists("+acd")
    45464664+   if exists("{a:vt}netrw_acdkeep")
     
    45514669+    if &l:acd
    45524670+     call s:NetrwLcd(curdir)
    4553      endif
    4554     endif
    4555 -
    4556 -"   call Decho("choice<" . choice . ">")
    4557 -   let ichoice= ichoice + 1
    4558 -
    4559 -   " NetRead: Determine method of read (ftp, rcp, etc) {{{3
    4560 -   call s:NetrwMethod(choice)
    4561 -   if !exists("b:netrw_method") || b:netrw_method < 0
    4562 -"    call Dfunc("netrw#NetRead : unsupported method")
    4563 -    return
     4671+    endif
     4672+   endif
    45644673+  endif
    45654674+  if exists("{a:vt}netrw_aikeep")   |let &l:ai     = {a:vt}netrw_aikeep      |unlet {a:vt}netrw_aikeep   |endif
     
    45904699+  if exists("{a:vt}netrw_modkeep")  |let &l:mod    = {a:vt}netrw_modkeep     |unlet {a:vt}netrw_modkeep  |endif
    45914700+  if exists("{a:vt}netrw_nukeep")   |let &l:nu     = {a:vt}netrw_nukeep      |unlet {a:vt}netrw_nukeep   |endif
     4701+  if exists("{a:vt}netrw_rnukeep")  |let &l:rnu    = {a:vt}netrw_rnukeep     |unlet {a:vt}netrw_rnukeep  |endif
    45924702+  if exists("{a:vt}netrw_repkeep")  |let &l:report = {a:vt}netrw_repkeep     |unlet {a:vt}netrw_repkeep  |endif
    45934703+  if exists("{a:vt}netrw_rokeep")   |let &l:ro     = {a:vt}netrw_rokeep      |unlet {a:vt}netrw_rokeep   |endif
     
    46174727+    sil! let &l:swf= {a:vt}netrw_swfkeep
    46184728+    unlet {a:vt}netrw_swfkeep
    4619     endif
    4620 -   let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
    4621 -
    4622 -   " Check if NetrwBrowse() should be handling this request
    4623 -"   call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
    4624 -   if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
    4625 -"    call Decho("yes, choice matches '^.*[\/]$'")
    4626 -    keepj call s:NetrwBrowse(0,choice)
    4627 -"    call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
    4628 -    return
     4729+   endif
    46294730+  endif
    46304731+  if exists("{a:vt}netrw_dirkeep") && isdirectory({a:vt}netrw_dirkeep) && g:netrw_keepdir
     
    46454746+   if exists("s:nbcd_curpos_".bufnr('%'))
    46464747+    unlet s:nbcd_curpos_{bufnr('%')}
    4647     endif
    4648 +  else
     4748+   endif
     4749   else
     4750-   exe a:mode
     4751-   let readcmd = "r"
    46494752+"   call Decho("no previous position")
    4650 +  endif
    4651  
    4652 -   " ============
    4653 -   " NetRead: Perform Protocol-Based Read {{{3
    4654 -   " ===========================
    4655 -   if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
    4656 -    echo "(netrw) Processing your read request..."
    4657 -   endif
     4753   endif
     4754-  let ichoice = (a:0 == 0)? 0 : 1
     4755-"  call Decho("readcmd<".readcmd."> ichoice=".ichoice)
     4756 
     4757-  " NetRead: get temporary filename {{{3
     4758-  let tmpfile= s:GetTempfile("")
     4759-  if tmpfile == ""
     4760-"   call Dret("netrw#NetRead : unable to get a tempfile!")
     4761-   return
    46584762+"  call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
    46594763+"  call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"))
     
    46674771+"   call Decho("filetype detect  (ft=".&ft.")")
    46684772+   filetype detect
    4669 +  endif
     4773   endif
    46704774+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
    46714775+"  call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
    46724776+endfun
    46734777 
    4674 -   ".........................................
    4675 -   " NetRead: (rcp)  NetRead Method #1 {{{3
    4676 -   if  b:netrw_method == 1 " read with rcp
    4677 -"    call Decho("read via rcp (method #1)")
    4678 -   " ER: nothing done with g:netrw_uid yet?
    4679 -   " ER: on Win2K" rcp machine[.user]:file tmpfile
    4680 -   " ER: if machine contains '.' adding .user is required (use $USERNAME)
    4681 -   " ER: the tmpfile is full path: rcp sees C:\... as host C
    4682 -   if s:netrw_has_nt_rcp == 1
    4683 -    if exists("g:netrw_uid") &&        ( g:netrw_uid != "" )
    4684 -     let uid_machine = g:netrw_machine .'.'. g:netrw_uid
    4685 -    else
    4686 -     " Any way needed it machine contains a '.'
    4687 -     let uid_machine = g:netrw_machine .'.'. $USERNAME
    4688 -    endif
    4689 -   else
    4690 -    if exists("g:netrw_uid") &&        ( g:netrw_uid != "" )
    4691 -     let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    4692 -    else
    4693 -     let uid_machine = g:netrw_machine
    4694 -    endif
    4695 -   endif
    4696 -"   call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    4697 -   exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    4698 -   let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4699 -   let b:netrw_lastfile = choice
     4778-  while ichoice <= a:0
     4779-
     4780-   " attempt to repeat with previous host-file-etc
     4781-   if exists("b:netrw_lastfile") && a:0 == 0
     4782-"    call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
     4783-    let choice = b:netrw_lastfile
     4784-    let ichoice= ichoice + 1
    47004785+" ---------------------------------------------------------------------
    47014786+" s:NetrwOptionSave: save options prior to setting to "netrw-buffer-standard" form {{{2
     
    47114796+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
    47124797 
    4713 -   ".........................................
    4714 -   " NetRead: (ftp + <.netrc>)  NetRead Method #2 {{{3
    4715 -   elseif b:netrw_method  == 2         " read with ftp + <.netrc>
    4716 -"     call Decho("read via ftp+.netrc (method #2)")
    4717 -     let netrw_fname= b:netrw_fname
    4718 -     keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
    4719 -     let filtbuf= bufnr("%")
    4720 -     setl ff=unix
    4721 -     keepj put =g:netrw_ftpmode
    4722 -"     call Decho("filter input: ".getline(line("$")))
    4723 -     if exists("g:netrw_ftpextracmd")
    4724 -      keepj put =g:netrw_ftpextracmd
    4725 -"      call Decho("filter input: ".getline(line("$")))
    4726 -     endif
    4727 -     call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
    4728 -"     call Decho("filter input: ".getline(line("$")))
    4729 -     if exists("g:netrw_port") && g:netrw_port != ""
    4730 -"      call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
    4731 -      exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
    4732 -     else
    4733 -"      call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
    4734 -      exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
    4735 -     endif
    4736 -     " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    4737 -     if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
    4738 -      let debugkeep = &debug
    4739 -      setl debug=msg
    4740 -      keepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
    4741 -      let &debug    = debugkeep
    4742 -     endif
    4743 -     call s:SaveBufVars()
    4744 -     bd!
    4745 -     if bufname("%") == "" && getline("$") == "" && line('$') == 1
    4746 -      " needed when one sources a file in a nolbl setting window via ftp
    4747 -      q!
    4748 -     endif
    4749 -     call s:RestoreBufVars()
    4750 -     let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4751 -     let b:netrw_lastfile = choice
     4798-   else
     4799-    exe "let choice= a:" . ichoice
     4800-"    call Decho("no lastfile: choice<" . choice . ">")
    47524801+  if !exists("{a:vt}netrw_optionsave")
    47534802+   let {a:vt}netrw_optionsave= 1
     
    47584807+"  call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff)
    47594808 
    4760 -   ".........................................
    4761 -   " NetRead: (ftp + machine,id,passwd,filename)  NetRead Method #3 {{{3
    4762 -   elseif b:netrw_method == 3          " read with ftp + machine, id, passwd, and fname
    4763 -    " Construct execution string (four lines) which will be passed through filter
    4764 -"    call Decho("read via ftp+mipf (method #3)")
    4765 -    let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    4766 -    keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
    4767 -    let filtbuf= bufnr("%")
    4768 -    setl ff=unix
    4769 -    if exists("g:netrw_port") && g:netrw_port != ""
    4770 -     keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    4771 -"     call Decho("filter input: ".getline('.'))
    4772 -    else
    4773 -     keepj put ='open '.g:netrw_machine
    4774 -"     call Decho("filter input: ".getline('.'))
    4775 -    endif
     4809-    if match(choice,"?") == 0
     4810-     " give help
     4811-     echomsg 'NetRead Usage:'
     4812-     echomsg ':Nread machine:path                         uses rcp'
     4813-     echomsg ':Nread "machine path"                       uses ftp   with <.netrc>'
     4814-     echomsg ':Nread "machine id password path"           uses ftp'
     4815-     echomsg ':Nread dav://machine[:port]/path            uses cadaver'
     4816-     echomsg ':Nread fetch://machine/path                 uses fetch'
     4817-     echomsg ':Nread ftp://[user@]machine[:port]/path     uses ftp   autodetects <.netrc>'
     4818-     echomsg ':Nread http://[user@]machine/path           uses http  wget'
     4819-     echomsg ':Nread rcp://[user@]machine/path            uses rcp'
     4820-     echomsg ':Nread rsync://machine[:port]/path          uses rsync'
    47764821+  " Save current settings and current directory
    47774822+"  call Decho("saving current settings and current directory")
     
    47824827+  let {a:vt}netrw_bhkeep    = &l:bh
    47834828+  let {a:vt}netrw_blkeep    = &l:bl
    4784 +"  let {a:vt}netrw_btkeep    = &l:bt
     4829+  let {a:vt}netrw_btkeep    = &l:bt
    47854830+  let {a:vt}netrw_bombkeep  = &l:bomb
    47864831+  let {a:vt}netrw_cedit     = &cedit
     
    47924837+  let {a:vt}netrw_diffkeep  = &l:diff
    47934838+  let {a:vt}netrw_fenkeep   = &l:fen
    4794 +  let {a:vt}netrw_ffkeep    = &l:ff
     4839+  if !exists("g:netrw_ffkeep") || g:netrw_ffkeep == 1
     4840+   let {a:vt}netrw_ffkeep    = &l:ff
     4841+  endif
    47954842+  let {a:vt}netrw_fokeep    = &l:fo           " formatoptions
    47964843+  let {a:vt}netrw_gdkeep    = &l:gd           " gdefault
     
    48034850+  let {a:vt}netrw_modkeep   = &l:mod
    48044851+  let {a:vt}netrw_nukeep    = &l:nu
     4852+  let {a:vt}netrw_rnukeep   = &l:rnu
    48054853+  let {a:vt}netrw_repkeep   = &l:report
    48064854+  let {a:vt}netrw_rokeep    = &l:ro
     
    48184866+  let {a:vt}netrw_wrapkeep  = &l:wrap
    48194867+  let {a:vt}netrw_writekeep = &l:write
    4820  
    4821 -    if exists("g:netrw_uid") && g:netrw_uid != ""
    4822 -     if exists("g:netrw_ftp") && g:netrw_ftp == 1
    4823 -      keepj put =g:netrw_uid
    4824 -"       call Decho("filter input: ".getline('.'))
    4825 -      if exists("s:netrw_passwd")
    4826 -       keepj put ='\"'.s:netrw_passwd.'\"'
    4827 -      endif
    4828 -"      call Decho("filter input: ".getline('.'))
    4829 -     elseif exists("s:netrw_passwd")
    4830 -      keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
    4831 -"      call Decho("filter input: ".getline('.'))
    4832 -     endif
    4833 -    endif
     4868+
    48344869+  " save a few selected netrw-related variables
    48354870+"  call Decho("saving a few selected netrw-related variables")
     
    48414876+  endif
    48424877+  sil! let {a:vt}netrw_regslash= @/
    4843  
    4844 -    if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
    4845 -     keepj put =g:netrw_ftpmode
    4846 -"     call Decho("filter input: ".getline('.'))
    4847 -    endif
    4848 -    if exists("g:netrw_ftpextracmd")
    4849 -     keepj put =g:netrw_ftpextracmd
    4850 -"     call Decho("filter input: ".getline('.'))
    4851 -    endif
    4852 -    keepj put ='get \"'.netrw_fname.'\" '.tmpfile
    4853 -"    call Decho("filter input: ".getline('.'))
     4878+
    48544879+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt)
    48554880+"  call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr())
    48564881+endfun
    4857  
    4858 -    " perform ftp:
    4859 -    " -i       : turns off interactive prompting from ftp
    4860 -    " -n  unix : DON'T use <.netrc>, even though it exists
    4861 -    " -n  win32: quit being obnoxious about password
    4862 -    keepj norm! 1Gdd
    4863 -"    call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
    4864 -    exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
    4865 -    " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    4866 -    if getline(1) !~ "^$"
    4867 -"     call Decho("error<".getline(1).">")
    4868 -     if !exists("g:netrw_quiet")
    4869 -      call netrw#ErrorMsg(s:ERROR,getline(1),5)
    4870 -     endif
    4871 -    endif
    4872 -    call s:SaveBufVars()|bd!|call s:RestoreBufVars()
    4873 -    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4874 -    let b:netrw_lastfile = choice
     4882+
    48754883+" ------------------------------------------------------------------------
    48764884+" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
     
    49114919+  setl cedit&
    49124920+  call s:NetrwCursor()
    4913  
    4914 -   ".........................................
    4915 -   " NetRead: (scp) NetRead Method #4 {{{3
    4916 -   elseif     b:netrw_method  == 4     " read with scp
    4917 -"    call Decho("read via scp (method #4)")
    4918 -    if exists("g:netrw_port") && g:netrw_port != ""
    4919 -     let useport= " ".g:netrw_scpport." ".g:netrw_port
    4920 -    else
    4921 -     let useport= ""
    4922 -    endif
    4923 -"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    4924 -    exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    4925 -    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4926 -    let b:netrw_lastfile = choice
     4921+
    49274922+  " allow the user to override safe options
    49284923+"  call Decho("ft<".&ft."> ei=".&ei)
     
    49314926+   sil! keepalt keepj doau FileType netrw
    49324927+  endif
    4933  
    4934 -   ".........................................
    4935 -   " NetRead: (http) NetRead Method #5 (wget) {{{3
    4936 -   elseif     b:netrw_method  == 5
    4937 -"    call Decho("read via http (method #5)")
    4938 -    if g:netrw_http_cmd == ""
    4939 -     if !exists("g:netrw_quiet")
    4940 -      call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
    4941 -     endif
    4942 -"     call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
    4943 -     return
    4944 -    endif
    4945 -
    4946 -    if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
    4947 -     " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
    4948 -"     call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
    4949 -     if exists("g:netrw_http_xcmd")
    4950 -"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
    4951 -      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
    4952 -     else
    4953 -"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1))
    4954 -      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)
    4955 -     endif
    4956 -     let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4957 -
    4958 -    else
    4959 -     " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
    4960 -"     call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
    4961 -     let netrw_html= substitute(b:netrw_fname,"#.*$","","")
    4962 -     let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
    4963 -"     call Decho("netrw_html<".netrw_html.">")
    4964 -"     call Decho("netrw_tag <".netrw_tag.">")
    4965 -"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1))
    4966 -     exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1)
    4967 -     let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    4968 -"     call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
    4969 -     exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
    4970 -    endif
    4971 -    let b:netrw_lastfile = choice
    4972 -"    call Decho("(NetRead) setl ro")
    4973 -    setl ro
    4974 -
    4975 -   ".........................................
    4976 -   " NetRead: (dav) NetRead Method #6 {{{3
    4977 -   elseif     b:netrw_method  == 6
    4978 -"    call Decho("read via cadaver (method #6)")
    4979 -
    4980 -    if !executable(g:netrw_dav_cmd)
    4981 -     call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
    4982 -"     call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
    4983 -     return
    4984 -    endif
    4985 -    if g:netrw_dav_cmd =~ "curl"
    4986 -"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
    4987 -     exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
    4988 -    else
    4989 -     " Construct execution string (four lines) which will be passed through filter
    4990 -     let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    4991 -     new
    4992 -     setl ff=unix
    4993 -     if exists("g:netrw_port") && g:netrw_port != ""
    4994 -      keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    4995 -     else
    4996 -      keepj put ='open '.g:netrw_machine
    4997 -     endif
    4998 -     if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
    4999 -      keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
    5000 -     endif
    5001 -     keepj put ='get '.netrw_fname.' '.tmpfile
    5002 -     keepj put ='quit'
    5003 -
    5004 -     " perform cadaver operation:
    5005 -     keepj norm! 1Gdd
    5006 -"    call Decho("executing: %!".g:netrw_dav_cmd)
    5007 -     exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
    5008 -     bd!
    5009 -    endif
    5010 -    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5011 -    let b:netrw_lastfile = choice
    5012 -
    5013 -   ".........................................
    5014 -   " NetRead: (rsync) NetRead Method #7 {{{3
    5015 -   elseif     b:netrw_method  == 7
    5016 -"    call Decho("read via rsync (method #7)")
    5017 -"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    5018 -    exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    5019 -    let result          = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
    5020 -    let b:netrw_lastfile = choice
    5021 -
    5022 -   ".........................................
    5023 -   " NetRead: (fetch) NetRead Method #8 {{{3
    5024 -   "    fetch://[user@]host[:http]/path
    5025 -   elseif     b:netrw_method  == 8
    5026 -"    call Decho("read via fetch (method #8)")
    5027 -    if g:netrw_fetch_cmd == ""
    5028 -     if !exists("g:netrw_quiet")
    5029 -      keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
    5030 -     endif
    5031 -"     call Dret("NetRead")
    5032 -     return
    5033 -    endif
    5034 -    if exists("g:netrw_option") && g:netrw_option == ":https\="
    5035 -     let netrw_option= "http"
    5036 -    else
    5037 -     let netrw_option= "ftp"
    5038 -    endif
    5039 -"    call Decho("read via fetch for ".netrw_option)
    5040 -
    5041 -    if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
    5042 -"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
    5043 -     exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1)
    5044 -    else
    5045 -"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
    5046 -     exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)
    5047 -    endif
    5048 -
    5049 -    let result         = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
    5050 -    let b:netrw_lastfile = choice
    5051 -"    call Decho("(NetRead) setl ro")
    5052 -    setl ro
     4928+
    50534929+"  call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh)
    50544930+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
    50554931+"  call Dret("s:NetrwSafeOptions")
    50564932+endfun
    5057  
    5058 -   ".........................................
    5059 -   " NetRead: (sftp) NetRead Method #9 {{{3
    5060 -   elseif     b:netrw_method  == 9
    5061 -"    call Decho("read via sftp (method #9)")
    5062 -"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
    5063 -    exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
    5064 -    let result         = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5065 -    let b:netrw_lastfile = choice
     4933+
    50664934+" ---------------------------------------------------------------------
    50674935+" NetrwStatusLine: {{{2
    50684936+fun! NetrwStatusLine()
    5069  
    5070 -   ".........................................
    5071 -   " NetRead: Complain {{{3
    5072 -   else
    5073 -    call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
    5074 -   endif
    5075 -  endwhile
     4937+
    50764938+" vvv NetrwStatusLine() debugging vvv
    50774939+"  let g:stlmsg=""
     
    50904952+"  endif
    50914953+" ^^^ NetrwStatusLine() debugging ^^^
    5092  
    5093 -  " NetRead: cleanup {{{3
    5094 -  if exists("b:netrw_method")
    5095 -"   call Decho("cleanup b:netrw_method and b:netrw_fname")
    5096 -   unlet b:netrw_method
    5097 -   unlet b:netrw_fname
    5098 -  endif
    5099 -  if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
    5100 -"   call Decho("cleanup by deleting tmpfile<".tmpfile.">")
    5101 -   keepj call s:NetrwDelete(tmpfile)
     4954+
    51024955+  if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
    51034956+   " restore user's status line
     
    51094962+  else
    51104963+   return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
    5111    endif
    5112 -  keepj call s:NetrwOptionRestore("w:")
    5113 -
    5114 -"  call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
    5115  endfun
    5116  
     4964+  endif
     4965+endfun
     4966+
    51174967+" ---------------------------------------------------------------------
    51184968+"  Netrw Transfer Functions: {{{1
    51194969+" ===============================
    51204970+
    5121  " ------------------------------------------------------------------------
    5122 -" netrw#NetWrite: responsible for writing a file over the net {{{2
    5123 -fun! netrw#NetWrite(...) range
    5124 -"  call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
     4971+" ------------------------------------------------------------------------
    51254972+" netrw#NetRead: responsible for reading a file over the net {{{2
    51264973+"   mode: =0 read remote file and insert before current line
     
    51304977+fun! netrw#NetRead(mode,...)
    51314978+"  call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
    5132  
    5133 -  " NetWrite: option handling {{{3
    5134 -  let mod= 0
     4979+
    51354980+  " NetRead: save options {{{3
    5136    call s:NetrwOptionSave("w:")
    5137    call s:NetrwSafeOptions()
     4981+  call s:NetrwOptionSave("w:")
     4982+  call s:NetrwSafeOptions()
    51384983+  call s:RestoreCursorline()
    5139  
    5140 -  " NetWrite: Get Temporary Filename {{{3
    5141 -  let tmpfile= s:GetTempfile("")
    5142 -  if tmpfile == ""
    5143 -"   call Dret("netrw#NetWrite : unable to get a tempfile!")
    5144 -   return
    5145 -  endif
    5146 -
    5147 -  if a:0 == 0
    5148 -   let ichoice = 0
    5149 -  else
    5150 -   let ichoice = 1
    5151 -  endif
    5152 -
    5153 -  let curbufname= expand("%")
    5154 -"  call Decho("curbufname<".curbufname.">")
    5155 -  if &binary
    5156 -   " For binary writes, always write entire file.
    5157 -   " (line numbers don't really make sense for that).
    5158 -   " Also supports the writing of tar and zip files.
    5159 -"   call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
    5160 -   exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
    5161 -  elseif g:netrw_cygwin
    5162 -   " write (selected portion of) file to temporary
    5163 -   let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','')
    5164 -"   call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
    5165 -   exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
     4984+
    51664985+  " NetRead: interpret mode into a readcmd {{{3
    51674986+  if     a:mode == 0 " read remote file before current line
     
    51734992+  elseif a:mode == 3 " skip read of file (leave as temporary)
    51744993+   let readcmd = "t"
    5175    else
    5176 -   " write (selected portion of) file to temporary
    5177 -"   call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
    5178 -   exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
     4994+  else
    51794995+   exe a:mode
    51804996+   let readcmd = "r"
    5181    endif
     4997+  endif
    51824998+  let ichoice = (a:0 == 0)? 0 : 1
    51834999+"  call Decho("readcmd<".readcmd."> ichoice=".ichoice)
    5184  
    5185 -  if curbufname == ""
    5186 -   " if the file is [No Name], and one attempts to Nwrite it, the buffer takes
    5187 -   " on the temporary file's name.  Deletion of the temporary file during
    5188 -   " cleanup then causes an error message.
    5189 -   0file!
     5000+
    51905001+  " NetRead: get temporary filename {{{3
    51915002+  let tmpfile= s:GetTempfile("")
     
    51935004+"   call Dret("netrw#NetRead : unable to get a tempfile!")
    51945005+   return
    5195    endif
    5196  
    5197 -  " NetWrite: while choice loop: {{{3
    5198    while ichoice <= a:0
    5199  
    5200 -   " Process arguments: {{{4
    5201     " attempt to repeat with previous host-file-etc
    5202     if exists("b:netrw_lastfile") && a:0 == 0
    5203  "    call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
    5204      let choice = b:netrw_lastfile
    5205      let ichoice= ichoice + 1
    5206 +
    5207     else
    5208      exe "let choice= a:" . ichoice
     5006+  endif
     5007+
     5008+  while ichoice <= a:0
     5009+
     5010+   " attempt to repeat with previous host-file-etc
     5011+   if exists("b:netrw_lastfile") && a:0 == 0
     5012+"    call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
     5013+    let choice = b:netrw_lastfile
     5014+    let ichoice= ichoice + 1
     5015+
     5016+   else
     5017+    exe "let choice= a:" . ichoice
    52095018+"    call Decho("no lastfile: choice<" . choice . ">")
    5210  
    5211 -    " Reconstruct Choice if choice starts with '"'
    5212      if match(choice,"?") == 0
    5213 -     echomsg 'NetWrite Usage:"'
    5214 -     echomsg ':Nwrite machine:path                        uses rcp'
    5215 -     echomsg ':Nwrite "machine path"                      uses ftp with <.netrc>'
    5216 -     echomsg ':Nwrite "machine id password path"          uses ftp'
    5217 -     echomsg ':Nwrite dav://[user@]machine/path           uses cadaver'
    5218 -     echomsg ':Nwrite fetch://[user@]machine/path         uses fetch'
    5219 -     echomsg ':Nwrite ftp://machine[#port]/path           uses ftp  (autodetects <.netrc>)'
    5220 -     echomsg ':Nwrite rcp://machine/path                  uses rcp'
    5221 -     echomsg ':Nwrite rsync://[user@]machine/path         uses rsync'
    5222 -     echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
    5223 -     echomsg ':Nwrite sftp://[user@]machine/path          uses sftp'
    5224 -     sleep 4
    5225 -     break
    5226 -
    5227 -    elseif match(choice,"^\"") != -1
    5228 -     if match(choice,"\"$") != -1
    5229 -       " case "..."
    5230 -      let choice=strpart(choice,1,strlen(choice)-2)
    5231 -     else
    5232 -      "  case "... ... ..."
    5233 -      let choice      = strpart(choice,1,strlen(choice)-1)
    5234 -      let wholechoice = ""
     5019+
     5020+    if match(choice,"?") == 0
    52355021+     " give help
    52365022+     echomsg 'NetRead Usage:'
     
    52455031+     echomsg ':Nread rcp://[user@]machine/path            uses rcp'
    52465032+     echomsg ':Nread rsync://machine[:port]/path          uses rsync'
    5247 +     echomsg ':Nread scp://[user@]machine[[:#]port]/path  uses scp'
    5248 +     echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
    5249 +     sleep 4
    5250 +     break
    5251  
    5252 -      while match(choice,"\"$") == -1
    5253 -       let wholechoice= wholechoice . " " . choice
    5254 -       let ichoice    = ichoice + 1
    5255 -       if choice > a:0
    5256 +    elseif match(choice,'^"') != -1
    5257 +     " Reconstruct Choice if choice starts with '"'
    5258 +"     call Decho("reconstructing choice")
    5259 +     if match(choice,'"$') != -1
    5260 +      " case "..."
    5261 +      let choice= strpart(choice,1,strlen(choice)-2)
    5262 +     else
    5263 +       "  case "... ... ..."
    5264 +      let choice      = strpart(choice,1,strlen(choice)-1)
    5265 +      let wholechoice = ""
    5266 +
    5267 +      while match(choice,'"$') == -1
    5268 +       let wholechoice = wholechoice . " " . choice
    5269 +       let ichoice     = ichoice + 1
    5270 +       if ichoice > a:0
    5271                 if !exists("g:netrw_quiet")
    5272 -        call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
    5273 +        call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
    5274         endif
    5275 -"        call Dret("netrw#NetWrite")
    5276 +"        call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
    5277          return
    5278         endif
    5279         let choice= a:{ichoice}
    5280 @@ -2047,105 +1765,110 @@
     5033      echomsg ':Nread scp://[user@]machine[[:#]port]/path  uses scp'
     5034      echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
     5035      sleep 4
     5036@@ -1637,7 +1837,7 @@
     5037    endif
     5038    let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
     5039 
     5040-   " Check if NetrwBrowse() should be handling this request
     5041+   " Check whether or not NetrwBrowse() should be handling this request
     5042 "   call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
     5043    if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
     5044 "    call Decho("yes, choice matches '^.*[\/]$'")
     5045@@ -1659,7 +1859,7 @@
     5046 "    call Decho("read via rcp (method #1)")
     5047    " ER: nothing done with g:netrw_uid yet?
     5048    " ER: on Win2K" rcp machine[.user]:file tmpfile
     5049-   " ER: if machine contains '.' adding .user is required (use $USERNAME)
     5050+   " ER: when machine contains '.' adding .user is required (use $USERNAME)
     5051    " ER: the tmpfile is full path: rcp sees C:\... as host C
     5052    if s:netrw_has_nt_rcp == 1
     5053     if exists("g:netrw_uid") &&        ( g:netrw_uid != "" )
     5054@@ -1810,11 +2010,11 @@
     5055      " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
     5056 "     call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
     5057      if exists("g:netrw_http_xcmd")
     5058-"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
     5059-      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
     5060+"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
     5061+      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
     5062      else
     5063-"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1))
     5064-      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.b:netrw_fname,1)
     5065+"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
     5066+      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)
    52815067      endif
     5068      let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
     5069 
     5070@@ -1825,15 +2025,15 @@
     5071      let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
     5072 "     call Decho("netrw_html<".netrw_html.">")
     5073 "     call Decho("netrw_tag <".netrw_tag.">")
     5074-"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1))
     5075-     exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape("http://".g:netrw_machine.netrw_html,1)
     5076+"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
     5077+     exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1)
     5078      let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
     5079 "     call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
     5080      exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
    52825081     endif
    5283     endif
    5284 +
    5285 +"   call Decho("choice<" . choice . ">")
    5286     let ichoice= ichoice + 1
    5287 -"   call Decho("choice<" . choice . "> ichoice=".ichoice)
    5288  
    5289 -   " Determine method of write (ftp, rcp, etc) {{{4
    5290 -   keepj call s:NetrwMethod(choice)
    5291 +   " NetRead: Determine method of read (ftp, rcp, etc) {{{3
    5292 +   call s:NetrwMethod(choice)
    5293     if !exists("b:netrw_method") || b:netrw_method < 0
    5294 -"    call Dfunc("netrw#NetWrite : unsupported method")
    5295 +"    call Dfunc("netrw#NetRead : unsupported method")
    5296 +    return
    5297 +   endif
    5298 +   let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
    5299 +
    5300 +   " Check whether or not NetrwBrowse() should be handling this request
    5301 +"   call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">")
    5302 +   if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
    5303 +"    call Decho("yes, choice matches '^.*[\/]$'")
    5304 +    keepj call s:NetrwBrowse(0,choice)
    5305 +"    call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
    5306      return
    5307     endif
    5308  
    5309 -   " =============
    5310 -   " NetWrite: Perform Protocol-Based Write {{{3
    5311 -   " ============================
    5312 +   " ============
    5313 +   " NetRead: Perform Protocol-Based Read {{{3
    5314 +   " ===========================
    5315     if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
    5316 -    echo "(netrw) Processing your write request..."
    5317 -"    call Decho("(netrw) Processing your write request...")
    5318 +    echo "(netrw) Processing your read request..."
    5319     endif
     5082     let b:netrw_lastfile = choice
     5083-"    call Decho("(NetRead) setl ro")
     5084-    setl ro
     5085+"    call Decho("setl ro")
     5086+    setl ro nomod
    53205087 
    53215088    ".........................................
    5322 -   " NetWrite: (rcp) NetWrite Method #1 {{{3
    5323 -   if  b:netrw_method == 1
    5324 -"    call Decho("write via rcp (method #1)")
    5325 -    if s:netrw_has_nt_rcp == 1
    5326 -     if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    5327 -      let uid_machine = g:netrw_machine .'.'. g:netrw_uid
    5328 -     else
    5329 -      let uid_machine = g:netrw_machine .'.'. $USERNAME
    5330 -     endif
    5331 +   " NetRead: (rcp)  NetRead Method #1 {{{3
    5332 +   if  b:netrw_method == 1 " read with rcp
    5333 +"    call Decho("read via rcp (method #1)")
    5334 +   " ER: nothing done with g:netrw_uid yet?
    5335 +   " ER: on Win2K" rcp machine[.user]:file tmpfile
    5336 +   " ER: when machine contains '.' adding .user is required (use $USERNAME)
    5337 +   " ER: the tmpfile is full path: rcp sees C:\... as host C
    5338 +   if s:netrw_has_nt_rcp == 1
    5339 +    if exists("g:netrw_uid") &&        ( g:netrw_uid != "" )
    5340 +     let uid_machine = g:netrw_machine .'.'. g:netrw_uid
     5089    " NetRead: (dav) NetRead Method #6 {{{3
     5090@@ -1894,7 +2094,7 @@
     5091 "     call Dret("NetRead")
     5092      return
     5093     endif
     5094-    if exists("g:netrw_option") && g:netrw_option == ":https\="
     5095+    if exists("g:netrw_option") && g:netrw_option =~ ":https\="
     5096      let netrw_option= "http"
    53415097     else
    5342 -     if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    5343 -      let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    5344 -     else
    5345 -      let uid_machine = g:netrw_machine
    5346 -     endif
    5347 -    endif
    5348 -"    call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
    5349 -    exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1)
    5350 -    let b:netrw_lastfile = choice
    5351 -
    5352 -   ".........................................
    5353 -   " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
    5354 -   elseif b:netrw_method == 2
    5355 -"    call Decho("write via ftp+.netrc (method #2)")
    5356 -    let netrw_fname = b:netrw_fname
    5357 -
    5358 -    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    5359 -    let bhkeep      = &l:bh
    5360 -    let curbuf      = bufnr("%")
    5361 -    setl bh=hide
    5362 -    keepalt enew
    5363 -
    5364 -"    call Decho("filter input window#".winnr())
    5365 -    setl ff=unix
    5366 -    keepj put =g:netrw_ftpmode
    5367 -"    call Decho("filter input: ".getline('$'))
    5368 -    if exists("g:netrw_ftpextracmd")
    5369 -     keepj put =g:netrw_ftpextracmd
    5370 -"     call Decho("filter input: ".getline("$"))
    5371 +     " Any way needed it machine contains a '.'
    5372 +     let uid_machine = g:netrw_machine .'.'. $USERNAME
    5373      endif
    5374 -    keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
    5375 -"    call Decho("filter input: ".getline("$"))
    5376 -    if exists("g:netrw_port") && g:netrw_port != ""
    5377 -"     call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
    5378 -     exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
    5379 +   else
    5380 +    if exists("g:netrw_uid") &&        ( g:netrw_uid != "" )
    5381 +     let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    5382      else
    5383 -"     call Decho("filter input window#".winnr())
    5384 -"     call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
    5385 -     exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
    5386 -    endif
    5387 -    " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    5388 -    if getline(1) !~ "^$"
    5389 -     if !exists("g:netrw_quiet")
    5390 -      keepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
    5391 -     endif
    5392 -     let mod=1
    5393 +     let uid_machine = g:netrw_machine
    5394      endif
    5395 +   endif
    5396 +"   call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    5397 +   exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(uid_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    5398 +   let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5399 +   let b:netrw_lastfile = choice
    5400  
    5401 -    " remove enew buffer (quietly)
    5402 -    let filtbuf= bufnr("%")
    5403 -    exe curbuf."b!"
    5404 -    let &l:bh            = bhkeep
    5405 -    exe filtbuf."bw!"
    5406 -
    5407 -    let b:netrw_lastfile = choice
    5408 +   ".........................................
    5409 +   " NetRead: (ftp + <.netrc>)  NetRead Method #2 {{{3
    5410 +   elseif b:netrw_method  == 2         " read with ftp + <.netrc>
    5411 +"     call Decho("read via ftp+.netrc (method #2)")
    5412 +     let netrw_fname= b:netrw_fname
    5413 +     keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
    5414 +     let filtbuf= bufnr("%")
    5415 +     setl ff=unix
    5416 +     keepj put =g:netrw_ftpmode
    5417 +"     call Decho("filter input: ".getline(line("$")))
    5418 +     if exists("g:netrw_ftpextracmd")
    5419 +      keepj put =g:netrw_ftpextracmd
    5420 +"      call Decho("filter input: ".getline(line("$")))
    5421 +     endif
    5422 +     call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
    5423 +"     call Decho("filter input: ".getline(line("$")))
    5424 +     if exists("g:netrw_port") && g:netrw_port != ""
    5425 +"      call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
    5426 +      exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
    5427 +     else
    5428 +"      call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
    5429 +      exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
    5430 +     endif
    5431 +     " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    5432 +     if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
    5433 +      let debugkeep = &debug
    5434 +      setl debug=msg
    5435 +      keepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
    5436 +      let &debug    = debugkeep
    5437 +     endif
    5438 +     call s:SaveBufVars()
    5439 +     bd!
    5440 +     if bufname("%") == "" && getline("$") == "" && line('$') == 1
    5441 +      " needed when one sources a file in a nolbl setting window via ftp
    5442 +      q!
    5443 +     endif
    5444 +     call s:RestoreBufVars()
    5445 +     let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5446 +     let b:netrw_lastfile = choice
     5098      let netrw_option= "ftp"
     5099@@ -1911,8 +2111,8 @@
     5100 
     5101     let result         = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
     5102     let b:netrw_lastfile = choice
     5103-"    call Decho("(NetRead) setl ro")
     5104-    setl ro
     5105+"    call Decho("setl ro")
     5106+    setl ro nomod
    54475107 
    54485108    ".........................................
    5449 -   " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
    5450 -   elseif b:netrw_method == 3
    5451 -    " Construct execution string (three or more lines) which will be passed through filter
    5452 +   " NetRead: (ftp + machine,id,passwd,filename)  NetRead Method #3 {{{3
    5453 +   elseif b:netrw_method == 3          " read with ftp + machine, id, passwd, and fname
    5454 +    " Construct execution string (four lines) which will be passed through filter
    5455  "    call Decho("read via ftp+mipf (method #3)")
    5456 -    let netrw_fname = b:netrw_fname
    5457 -    let bhkeep      = &l:bh
    5458 -
    5459 -    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    5460 -    let curbuf      = bufnr("%")
    5461 -    setl bh=hide
    5462 -    keepalt enew
    5463 +    let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    5464 +    keepj call s:SaveBufVars()|new|keepj call s:RestoreBufVars()
    5465 +    let filtbuf= bufnr("%")
    5466      setl ff=unix
    5467 -
    5468      if exists("g:netrw_port") && g:netrw_port != ""
    5469       keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    5470  "     call Decho("filter input: ".getline('.'))
    5471 @@ -2153,29 +1876,31 @@
    5472       keepj put ='open '.g:netrw_machine
    5473  "     call Decho("filter input: ".getline('.'))
    5474      endif
    5475 +
    5476      if exists("g:netrw_uid") && g:netrw_uid != ""
    5477       if exists("g:netrw_ftp") && g:netrw_ftp == 1
    5478        keepj put =g:netrw_uid
    5479 -"      call Decho("filter input: ".getline('.'))
    5480 -      if exists("s:netrw_passwd") && s:netrw_passwd != ""
    5481 +"       call Decho("filter input: ".getline('.'))
    5482 +      if exists("s:netrw_passwd")
    5483         keepj put ='\"'.s:netrw_passwd.'\"'
    5484        endif
    5485  "      call Decho("filter input: ".getline('.'))
    5486 -     elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
    5487 +     elseif exists("s:netrw_passwd")
    5488        keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
    5489  "      call Decho("filter input: ".getline('.'))
    5490       endif
    5491      endif
    5492 -    keepj put =g:netrw_ftpmode
    5493 -"    call Decho("filter input: ".getline('$'))
    5494 +
    5495 +    if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
    5496 +     keepj put =g:netrw_ftpmode
    5497 +"     call Decho("filter input: ".getline('.'))
    5498 +    endif
    5499      if exists("g:netrw_ftpextracmd")
    5500       keepj put =g:netrw_ftpextracmd
    5501 -"     call Decho("filter input: ".getline("$"))
    5502 +"     call Decho("filter input: ".getline('.'))
    5503      endif
    5504 -    keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
    5505 +    keepj put ='get \"'.netrw_fname.'\" '.tmpfile
    5506  "    call Decho("filter input: ".getline('.'))
    5507 -    " save choice/id/password for future use
    5508 -    let b:netrw_lastfile = choice
    5509  
    5510      " perform ftp:
    5511      " -i       : turns off interactive prompting from ftp
    5512 @@ -2186,3113 +1911,3829 @@
    5513      exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
    5514      " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    5515      if getline(1) !~ "^$"
    5516 -     if  !exists("g:netrw_quiet")
    5517 -      call netrw#ErrorMsg(s:ERROR,getline(1),15)
    5518 +"     call Decho("error<".getline(1).">")
    5519 +     if !exists("g:netrw_quiet")
    5520 +      call netrw#ErrorMsg(s:ERROR,getline(1),5)
    5521       endif
    5522 -     let mod=1
    5523      endif
    5524 -
    5525 -    " remove enew buffer (quietly)
    5526 -    let filtbuf= bufnr("%")
    5527 -    exe curbuf."b!"
    5528 -    let &l:bh= bhkeep
    5529 -    exe filtbuf."bw!"
    5530 +    call s:SaveBufVars()|bd!|call s:RestoreBufVars()
    5531 +    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5532 +    let b:netrw_lastfile = choice
    5533  
    5534     ".........................................
    5535 -   " NetWrite: (scp) NetWrite Method #4 {{{3
    5536 -   elseif     b:netrw_method == 4
    5537 -"    call Decho("write via scp (method #4)")
    5538 +   " NetRead: (scp) NetRead Method #4 {{{3
    5539 +   elseif     b:netrw_method  == 4     " read with scp
    5540 +"    call Decho("read via scp (method #4)")
    5541      if exists("g:netrw_port") && g:netrw_port != ""
    5542 -     let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
    5543 +     let useport= " ".g:netrw_scpport." ".g:netrw_port
    5544      else
    5545       let useport= ""
    5546      endif
    5547 -"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
    5548 -    exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
    5549 +"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    5550 +    exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    5551 +    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5552      let b:netrw_lastfile = choice
    5553  
    5554     ".........................................
    5555 -   " NetWrite: (http) NetWrite Method #5 {{{3
    5556 -   elseif     b:netrw_method == 5
    5557 -"    call Decho("write via http (method #5)")
     5109    " NetRead: (sftp) NetRead Method #9 {{{3
     5110@@ -1978,7 +2178,7 @@
     5111    exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
     5112   elseif g:netrw_cygwin
     5113    " write (selected portion of) file to temporary
     5114-   let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','')
     5115+   let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
     5116 "   call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
     5117    exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
     5118   else
     5119@@ -1988,7 +2188,7 @@
     5120   endif
     5121 
     5122   if curbufname == ""
     5123-   " if the file is [No Name], and one attempts to Nwrite it, the buffer takes
     5124+   " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
     5125    " on the temporary file's name.  Deletion of the temporary file during
     5126    " cleanup then causes an error message.
     5127    0file!
     5128@@ -2006,7 +2206,7 @@
     5129    else
     5130     exe "let choice= a:" . ichoice
     5131 
     5132-    " Reconstruct Choice if choice starts with '"'
     5133+    " Reconstruct Choice when choice starts with '"'
     5134     if match(choice,"?") == 0
     5135      echomsg 'NetWrite Usage:"'
     5136      echomsg ':Nwrite machine:path                        uses rcp'
     5137@@ -2215,8 +2415,13 @@
     5138    " NetWrite: (http) NetWrite Method #5 {{{3
     5139    elseif     b:netrw_method == 5
     5140 "    call Decho("write via http (method #5)")
    55585141-    if !exists("g:netrw_quiet")
    55595142-     call netrw#ErrorMsg(s:ERROR,"currently <netrw.vim> does not support writing using http:",16)
    5560 -    endif
    5561 -
    5562 -   ".........................................
    5563 -   " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
    5564 -   elseif     b:netrw_method == 6
    5565 -"    call Decho("write via cadaver (method #6)")
    5566 -
    5567 -    " Construct execution string (four lines) which will be passed through filter
    5568 -    let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
    5569 -    let bhkeep      = &l:bh
    5570 +   " NetRead: (http) NetRead Method #5 (wget) {{{3
    5571 +   elseif     b:netrw_method  == 5
    5572 +"    call Decho("read via http (method #5)")
    5573 +    if g:netrw_http_cmd == ""
    5574 +     if !exists("g:netrw_quiet")
    5575 +      call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
    5576 +     endif
    5577 +"     call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
    5578 +     return
    5579 +    endif
    5580  
    5581 -    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    5582 -    let curbuf      = bufnr("%")
    5583 -    setl bh=hide
    5584 -    keepalt enew
    5585 +    if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
    5586 +     " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
    5587 +"     call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)")
    5588 +     if exists("g:netrw_http_xcmd")
    5589 +"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1))
    5590 +      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".shellescape(tmpfile,1)
    5591 +     else
    5592 +"      call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
    5593 +      exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)
    5594 +     endif
    5595 +     let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5596  
    5597 -    setl ff=unix
    5598 -    if exists("g:netrw_port") && g:netrw_port != ""
    5599 -     keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    5600      else
    5601 -     keepj put ='open '.g:netrw_machine
    5602 -    endif
    5603 -    if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
    5604 -     keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
    5605 +     " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
    5606 +"     call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)")
    5607 +     let netrw_html= substitute(b:netrw_fname,"#.*$","","")
    5608 +     let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
    5609 +"     call Decho("netrw_html<".netrw_html.">")
    5610 +"     call Decho("netrw_tag <".netrw_tag.">")
    5611 +"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
    5612 +     exe s:netrw_silentxfer."!".g:netrw_http_cmd." ".shellescape(tmpfile,1)." ".shellescape(b:netrw_http."://".g:netrw_machine.netrw_html,1)
    5613 +     let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5614 +"     call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/')
    5615 +     exe 'keepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
    5616      endif
    5617 -    keepj put ='put '.tmpfile.' '.netrw_fname
    5618 +    let b:netrw_lastfile = choice
    5619 +"    call Decho("setl ro")
    5620 +    setl ro
    5621  
    5622 -    " perform cadaver operation:
    5623 -    keepj norm! 1Gdd
    5624 -"    call Decho("executing: %!".g:netrw_dav_cmd)
    5625 -    exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
    5626 +   ".........................................
    5627 +   " NetRead: (dav) NetRead Method #6 {{{3
    5628 +   elseif     b:netrw_method  == 6
    5629 +"    call Decho("read via cadaver (method #6)")
    5630  
    5631 -    " remove enew buffer (quietly)
    5632 -    let filtbuf= bufnr("%")
    5633 -    exe curbuf."b!"
    5634 -    let &l:bh            = bhkeep
    5635 -    exe filtbuf."bw!"
    5636 +    if !executable(g:netrw_dav_cmd)
    5637 +     call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
    5638 +"     call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
    5639 +     return
    5640 +    endif
    5641 +    if g:netrw_dav_cmd =~ "curl"
    5642 +"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1))
    5643 +     exe s:netrw_silentxfer."!".g:netrw_dav_cmd." ".shellescape("dav://".g:netrw_machine.b:netrw_fname,1)." ".shellescape(tmpfile,1)
    5644 +    else
    5645 +     " Construct execution string (four lines) which will be passed through filter
    5646 +     let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    5647 +     new
    5648 +     setl ff=unix
    5649 +     if exists("g:netrw_port") && g:netrw_port != ""
    5650 +      keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    5651 +     else
    5652 +      keepj put ='open '.g:netrw_machine
    5653 +     endif
    5654 +     if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
    5655 +      keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
    5656 +     endif
    5657 +     keepj put ='get '.netrw_fname.' '.tmpfile
    5658 +     keepj put ='quit'
    5659  
    5660 +     " perform cadaver operation:
    5661 +     keepj norm! 1Gdd
    5662 +"    call Decho("executing: %!".g:netrw_dav_cmd)
    5663 +     exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
    5664 +     bd!
    5665 +    endif
    5666 +    let result           = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5667      let b:netrw_lastfile = choice
    5668  
    5669     ".........................................
    5670 -   " NetWrite: (rsync) NetWrite Method #7 {{{3
    5671 -   elseif     b:netrw_method == 7
    5672 -"    call Decho("write via rsync (method #7)")
    5673 -"    call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
    5674 -    exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
    5675 +   " NetRead: (rsync) NetRead Method #7 {{{3
    5676 +   elseif     b:netrw_method  == 7
    5677 +"    call Decho("read via rsync (method #7)")
    5678 +"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1))
    5679 +    exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".shellescape(tmpfile,1)
    5680 +    let result          = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
    5681      let b:netrw_lastfile = choice
    5682  
    5683     ".........................................
    5684 -   " NetWrite: (sftp) NetWrite Method #9 {{{3
    5685 -   elseif     b:netrw_method == 9
    5686 -"    call Decho("write via sftp (method #9)")
    5687 -    let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    5688 -    if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    5689 -     let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    5690 +   " NetRead: (fetch) NetRead Method #8 {{{3
    5691 +   "    fetch://[user@]host[:http]/path
    5692 +   elseif     b:netrw_method  == 8
    5693 +"    call Decho("read via fetch (method #8)")
    5694 +    if g:netrw_fetch_cmd == ""
    5695 +     if !exists("g:netrw_quiet")
    5696 +      keepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
    5697 +     endif
    5698 +"     call Dret("NetRead")
    5699 +     return
    5700 +    endif
    5701 +    if exists("g:netrw_option") && g:netrw_option =~ ":https\="
    5702 +     let netrw_option= "http"
    5703      else
    5704 -     let uid_machine = g:netrw_machine
    5705 +     let netrw_option= "ftp"
    5706      endif
    5707 +"    call Decho("read via fetch for ".netrw_option)
    5708  
    5709 -    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    5710 -    let bhkeep = &l:bh
    5711 -    let curbuf = bufnr("%")
    5712 -    setl bh=hide
    5713 -    keepalt enew
    5714 +    if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
    5715 +"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
    5716 +     exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1)
    5717 +    else
    5718 +"     call Decho("exe ".s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
    5719 +     exe s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".shellescape(tmpfile,1)." ".shellescape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)
    5720 +    endif
    5721  
    5722 -    setl ff=unix
    5723 -    call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
    5724 -"    call Decho("filter input: ".getline('.'))
    5725 -"    call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
    5726 -    let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
    5727 -    exe s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1)
    5728 -    let filtbuf= bufnr("%")
    5729 -    exe curbuf."b!"
    5730 -    let &l:bh            = bhkeep
    5731 -    exe filtbuf."bw!"
    5732 +    let result         = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
    5733      let b:netrw_lastfile = choice
    5734 +"    call Decho("setl ro")
    5735 +    setl ro
    5736  
    5737     ".........................................
    5738 -   " NetWrite: Complain {{{3
    5739 +   " NetRead: (sftp) NetRead Method #9 {{{3
    5740 +   elseif     b:netrw_method  == 9
    5741 +"    call Decho("read via sftp (method #9)")
    5742 +"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
    5743 +    exe s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile
    5744 +    let result         = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
    5745 +    let b:netrw_lastfile = choice
    5746 +
    5747 +   ".........................................
    5748 +   " NetRead: Complain {{{3
    5749     else
    5750 -    call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
    5751 -    let leavemod= 1
    5752 +    call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
    5753     endif
    5754    endwhile
    5755  
    5756 -  " NetWrite: Cleanup: {{{3
    5757 -"  call Decho("cleanup")
    5758 -  if s:FileReadable(tmpfile)
    5759 -"   call Decho("tmpfile<".tmpfile."> readable, will now delete it")
    5760 -   call s:NetrwDelete(tmpfile)
    5761 +  " NetRead: cleanup {{{3
    5762 +  if exists("b:netrw_method")
    5763 +"   call Decho("cleanup b:netrw_method and b:netrw_fname")
    5764 +   unlet b:netrw_method
    5765 +   unlet b:netrw_fname
    5766    endif
    5767 -  call s:NetrwOptionRestore("w:")
    5768 -
    5769 -  if a:firstline == 1 && a:lastline == line("$")
    5770 -   " restore modifiability; usually equivalent to set nomod
    5771 -   let &mod= mod
    5772 -"   call Decho("(NetWrite)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    5773 -  elseif !exists("leavemod")
    5774 -   " indicate that the buffer has not been modified since last written
    5775 -"   call Decho("(NetWrite) set nomod")
    5776 -   set nomod
    5777 -"   call Decho("(NetWrite)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    5778 +  if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
    5779 +"   call Decho("cleanup by deleting tmpfile<".tmpfile.">")
    5780 +   keepj call s:NetrwDelete(tmpfile)
    5781    endif
    5782 +  keepj call s:NetrwOptionRestore("w:")
    5783  
    5784 -"  call Dret("netrw#NetWrite")
    5785 +"  call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
    5786  endfun
    5787  
    5788 -" ---------------------------------------------------------------------
    5789 -" netrw#NetSource: source a remotely hosted vim script {{{2
    5790 -" uses NetRead to get a copy of the file into a temporarily file,
    5791 -"              then sources that file,
    5792 -"              then removes that file.
    5793 -fun! netrw#NetSource(...)
    5794 -"  call Dfunc("netrw#NetSource() a:0=".a:0)
    5795 -  if a:0 > 0 && a:1 == '?'
    5796 -   " give help
    5797 -   echomsg 'NetSource Usage:'
    5798 -   echomsg ':Nsource dav://machine[:port]/path            uses cadaver'
    5799 -   echomsg ':Nsource fetch://machine/path                 uses fetch'
    5800 -   echomsg ':Nsource ftp://[user@]machine[:port]/path     uses ftp   autodetects <.netrc>'
    5801 -   echomsg ':Nsource http[s]://[user@]machine/path        uses http  wget'
    5802 -   echomsg ':Nsource rcp://[user@]machine/path            uses rcp'
    5803 -   echomsg ':Nsource rsync://machine[:port]/path          uses rsync'
    5804 -   echomsg ':Nsource scp://[user@]machine[[:#]port]/path  uses scp'
    5805 -   echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
    5806 -   sleep 4
    5807 -  else
    5808 -   let i= 1
    5809 -   while i <= a:0
    5810 -    call netrw#NetRead(3,a:{i})
    5811 -"    call Decho("(netrw#NetSource) s:netread_tmpfile<".s:netrw_tmpfile.">")
    5812 -    if s:FileReadable(s:netrw_tmpfile)
    5813 -"     call Decho("(netrw#NetSource) exe so ".fnameescape(s:netrw_tmpfile))
    5814 -     exe "so ".fnameescape(s:netrw_tmpfile)
    5815 -"     call Decho("(netrw#NetSource) delete(".s:netrw_tmpfile.")")
    5816 -     call delete(s:netrw_tmpfile)
    5817 -     unlet s:netrw_tmpfile
    5818 -    else
    5819 -     call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
    5820 -    endif
    5821 -    let i= i + 1
    5822 -   endwhile
    5823 -  endif
    5824 -"  call Dret("netrw#NetSource")
    5825 -endfun
    5826 +" ------------------------------------------------------------------------
    5827 +" netrw#NetWrite: responsible for writing a file over the net {{{2
    5828 +fun! netrw#NetWrite(...) range
    5829 +"  call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
    5830  
    5831 -" ===========================================
    5832 -" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
    5833 -"    readcmd == %r : replace buffer with newly read file
    5834 -"            == 0r : read file at top of buffer
    5835 -"            == r  : read file after current line
    5836 -"            == t  : leave file in temporary form (ie. don't read into buffer)
    5837 -fun! s:NetrwGetFile(readcmd, tfile, method)
    5838 -"  call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
    5839 +  " NetWrite: option handling {{{3
    5840 +  let mod= 0
    5841 +  call s:NetrwOptionSave("w:")
    5842 +  call s:NetrwSafeOptions()
    5843  
    5844 -  " readcmd=='t': simply do nothing
    5845 -  if a:readcmd == 't'
    5846 -"   call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    5847 -"   call Dret("NetrwGetFile : skip read of <".a:tfile.">")
    5848 +  " NetWrite: Get Temporary Filename {{{3
    5849 +  let tmpfile= s:GetTempfile("")
    5850 +  if tmpfile == ""
    5851 +"   call Dret("netrw#NetWrite : unable to get a tempfile!")
    5852     return
    5853    endif
    5854  
    5855 -  " get name of remote filename (ie. url and all)
    5856 -  let rfile= bufname("%")
    5857 -"  call Decho("rfile<".rfile.">")
    5858 -
    5859 -  if exists("*NetReadFixup")
    5860 -   " for the use of NetReadFixup (not otherwise used internally)
    5861 -   let line2= line("$")
    5862 +  if a:0 == 0
    5863 +   let ichoice = 0
    5864 +  else
    5865 +   let ichoice = 1
    5866    endif
    5867  
    5868 -  if a:readcmd[0] == '%'
    5869 -  " get file into buffer
    5870 -"   call Decho("get file into buffer")
    5871 -
    5872 -   " rename the current buffer to the temp file (ie. tfile)
    5873 -   if g:netrw_cygwin
    5874 -    let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','')
    5875 -   else
    5876 -    let tfile= a:tfile
    5877 -   endif
    5878 -"   call Decho("exe sil! keepalt file ".fnameescape(tfile))
    5879 -   exe "sil! keepalt file ".fnameescape(tfile)
    5880 -
    5881 -   " edit temporary file (ie. read the temporary file in)
    5882 -   if     rfile =~ '\.zip$'
    5883 -"    call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
    5884 -    call zip#Browse(tfile)
    5885 -   elseif rfile =~ '\.tar$'
    5886 -"    call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
    5887 -    call tar#Browse(tfile)
    5888 -   elseif rfile =~ '\.tar\.gz$'
    5889 -"    call Decho("handling remote gzip-compressed tar file")
    5890 -    call tar#Browse(tfile)
    5891 -   elseif rfile =~ '\.tar\.bz2$'
    5892 -"    call Decho("handling remote bz2-compressed tar file")
    5893 -    call tar#Browse(tfile)
    5894 -   elseif rfile =~ '\.tar\.xz$'
    5895 -"    call Decho("handling remote xz-compressed tar file")
    5896 -    call tar#Browse(tfile)
    5897 -   elseif rfile =~ '\.txz$'
    5898 -"    call Decho("handling remote xz-compressed tar file (.txz)")
    5899 -    call tar#Browse(tfile)
    5900 -   else
    5901 -"    call Decho("edit temporary file")
    5902 -    e!
    5903 -   endif
    5904 -
    5905 -   " rename buffer back to remote filename
    5906 -"   call Decho("exe sil! keepalt file ".fnameescape(rfile))
    5907 -   exe "sil! keepj keepalt file ".fnameescape(rfile)
    5908 -
    5909 -   " Detect filetype of local version of remote file.
    5910 -   " Note that isk must not include a "/" for scripts.vim
    5911 -   " to process this detection correctly.
    5912 -"   call Decho("detect filetype of local version of remote file")
    5913 -   let iskkeep= &l:isk
    5914 -   setl isk-=/
    5915 -   let &l:isk= iskkeep
    5916 -"   call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
    5917 -   let line1 = 1
    5918 -   let line2 = line("$")
    5919 -
    5920 -  elseif s:FileReadable(a:tfile)
    5921 -   " read file after current line
    5922 -"   call Decho("read file<".a:tfile."> after current line")
    5923 -   let curline = line(".")
    5924 -   let lastline= line("$")
    5925 -"   call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile).">  line#".curline)
    5926 -   exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
    5927 -   let line1= curline + 1
    5928 -   let line2= line("$") - lastline + 1
    5929 -
    5930 +  let curbufname= expand("%")
    5931 +"  call Decho("curbufname<".curbufname.">")
    5932 +  if &binary
    5933 +   " For binary writes, always write entire file.
    5934 +   " (line numbers don't really make sense for that).
    5935 +   " Also supports the writing of tar and zip files.
    5936 +"   call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
    5937 +   exe "sil keepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
    5938 +  elseif g:netrw_cygwin
    5939 +   " write (selected portion of) file to temporary
    5940 +   let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
    5941 +"   call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile))
    5942 +   exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
    5943    else
    5944 -   " not readable
    5945 -"   call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    5946 -"   call Decho("tfile<".a:tfile."> not readable")
    5947 -   keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
    5948 -"   call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
    5949 -   return
    5950 +   " write (selected portion of) file to temporary
    5951 +"   call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile))
    5952 +   exe "sil keepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
    5953    endif
    5954  
    5955 -  " User-provided (ie. optional) fix-it-up command
    5956 -  if exists("*NetReadFixup")
    5957 -"   call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
    5958 -   keepj call NetReadFixup(a:method, line1, line2)
    5959 -"  else " Decho
    5960 -"   call Decho("NetReadFixup() not called, doesn't exist  (line1=".line1." line2=".line2.")")
    5961 +  if curbufname == ""
    5962 +   " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
    5963 +   " on the temporary file's name.  Deletion of the temporary file during
    5964 +   " cleanup then causes an error message.
    5965 +   0file!
    5966    endif
    5967  
    5968 -  if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
    5969 -   " update the Buffers menu
    5970 -   keepj call s:UpdateBuffersMenu()
    5971 -  endif
    5972 +  " NetWrite: while choice loop: {{{3
    5973 +  while ichoice <= a:0
    5974  
    5975 -"  call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
    5976 +   " Process arguments: {{{4
    5977 +   " attempt to repeat with previous host-file-etc
    5978 +   if exists("b:netrw_lastfile") && a:0 == 0
    5979 +"    call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">")
    5980 +    let choice = b:netrw_lastfile
    5981 +    let ichoice= ichoice + 1
    5982 +   else
    5983 +    exe "let choice= a:" . ichoice
    5984  
    5985 - " make sure file is being displayed
    5986 -"  redraw!
    5987 +    " Reconstruct Choice when choice starts with '"'
    5988 +    if match(choice,"?") == 0
    5989 +     echomsg 'NetWrite Usage:"'
    5990 +     echomsg ':Nwrite machine:path                        uses rcp'
    5991 +     echomsg ':Nwrite "machine path"                      uses ftp with <.netrc>'
    5992 +     echomsg ':Nwrite "machine id password path"          uses ftp'
    5993 +     echomsg ':Nwrite dav://[user@]machine/path           uses cadaver'
    5994 +     echomsg ':Nwrite fetch://[user@]machine/path         uses fetch'
    5995 +     echomsg ':Nwrite ftp://machine[#port]/path           uses ftp  (autodetects <.netrc>)'
    5996 +     echomsg ':Nwrite rcp://machine/path                  uses rcp'
    5997 +     echomsg ':Nwrite rsync://[user@]machine/path         uses rsync'
    5998 +     echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
    5999 +     echomsg ':Nwrite sftp://[user@]machine/path          uses sftp'
    6000 +     sleep 4
    6001 +     break
    6002  
    6003 -"  call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    6004 -"  call Dret("NetrwGetFile")
    6005 -endfun
    6006 +    elseif match(choice,"^\"") != -1
    6007 +     if match(choice,"\"$") != -1
    6008 +       " case "..."
    6009 +      let choice=strpart(choice,1,strlen(choice)-2)
    6010 +     else
    6011 +      "  case "... ... ..."
    6012 +      let choice      = strpart(choice,1,strlen(choice)-1)
    6013 +      let wholechoice = ""
    6014  
    6015 -" ------------------------------------------------------------------------
    6016 -" s:NetrwMethod:  determine method of transfer {{{2
    6017 -" Input:
    6018 -"   choice = url   [protocol:]//[userid@]hostname[:port]/[path-to-file]
    6019 -" Output:
    6020 -"  b:netrw_method= 1: rcp                                             
    6021 -"                  2: ftp + <.netrc>                                 
    6022 -"                 3: ftp + machine, id, password, and [path]filename
    6023 -"                 4: scp                                             
    6024 -"                 5: http[s] (wget)                                     
    6025 -"                 6: dav
    6026 -"                 7: rsync                                           
    6027 -"                 8: fetch                                           
    6028 -"                 9: sftp                                           
    6029 -"  g:netrw_machine= hostname
    6030 -"  b:netrw_fname  = filename
    6031 -"  g:netrw_port   = optional port number (for ftp)
    6032 -"  g:netrw_choice = copy of input url (choice)
    6033 -fun! s:NetrwMethod(choice)
    6034 -"   call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
    6035 +      while match(choice,"\"$") == -1
    6036 +       let wholechoice= wholechoice . " " . choice
    6037 +       let ichoice    = ichoice + 1
    6038 +       if choice > a:0
    6039 +               if !exists("g:netrw_quiet")
    6040 +        call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
    6041 +       endif
    6042 +"        call Dret("netrw#NetWrite")
    6043 +        return
    6044 +       endif
    6045 +       let choice= a:{ichoice}
    6046 +      endwhile
    6047 +      let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
    6048 +     endif
    6049 +    endif
    6050 +   endif
    6051 +   let ichoice= ichoice + 1
    6052 +"   call Decho("choice<" . choice . "> ichoice=".ichoice)
    6053  
    6054 -   " sanity check: choice should have at least three slashes in it
    6055 -   if strlen(substitute(a:choice,'[^/]','','g')) < 3
    6056 -    call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
    6057 -    let b:netrw_method = -1
    6058 -"    call Dret("NetrwMethod : incorrect url format<".a:choice.">")
    6059 +   " Determine method of write (ftp, rcp, etc) {{{4
    6060 +   keepj call s:NetrwMethod(choice)
    6061 +   if !exists("b:netrw_method") || b:netrw_method < 0
    6062 +"    call Dfunc("netrw#NetWrite : unsupported method")
    6063      return
    6064     endif
    6065  
    6066 -   " record current g:netrw_machine, if any
    6067 -   " curmachine used if protocol == ftp and no .netrc
    6068 -   if exists("g:netrw_machine")
    6069 -    let curmachine= g:netrw_machine
    6070 -"    call Decho("curmachine<".curmachine.">")
    6071 -   else
    6072 -    let curmachine= "N O T A HOST"
    6073 -   endif
    6074 -   if exists("g:netrw_port")
    6075 -    let netrw_port= g:netrw_port
    6076 +   " =============
    6077 +   " NetWrite: Perform Protocol-Based Write {{{3
    6078 +   " ============================
    6079 +   if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
    6080 +    echo "(netrw) Processing your write request..."
    6081 +"    call Decho("(netrw) Processing your write request...")
    6082     endif
    6083  
    6084 -   " insure that netrw_ftp_cmd starts off every method determination
    6085 -   " with the current g:netrw_ftp_cmd
    6086 -   let s:netrw_ftp_cmd= g:netrw_ftp_cmd
    6087 +   ".........................................
    6088 +   " NetWrite: (rcp) NetWrite Method #1 {{{3
    6089 +   if  b:netrw_method == 1
    6090 +"    call Decho("write via rcp (method #1)")
    6091 +    if s:netrw_has_nt_rcp == 1
    6092 +     if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    6093 +      let uid_machine = g:netrw_machine .'.'. g:netrw_uid
    6094 +     else
    6095 +      let uid_machine = g:netrw_machine .'.'. $USERNAME
    6096 +     endif
    6097 +    else
    6098 +     if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    6099 +      let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    6100 +     else
    6101 +      let uid_machine = g:netrw_machine
    6102 +     endif
    6103 +    endif
    6104 +"    call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1))
    6105 +    exe s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".shellescape(tmpfile,1)." ".shellescape(uid_machine.":".b:netrw_fname,1)
    6106 +    let b:netrw_lastfile = choice
    6107  
    6108 -  " initialization
    6109 -  let b:netrw_method  = 0
    6110 -  let g:netrw_machine = ""
    6111 -  let b:netrw_fname   = ""
    6112 -  let g:netrw_port    = ""
    6113 -  let g:netrw_choice  = a:choice
    6114 +   ".........................................
    6115 +   " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
    6116 +   elseif b:netrw_method == 2
    6117 +"    call Decho("write via ftp+.netrc (method #2)")
    6118 +    let netrw_fname = b:netrw_fname
    6119  
    6120 -  " Patterns:
    6121 -  " mipf     : a:machine a:id password filename             Use ftp
    6122 -  " mf     : a:machine filename                     Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
    6123 -  " ftpurm   : ftp://[user@]host[[#:]port]/filename  Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
    6124 -  " rcpurm   : rcp://[user@]host/filename           Use rcp
    6125 -  " rcphf    : [user@]host:filename                 Use rcp
    6126 -  " scpurm   : scp://[user@]host[[#:]port]/filename  Use scp
    6127 -  " httpurm  : http[s]://[user@]host/filename       Use wget
    6128 -  " davurm   : dav[s]://host[:port]/path             Use cadaver/curl
    6129 -  " rsyncurm : rsync://host[:port]/path              Use rsync
    6130 -  " fetchurm : fetch://[user@]host[:http]/filename   Use fetch (defaults to ftp, override for http)
    6131 -  " sftpurm  : sftp://[user@]host/filename  Use scp
    6132 -  let mipf     = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
    6133 -  let mf       = '^\(\S\+\)\s\+\(\S\+\)$'
    6134 -"  let ftpurm   = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
    6135 -"  let rcpurm   = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
    6136 -"  let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
    6137 -  let ftpurm   = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
    6138 -  let rcpurm   = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
    6139 -  let rcphf    = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
    6140 -  let scpurm   = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
    6141 -  let httpurm  = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
    6142 -  let davurm   = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
    6143 -  let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
    6144 -  let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
    6145 -  let sftpurm  = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
    6146 +    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    6147 +    let bhkeep      = &l:bh
    6148 +    let curbuf      = bufnr("%")
    6149 +    setl bh=hide
    6150 +    keepalt enew
    6151  
    6152 -"  call Decho("determine method:")
    6153 -  " Determine Method
    6154 -  " Method#1: rcp://user@hostname/...path-to-file {{{3
    6155 -  if match(a:choice,rcpurm) == 0
    6156 -"   call Decho("rcp://...")
    6157 -   let b:netrw_method  = 1
    6158 -   let userid          = substitute(a:choice,rcpurm,'\1',"")
    6159 -   let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
    6160 -   let b:netrw_fname   = substitute(a:choice,rcpurm,'\3',"")
    6161 -   if userid != ""
    6162 -    let g:netrw_uid= userid
    6163 -   endif
    6164 -
    6165 -  " Method#4: scp://user@hostname/...path-to-file {{{3
    6166 -  elseif match(a:choice,scpurm) == 0
    6167 -"   call Decho("scp://...")
    6168 -   let b:netrw_method  = 4
    6169 -   let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
    6170 -   let g:netrw_port    = substitute(a:choice,scpurm,'\2',"")
    6171 -   let b:netrw_fname   = substitute(a:choice,scpurm,'\3',"")
    6172 +"    call Decho("filter input window#".winnr())
    6173 +    setl ff=unix
    6174 +    keepj put =g:netrw_ftpmode
    6175 +"    call Decho("filter input: ".getline('$'))
    6176 +    if exists("g:netrw_ftpextracmd")
    6177 +     keepj put =g:netrw_ftpextracmd
    6178 +"     call Decho("filter input: ".getline("$"))
    6179 +    endif
    6180 +    keepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
    6181 +"    call Decho("filter input: ".getline("$"))
    6182 +    if exists("g:netrw_port") && g:netrw_port != ""
    6183 +"     call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1))
    6184 +     exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)." ".shellescape(g:netrw_port,1)
    6185 +    else
    6186 +"     call Decho("filter input window#".winnr())
    6187 +"     call Decho("executing: %!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1))
    6188 +     exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".shellescape(g:netrw_machine,1)
    6189 +    endif
    6190 +    " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    6191 +    if getline(1) !~ "^$"
    6192 +     if !exists("g:netrw_quiet")
    6193 +      keepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
    6194 +     endif
    6195 +     let mod=1
    6196 +    endif
    6197  
    6198 -  " Method#5: http[s]://user@hostname/...path-to-file {{{3
    6199 -  elseif match(a:choice,httpurm) == 0
    6200 -"   call Decho("http://...")
    6201 -   let b:netrw_method = 5
    6202 -   let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
    6203 -   let b:netrw_fname  = substitute(a:choice,httpurm,'\2',"")
    6204 +    " remove enew buffer (quietly)
    6205 +    let filtbuf= bufnr("%")
    6206 +    exe curbuf."b!"
    6207 +    let &l:bh            = bhkeep
    6208 +    exe filtbuf."bw!"
    6209  
    6210 -  " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
    6211 -  elseif match(a:choice,davurm) == 0
    6212 -"   call Decho("dav://...")
    6213 -   let b:netrw_method= 6
    6214 -   if a:choice =~ 'davs:'
    6215 -    let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
    6216 -   else
    6217 -    let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
    6218 -   endif
    6219 -   let b:netrw_fname  = substitute(a:choice,davurm,'\3',"")
    6220 +    let b:netrw_lastfile = choice
    6221  
    6222 -   " Method#7: rsync://user@hostname/...path-to-file {{{3
    6223 -  elseif match(a:choice,rsyncurm) == 0
    6224 -"   call Decho("rsync://...")
    6225 -   let b:netrw_method = 7
    6226 -   let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
    6227 -   let b:netrw_fname  = substitute(a:choice,rsyncurm,'\2',"")
    6228 +   ".........................................
    6229 +   " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
    6230 +   elseif b:netrw_method == 3
    6231 +    " Construct execution string (three or more lines) which will be passed through filter
    6232 +"    call Decho("read via ftp+mipf (method #3)")
    6233 +    let netrw_fname = b:netrw_fname
    6234 +    let bhkeep      = &l:bh
    6235  
    6236 -   " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
    6237 -  elseif match(a:choice,ftpurm) == 0
    6238 -"   call Decho("ftp://...")
    6239 -   let userid        = substitute(a:choice,ftpurm,'\2',"")
    6240 -   let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
    6241 -   let g:netrw_port   = substitute(a:choice,ftpurm,'\4',"")
    6242 -   let b:netrw_fname  = substitute(a:choice,ftpurm,'\5',"")
    6243 -"   call Decho("g:netrw_machine<".g:netrw_machine.">")
    6244 -   if userid != ""
    6245 -    let g:netrw_uid= userid
    6246 -   endif
    6247 +    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    6248 +    let curbuf      = bufnr("%")
    6249 +    setl bh=hide
    6250 +    keepalt enew
    6251 +    setl ff=unix
    6252  
    6253 -   if curmachine != g:netrw_machine
    6254 -    if exists("s:netwr_hup[".g:netrw_machine."]")
    6255 -     call NetUserPass("ftp:".g:netrw_machine)
    6256 -    elseif exists("s:netrw_passwd")
    6257 -     " if there's a change in hostname, require password re-entry
    6258 -     unlet s:netrw_passwd
    6259 +    if exists("g:netrw_port") && g:netrw_port != ""
    6260 +     keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    6261 +"     call Decho("filter input: ".getline('.'))
    6262 +    else
    6263 +     keepj put ='open '.g:netrw_machine
    6264 +"     call Decho("filter input: ".getline('.'))
    6265      endif
    6266 -    if exists("netrw_port")
    6267 -     unlet netrw_port
    6268 +    if exists("g:netrw_uid") && g:netrw_uid != ""
    6269 +     if exists("g:netrw_ftp") && g:netrw_ftp == 1
    6270 +      keepj put =g:netrw_uid
    6271 +"      call Decho("filter input: ".getline('.'))
    6272 +      if exists("s:netrw_passwd") && s:netrw_passwd != ""
    6273 +       keepj put ='\"'.s:netrw_passwd.'\"'
    6274 +      endif
    6275 +"      call Decho("filter input: ".getline('.'))
    6276 +     elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
    6277 +      keepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
    6278 +"      call Decho("filter input: ".getline('.'))
    6279 +     endif
    6280      endif
    6281 -   endif
    6282 -
    6283 -   if exists("g:netrw_uid") && exists("s:netrw_passwd")
    6284 -    let b:netrw_method = 3
    6285 -   else
    6286 -    let host= substitute(g:netrw_machine,'\..*$','','')
    6287 -    if exists("s:netrw_hup[host]")
    6288 -     call NetUserPass("ftp:".host)
    6289 +    keepj put =g:netrw_ftpmode
    6290 +"    call Decho("filter input: ".getline('$'))
    6291 +    if exists("g:netrw_ftpextracmd")
    6292 +     keepj put =g:netrw_ftpextracmd
    6293 +"     call Decho("filter input: ".getline("$"))
    6294 +    endif
    6295 +    keepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
    6296 +"    call Decho("filter input: ".getline('.'))
    6297 +    " save choice/id/password for future use
    6298 +    let b:netrw_lastfile = choice
    6299  
    6300 -    elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
    6301 -"     call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
    6302 -"     call Decho("          g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
    6303 -     if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
    6304 -      let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
    6305 -"      call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
    6306 -     endif
    6307 -     let b:netrw_method= 2
    6308 -    elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
    6309 -"     call Decho("using <".expand("$HOME/.netrc")."> (readable)")
    6310 -     let b:netrw_method= 2
    6311 -    else
    6312 -     if !exists("g:netrw_uid") || g:netrw_uid == ""
    6313 -      call NetUserPass()
    6314 -     elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
    6315 -      call NetUserPass(g:netrw_uid)
    6316 -    " else just use current g:netrw_uid and s:netrw_passwd
    6317 +    " perform ftp:
    6318 +    " -i       : turns off interactive prompting from ftp
    6319 +    " -n  unix : DON'T use <.netrc>, even though it exists
    6320 +    " -n  win32: quit being obnoxious about password
    6321 +    keepj norm! 1Gdd
    6322 +"    call Decho("executing: %!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
    6323 +    exe s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options
    6324 +    " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
    6325 +    if getline(1) !~ "^$"
    6326 +     if  !exists("g:netrw_quiet")
    6327 +      call netrw#ErrorMsg(s:ERROR,getline(1),15)
    6328       endif
    6329 -     let b:netrw_method= 3
    6330 +     let mod=1
    6331      endif
    6332 -   endif
    6333  
    6334 -  " Method#8: fetch {{{3
    6335 -  elseif match(a:choice,fetchurm) == 0
    6336 -"   call Decho("fetch://...")
    6337 -   let b:netrw_method = 8
    6338 -   let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
    6339 -   let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
    6340 -   let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
    6341 -   let b:netrw_fname  = substitute(a:choice,fetchurm,'\5',"")
    6342 +    " remove enew buffer (quietly)
    6343 +    let filtbuf= bufnr("%")
    6344 +    exe curbuf."b!"
    6345 +    let &l:bh= bhkeep
    6346 +    exe filtbuf."bw!"
    6347  
    6348 -   " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
    6349 -  elseif match(a:choice,mipf) == 0
    6350 -"   call Decho("(ftp) host id pass file")
    6351 -   let b:netrw_method  = 3
    6352 -   let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
    6353 -   let g:netrw_uid     = substitute(a:choice,mipf,'\2',"")
    6354 -   let s:netrw_passwd  = substitute(a:choice,mipf,'\3',"")
    6355 -   let b:netrw_fname   = substitute(a:choice,mipf,'\4',"")
    6356 -   call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
    6357 +   ".........................................
    6358 +   " NetWrite: (scp) NetWrite Method #4 {{{3
    6359 +   elseif     b:netrw_method == 4
    6360 +"    call Decho("write via scp (method #4)")
    6361 +    if exists("g:netrw_port") && g:netrw_port != ""
    6362 +     let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
    6363 +    else
    6364 +     let useport= ""
    6365 +    endif
    6366 +"    call Decho("exe ".s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
    6367 +    exe s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
    6368 +    let b:netrw_lastfile = choice
    6369  
    6370 -  " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
    6371 -  elseif match(a:choice,mf) == 0
    6372 -"   call Decho("(ftp) host file")
    6373 -   if exists("g:netrw_uid") && exists("s:netrw_passwd")
    6374 -    let b:netrw_method  = 3
    6375 -    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
    6376 -    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
    6377 +   ".........................................
    6378 +   " NetWrite: (http) NetWrite Method #5 {{{3
    6379 +   elseif     b:netrw_method == 5
    6380 +"    call Decho("write via http (method #5)")
    63815143+    let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
    63825144+    if executable(curl)
     
    63865148+    elseif !exists("g:netrw_quiet")
    63875149+     call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd".">".",16)
    6388 +    endif
    6389  
    6390 -   elseif s:FileReadable(expand("$HOME/.netrc"))
    6391 -    let b:netrw_method  = 2
    6392 -    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
    6393 -    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
    6394 -   endif
    6395 +   ".........................................
    6396 +   " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
    6397 +   elseif     b:netrw_method == 6
    6398 +"    call Decho("write via cadaver (method #6)")
    6399  
    6400 -  " Method#9: sftp://user@hostname/...path-to-file {{{3
    6401 -  elseif match(a:choice,sftpurm) == 0
    6402 -"   call Decho("sftp://...")
    6403 -   let b:netrw_method = 9
    6404 -   let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
    6405 -   let b:netrw_fname  = substitute(a:choice,sftpurm,'\2',"")
    6406 +    " Construct execution string (four lines) which will be passed through filter
    6407 +    let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
    6408 +    let bhkeep      = &l:bh
    6409  
    6410 -  " Method#1: Issue an rcp: hostname:filename"  (this one should be last) {{{3
    6411 -  elseif match(a:choice,rcphf) == 0
    6412 -"   call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
    6413 -   let b:netrw_method  = 1
    6414 -   let userid          = substitute(a:choice,rcphf,'\2',"")
    6415 -   let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
    6416 -   let b:netrw_fname   = substitute(a:choice,rcphf,'\4',"")
    6417 -"   call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
    6418 -"   call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
    6419 -"   call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
    6420 -"   call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
    6421 -   if userid != ""
    6422 -    let g:netrw_uid= userid
    6423 -   endif
    6424 +    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    6425 +    let curbuf      = bufnr("%")
    6426 +    setl bh=hide
    6427 +    keepalt enew
    6428  
    6429 -  " Cannot Determine Method {{{3
    6430 -  else
    6431 -   if !exists("g:netrw_quiet")
    6432 -    call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
    6433 -   endif
    6434 -   let b:netrw_method  = -1
    6435 -  endif
    6436 -  "}}}3
    6437 +    setl ff=unix
    6438 +    if exists("g:netrw_port") && g:netrw_port != ""
    6439 +     keepj put ='open '.g:netrw_machine.' '.g:netrw_port
    6440 +    else
    6441 +     keepj put ='open '.g:netrw_machine
    6442 +    endif
    6443 +    if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
    6444 +     keepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
    6445 +    endif
    6446 +    keepj put ='put '.tmpfile.' '.netrw_fname
    6447  
    6448 -  if g:netrw_port != ""
    6449 -   " remove any leading [:#] from port number
    6450 -   let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
    6451 -  elseif exists("netrw_port")
    6452 -   " retain port number as implicit for subsequent ftp operations
    6453 -   let g:netrw_port= netrw_port
    6454 -  endif
    6455 +    " perform cadaver operation:
    6456 +    keepj norm! 1Gdd
    6457 +"    call Decho("executing: %!".g:netrw_dav_cmd)
    6458 +    exe s:netrw_silentxfer."%!".g:netrw_dav_cmd
    6459  
    6460 -"  call Decho("a:choice       <".a:choice.">")
    6461 -"  call Decho("b:netrw_method <".b:netrw_method.">")
    6462 -"  call Decho("g:netrw_machine<".g:netrw_machine.">")
    6463 -"  call Decho("g:netrw_port   <".g:netrw_port.">")
    6464 -"  if exists("g:netrw_uid")            "Decho
    6465 -"   call Decho("g:netrw_uid    <".g:netrw_uid.">")
    6466 -"  endif                                       "Decho
    6467 -"  if exists("s:netrw_passwd")         "Decho
    6468 -"   call Decho("s:netrw_passwd <".s:netrw_passwd.">")
    6469 -"  endif                                       "Decho
    6470 -"  call Decho("b:netrw_fname  <".b:netrw_fname.">")
    6471 -"  call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
    6472 -endfun
    6473 +    " remove enew buffer (quietly)
    6474 +    let filtbuf= bufnr("%")
    6475 +    exe curbuf."b!"
    6476 +    let &l:bh            = bhkeep
    6477 +    exe filtbuf."bw!"
    6478  
    6479 -" ------------------------------------------------------------------------
    6480 -" NetReadFixup: this sort of function is typically written by the user {{{2
    6481 -"               to handle extra junk that their system's ftp dumps
    6482 -"               into the transfer.  This function is provided as an
    6483 -"               example and as a fix for a Windows 95 problem: in my
    6484 -"               experience, win95's ftp always dumped four blank lines
    6485 -"               at the end of the transfer.
    6486 -if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
    6487 - fun! NetReadFixup(method, line1, line2)
    6488 -"   call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
    6489 +    let b:netrw_lastfile = choice
    6490  
    6491 -   " sanity checks -- attempt to convert inputs to integers
    6492 -   let method = a:method + 0
    6493 -   let line1  = a:line1 + 0
    6494 -   let line2  = a:line2 + 0
    6495 -   if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
    6496 -"    call Dret("NetReadFixup")
    6497 -    return
    6498 -   endif
    6499 +   ".........................................
    6500 +   " NetWrite: (rsync) NetWrite Method #7 {{{3
    6501 +   elseif     b:netrw_method == 7
    6502 +"    call Decho("write via rsync (method #7)")
    6503 +"    call Decho("executing: !".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1))
    6504 +    exe s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".shellescape(tmpfile,1)." ".shellescape(g:netrw_machine.":".b:netrw_fname,1)
    6505 +    let b:netrw_lastfile = choice
    6506  
    6507 -   if method == 3   " ftp (no <.netrc>)
    6508 -    let fourblanklines= line2 - 3
    6509 -    if fourblanklines >= line1
    6510 -     exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
    6511 -     call histdel("/",-1)
    6512 +   ".........................................
    6513 +   " NetWrite: (sftp) NetWrite Method #9 {{{3
    6514 +   elseif     b:netrw_method == 9
    6515 +"    call Decho("write via sftp (method #9)")
    6516 +    let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
    6517 +    if exists("g:netrw_uid") &&  ( g:netrw_uid != "" )
    6518 +     let uid_machine = g:netrw_uid .'@'. g:netrw_machine
    6519 +    else
    6520 +     let uid_machine = g:netrw_machine
    65215150     endif
    6522 -   endif
    6523 -
    6524 -"   call Dret("NetReadFixup")
    6525 - endfun
    6526 -endif
    6527 -
    6528 -" ---------------------------------------------------------------------
    6529 -" NetUserPass: set username and password for subsequent ftp transfer {{{2
    6530 -"   Usage:  :call NetUserPass()                               -- will prompt for userid and password
    6531 -"          :call NetUserPass("uid")                   -- will prompt for password
    6532 -"          :call NetUserPass("uid","password")        -- sets global userid and password
    6533 -"          :call NetUserPass("ftp:host")              -- looks up userid and password using hup dictionary
    6534 -"          :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
    6535 -fun! NetUserPass(...)
    6536  
    6537 -" call Dfunc("NetUserPass() a:0=".a:0)
    6538 +    " formerly just a "new...bd!", that changed the window sizes when equalalways.  Using enew workaround instead
    6539 +    let bhkeep = &l:bh
    6540 +    let curbuf = bufnr("%")
    6541 +    setl bh=hide
    6542 +    keepalt enew
    6543  
    6544 - if !exists('s:netrw_hup')
    6545 -  let s:netrw_hup= {}
    6546 - endif
    6547 +    setl ff=unix
    6548 +    call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
    6549 +"    call Decho("filter input: ".getline('.'))
    6550 +"    call Decho("executing: %!".g:netrw_sftp_cmd.' '.shellescape(uid_machine,1))
    6551 +    let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
    6552 +    exe s:netrw_silentxfer."%!".sftpcmd.' '.shellescape(uid_machine,1)
    6553 +    let filtbuf= bufnr("%")
    6554 +    exe curbuf."b!"
    6555 +    let &l:bh            = bhkeep
    6556 +    exe filtbuf."bw!"
    6557 +    let b:netrw_lastfile = choice
    6558  
    6559 - if a:0 == 0
    6560 -  " case: no input arguments
    6561 +   ".........................................
    6562 +   " NetWrite: Complain {{{3
    6563 +   else
    6564 +    call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
    6565 +    let leavemod= 1
    6566 +   endif
    6567 +  endwhile
    6568  
    6569 -  " change host and username if not previously entered; get new password
    6570 -  if !exists("g:netrw_machine")
    6571 -   let g:netrw_machine= input('Enter hostname: ')
    6572 -  endif
    6573 -  if !exists("g:netrw_uid") || g:netrw_uid == ""
    6574 -   " get username (user-id) via prompt
    6575 -   let g:netrw_uid= input('Enter username: ')
    6576 +  " NetWrite: Cleanup: {{{3
    6577 +"  call Decho("cleanup")
    6578 +  if s:FileReadable(tmpfile)
    6579 +"   call Decho("tmpfile<".tmpfile."> readable, will now delete it")
    6580 +   call s:NetrwDelete(tmpfile)
    6581    endif
    6582 -  " get password via prompting
    6583 -  let s:netrw_passwd= inputsecret("Enter Password: ")
    6584 +  call s:NetrwOptionRestore("w:")
    6585  
    6586 -  " set up hup database
    6587 -  let host = substitute(g:netrw_machine,'\..*$','','')
    6588 -  if !exists('s:netrw_hup[host]')
    6589 -   let s:netrw_hup[host]= {}
    6590 +  if a:firstline == 1 && a:lastline == line("$")
    6591 +   " restore modifiability; usually equivalent to set nomod
    6592 +   let &mod= mod
     5151 
     5152    ".........................................
     5153@@ -2313,12 +2518,12 @@
     5154   if a:firstline == 1 && a:lastline == line("$")
     5155    " restore modifiability; usually equivalent to set nomod
     5156    let &mod= mod
     5157-"   call Decho("(NetWrite)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    65935158+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    6594 +  elseif !exists("leavemod")
    6595 +   " indicate that the buffer has not been modified since last written
     5159   elseif !exists("leavemod")
     5160    " indicate that the buffer has not been modified since last written
     5161-"   call Decho("(NetWrite) set nomod")
     5162-   set nomod
     5163-"   call Decho("(NetWrite)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    65965164+"   call Decho("set nomod")
    65975165+   setl nomod
    65985166+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    65995167   endif
    6600 -  let s:netrw_hup[host].uid    = g:netrw_uid
    6601 -  let s:netrw_hup[host].passwd = s:netrw_passwd
    6602  
    6603 - elseif a:0 == 1
    6604 -  " case: one input argument
    6605 -
    6606 -  if a:1 =~ '^ftp:'
    6607 -   " get host from ftp:... url
    6608 -   " access userid and password from hup (host-user-passwd) dictionary
    6609 -   let host = substitute(a:1,'^ftp:','','')
    6610 -   let host = substitute(host,'\..*','','')
    6611 -   if exists("s:netrw_hup[host]")
    6612 -    let g:netrw_uid    = s:netrw_hup[host].uid
    6613 -    let s:netrw_passwd = s:netrw_hup[host].passwd
    6614 -"    call Decho("get s:netrw_hup[".host."].uid   <".s:netrw_hup[host].uid.">")
    6615 -"    call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
    6616 -   else
    6617 -    let g:netrw_uid    = input("Enter UserId: ")
    6618 -    let s:netrw_passwd = inputsecret("Enter Password: ")
    6619 -   endif
    6620 +"  call Dret("netrw#NetWrite")
    6621 +endfun
    6622  
    6623 +" ---------------------------------------------------------------------
    6624 +" netrw#NetSource: source a remotely hosted vim script {{{2
    6625 +" uses NetRead to get a copy of the file into a temporarily file,
    6626 +"              then sources that file,
    6627 +"              then removes that file.
    6628 +fun! netrw#NetSource(...)
    6629 +"  call Dfunc("netrw#NetSource() a:0=".a:0)
    6630 +  if a:0 > 0 && a:1 == '?'
    6631 +   " give help
    6632 +   echomsg 'NetSource Usage:'
    6633 +   echomsg ':Nsource dav://machine[:port]/path            uses cadaver'
    6634 +   echomsg ':Nsource fetch://machine/path                 uses fetch'
    6635 +   echomsg ':Nsource ftp://[user@]machine[:port]/path     uses ftp   autodetects <.netrc>'
    6636 +   echomsg ':Nsource http[s]://[user@]machine/path        uses http  wget'
    6637 +   echomsg ':Nsource rcp://[user@]machine/path            uses rcp'
    6638 +   echomsg ':Nsource rsync://machine[:port]/path          uses rsync'
    6639 +   echomsg ':Nsource scp://[user@]machine[[:#]port]/path  uses scp'
    6640 +   echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
    6641 +   sleep 4
    6642    else
    6643 -   " case: one input argument, not an url.  Using it as a new user-id.
    6644 -   if exists("g:netrw_machine")
    6645 -    let host= substitute(g:netrw_machine,'\..*$','','')
    6646 -   else
    6647 -    let g:netrw_machine= input('Enter hostname: ')
    6648 -   endif
    6649 -   let g:netrw_uid = a:1
    6650 -"   call Decho("set g:netrw_uid= <".g:netrw_uid.">")
    6651 -   if exists("g:netrw_passwd")
    6652 -    " ask for password if one not previously entered
    6653 -    let s:netrw_passwd= g:netrw_passwd
    6654 -   else
    6655 -    let s:netrw_passwd = inputsecret("Enter Password: ")
    6656 -   endif
    6657 +   let i= 1
    6658 +   while i <= a:0
    6659 +    call netrw#NetRead(3,a:{i})
     5168 
     5169 "  call Dret("netrw#NetWrite")
     5170@@ -2347,11 +2552,11 @@
     5171    let i= 1
     5172    while i <= a:0
     5173     call netrw#NetRead(3,a:{i})
     5174-"    call Decho("(netrw#NetSource) s:netread_tmpfile<".s:netrw_tmpfile.">")
    66605175+"    call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">")
    6661 +    if s:FileReadable(s:netrw_tmpfile)
     5176     if s:FileReadable(s:netrw_tmpfile)
     5177-"     call Decho("(netrw#NetSource) exe so ".fnameescape(s:netrw_tmpfile))
    66625178+"     call Decho("exe so ".fnameescape(s:netrw_tmpfile))
    6663 +     exe "so ".fnameescape(s:netrw_tmpfile)
     5179      exe "so ".fnameescape(s:netrw_tmpfile)
     5180-"     call Decho("(netrw#NetSource) delete(".s:netrw_tmpfile.")")
    66645181+"     call Decho("delete(".s:netrw_tmpfile.")")
    6665 +     call delete(s:netrw_tmpfile)
    6666 +     unlet s:netrw_tmpfile
    6667 +    else
    6668 +     call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
    6669 +    endif
    6670 +    let i= i + 1
    6671 +   endwhile
    6672    endif
    6673 +"  call Dret("netrw#NetSource")
    6674 +endfun
    6675  
    6676 -"  call Decho("host<".host.">")
    6677 -  if exists("host")
    6678 -   if !exists('s:netrw_hup[host]')
    6679 -    let s:netrw_hup[host]= {}
    6680 -   endif
    6681 -   let s:netrw_hup[host].uid    = g:netrw_uid
    6682 -   let s:netrw_hup[host].passwd = s:netrw_passwd
     5182      call delete(s:netrw_tmpfile)
     5183      unlet s:netrw_tmpfile
     5184     else
     5185@@ -2363,6 +2568,49 @@
     5186 "  call Dret("netrw#NetSource")
     5187 endfun
     5188 
    66835189+" ---------------------------------------------------------------------
    66845190+" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
     
    67205226+  else
    67215227+   call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
    6722    endif
     5228+  endif
    67235229+"  call Dret("netrw#SetTreetop")
    67245230+endfun
    6725  
    6726 - elseif a:0 == 2
    6727 -  let g:netrw_uid    = a:1
    6728 -  let s:netrw_passwd = a:2
    6729 +" ===========================================
    6730 +" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
    6731 +"    readcmd == %r : replace buffer with newly read file
    6732 +"            == 0r : read file at top of buffer
    6733 +"            == r  : read file after current line
    6734 +"            == t  : leave file in temporary form (ie. don't read into buffer)
    6735 +fun! s:NetrwGetFile(readcmd, tfile, method)
    6736 +"  call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
    6737  
    6738 - elseif a:0 == 3
    6739 -  " enter hostname, user-id, and password into the hup dictionary
    6740 -  let host = substitute(a:1,'^\a\+:','','')
    6741 -  let host = substitute(host,'\..*$','','')
    6742 -  if !exists('s:netrw_hup[host]')
    6743 -   let s:netrw_hup[host]= {}
    6744 +  " readcmd=='t': simply do nothing
    6745 +  if a:readcmd == 't'
     5231+
     5232 " ===========================================
     5233 " s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
     5234 "    readcmd == %r : replace buffer with newly read file
     5235@@ -2374,7 +2622,7 @@
     5236 
     5237   " readcmd=='t': simply do nothing
     5238   if a:readcmd == 't'
     5239-"   call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    67465240+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    6747 +"   call Dret("NetrwGetFile : skip read of <".a:tfile.">")
     5241 "   call Dret("NetrwGetFile : skip read of <".a:tfile.">")
     5242    return
     5243   endif
     5244@@ -2394,7 +2642,7 @@
     5245 
     5246    " rename the current buffer to the temp file (ie. tfile)
     5247    if g:netrw_cygwin
     5248-    let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','')
     5249+    let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
     5250    else
     5251     let tfile= a:tfile
     5252    endif
     5253@@ -2440,6 +2688,12 @@
     5254    let line1 = 1
     5255    let line2 = line("$")
     5256 
     5257+  elseif !&ma
     5258+   " attempting to read a file after the current line in the file, but the buffer is not modifiable
     5259+   keepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
     5260+"   call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
    67485261+   return
    6749    endif
    6750 -  let s:netrw_hup[host].uid    = a:2
    6751 -  let s:netrw_hup[host].passwd = a:3
    6752 -  let g:netrw_uid              = s:netrw_hup[host].uid
    6753 -  let s:netrw_passwd           = s:netrw_hup[host].passwd
    6754 -"  call Decho("set s:netrw_hup[".host."].uid   <".s:netrw_hup[host].uid.">")
    6755 -"  call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
    6756 - endif
    6757  
    6758 -" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
    6759 -endfun
    6760 +  " get name of remote filename (ie. url and all)
    6761 +  let rfile= bufname("%")
    6762 +"  call Decho("rfile<".rfile.">")
    6763  
    6764 -" ===========================================
    6765 -"  Shared Browsing Support:    {{{1
    6766 -" ===========================================
    6767 +  if exists("*NetReadFixup")
    6768 +   " for the use of NetReadFixup (not otherwise used internally)
    6769 +   let line2= line("$")
    6770 +  endif
    6771  
    6772 -" ---------------------------------------------------------------------
     5262+
     5263   elseif s:FileReadable(a:tfile)
     5264    " read file after current line
     5265 "   call Decho("read file<".a:tfile."> after current line")
     5266@@ -2452,7 +2706,7 @@
     5267 
     5268   else
     5269    " not readable
     5270-"   call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5271+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5272 "   call Decho("tfile<".a:tfile."> not readable")
     5273    keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
     5274 "   call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
     5275@@ -2477,7 +2731,7 @@
     5276  " make sure file is being displayed
     5277 "  redraw!
     5278 
     5279-"  call Decho("(NetrwGetFile)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5280+"  call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5281 "  call Dret("NetrwGetFile")
     5282 endfun
     5283 
     5284@@ -2583,10 +2837,11 @@
     5285 
     5286   " Method#5: http[s]://user@hostname/...path-to-file {{{3
     5287   elseif match(a:choice,httpurm) == 0
     5288-"   call Decho("http://...")
     5289+"   call Decho("http[s]://...")
     5290    let b:netrw_method = 5
     5291    let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
     5292    let b:netrw_fname  = substitute(a:choice,httpurm,'\2',"")
     5293+   let b:netrw_http   = (a:choice =~ '^https:')? "https" : "http"
     5294 
     5295   " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
     5296   elseif match(a:choice,davurm) == 0
     5297@@ -2820,6 +3075,7 @@
     5298   if a:1 =~ '^ftp:'
     5299    " get host from ftp:... url
     5300    " access userid and password from hup (host-user-passwd) dictionary
     5301+"   call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)")
     5302    let host = substitute(a:1,'^ftp:','','')
     5303    let host = substitute(host,'\..*','','')
     5304    if exists("s:netrw_hup[host]")
     5305@@ -2834,8 +3090,13 @@
     5306 
     5307   else
     5308    " case: one input argument, not an url.  Using it as a new user-id.
     5309+"   call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)")
     5310    if exists("g:netrw_machine")
     5311-    let host= substitute(g:netrw_machine,'\..*$','','')
     5312+    if g:netrw_machine =~ '[0-9.]\+'
     5313+     let host= g:netrw_machine
     5314+    else
     5315+     let host= substitute(g:netrw_machine,'\..*$','','')
     5316+    endif
     5317    else
     5318     let g:netrw_machine= input('Enter hostname: ')
     5319    endif
     5320@@ -2885,365 +3146,32 @@
     5321 " ===========================================
     5322 
     5323 " ---------------------------------------------------------------------
    67735324-" s:NetrwMaps: {{{2
    67745325-fun! s:NetrwMaps(islocal)
    67755326-"  call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
    6776 +  if a:readcmd[0] == '%'
    6777 +  " get file into buffer
    6778 +"   call Decho("get file into buffer")
     5327+" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
     5328+fun! s:ExplorePatHls(pattern)
     5329+"  call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
     5330+  let repat= substitute(a:pattern,'^**/\{1,2}','','')
     5331+"  call Decho("repat<".repat.">")
     5332+  let repat= escape(repat,'][.\')
     5333+"  call Decho("repat<".repat.">")
     5334+  let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
     5335+"  call Dret("s:ExplorePatHls repat<".repat.">")
     5336+  return repat
     5337+endfun
    67795338 
    67805339-  " set up Rexplore and [ 2-leftmouse-click -or- c-leftmouse ]
     
    67915350-     nmap <unique> <silent> <c-leftmouse>      <Plug>NetrwReturn
    67925351-    endif
    6793 +   " rename the current buffer to the temp file (ie. tfile)
    6794 +   if g:netrw_cygwin
    6795 +    let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
    6796 +   else
    6797 +    let tfile= a:tfile
    6798     endif
     5352-   endif
    67995353-   nno <silent> <Plug>NetrwReturn      :Rexplore<cr>
    68005354-"   call Decho("(NetrwMaps) made <Plug>NetrwReturn map")
    6801 +"   call Decho("exe sil! keepalt file ".fnameescape(tfile))
    6802 +   exe "sil! keepalt file ".fnameescape(tfile)
    6803 +
    6804 +   " edit temporary file (ie. read the temporary file in)
    6805 +   if     rfile =~ '\.zip$'
    6806 +"    call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)")
    6807 +    call zip#Browse(tfile)
    6808 +   elseif rfile =~ '\.tar$'
    6809 +"    call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)")
    6810 +    call tar#Browse(tfile)
    6811 +   elseif rfile =~ '\.tar\.gz$'
    6812 +"    call Decho("handling remote gzip-compressed tar file")
    6813 +    call tar#Browse(tfile)
    6814 +   elseif rfile =~ '\.tar\.bz2$'
    6815 +"    call Decho("handling remote bz2-compressed tar file")
    6816 +    call tar#Browse(tfile)
    6817 +   elseif rfile =~ '\.tar\.xz$'
    6818 +"    call Decho("handling remote xz-compressed tar file")
    6819 +    call tar#Browse(tfile)
    6820 +   elseif rfile =~ '\.txz$'
    6821 +"    call Decho("handling remote xz-compressed tar file (.txz)")
    6822 +    call tar#Browse(tfile)
    6823 +   else
    6824 +"    call Decho("edit temporary file")
    6825 +    e!
    6826 +   endif
    6827 +
    6828 +   " rename buffer back to remote filename
    6829 +"   call Decho("exe sil! keepalt file ".fnameescape(rfile))
    6830 +   exe "sil! keepj keepalt file ".fnameescape(rfile)
    6831 +
    6832 +   " Detect filetype of local version of remote file.
    6833 +   " Note that isk must not include a "/" for scripts.vim
    6834 +   " to process this detection correctly.
    6835 +"   call Decho("detect filetype of local version of remote file")
    6836 +   let iskkeep= &l:isk
    6837 +   setl isk-=/
    6838 +   let &l:isk= iskkeep
    6839 +"   call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!")
    6840 +   let line1 = 1
    6841 +   let line2 = line("$")
    6842 +
    6843 +  elseif !&ma
    6844 +   " attempting to read a file after the current line in the file, but the buffer is not modifiable
    6845 +   keepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
    6846 +"   call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
    6847 +   return
    6848 +
    6849 +  elseif s:FileReadable(a:tfile)
    6850 +   " read file after current line
    6851 +"   call Decho("read file<".a:tfile."> after current line")
    6852 +   let curline = line(".")
    6853 +   let lastline= line("$")
    6854 +"   call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile).">  line#".curline)
    6855 +   exe "keepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
    6856 +   let line1= curline + 1
    6857 +   let line2= line("$") - lastline + 1
    6858 +
    6859 +  else
    6860 +   " not readable
    6861 +"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    6862 +"   call Decho("tfile<".a:tfile."> not readable")
    6863 +   keepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
    6864 +"   call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
    6865 +   return
    6866    endif
    6867  
     5355-  endif
     5356-
    68685357-  if a:islocal
    68695358-"   call Decho("(NetrwMaps) make local maps")
     
    69715460-    nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
    69725461-    imap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
    6973 +  " User-provided (ie. optional) fix-it-up command
    6974 +  if exists("*NetReadFixup")
    6975 +"   call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")")
    6976 +   keepj call NetReadFixup(a:method, line1, line2)
    6977 +"  else " Decho
    6978 +"   call Decho("NetReadFixup() not called, doesn't exist  (line1=".line1." line2=".line2.")")
    6979 +  endif
    6980 +
    6981 +  if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
    6982 +   " update the Buffers menu
    6983 +   keepj call s:UpdateBuffersMenu()
    6984 +  endif
    6985 +
    6986 +"  call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile))
    6987 +
    6988 + " make sure file is being displayed
    6989 +"  redraw!
    6990 +
    6991 +"  call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    6992 +"  call Dret("NetrwGetFile")
    6993 +endfun
    6994 +
    6995 +" ------------------------------------------------------------------------
    6996 +" s:NetrwMethod:  determine method of transfer {{{2
    6997 +" Input:
    6998 +"   choice = url   [protocol:]//[userid@]hostname[:port]/[path-to-file]
    6999 +" Output:
    7000 +"  b:netrw_method= 1: rcp                                             
    7001 +"                  2: ftp + <.netrc>                                 
    7002 +"                 3: ftp + machine, id, password, and [path]filename
    7003 +"                 4: scp                                             
    7004 +"                 5: http[s] (wget)                                     
    7005 +"                 6: dav
    7006 +"                 7: rsync                                           
    7007 +"                 8: fetch                                           
    7008 +"                 9: sftp                                           
    7009 +"  g:netrw_machine= hostname
    7010 +"  b:netrw_fname  = filename
    7011 +"  g:netrw_port   = optional port number (for ftp)
    7012 +"  g:netrw_choice = copy of input url (choice)
    7013 +fun! s:NetrwMethod(choice)
    7014 +"   call Dfunc("NetrwMethod(a:choice<".a:choice.">)")
    7015 +
    7016 +   " sanity check: choice should have at least three slashes in it
    7017 +   if strlen(substitute(a:choice,'[^/]','','g')) < 3
    7018 +    call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
    7019 +    let b:netrw_method = -1
    7020 +"    call Dret("NetrwMethod : incorrect url format<".a:choice.">")
    7021 +    return
    7022     endif
     5462-   endif
    70235463-   nnoremap <buffer> <silent> <Plug>NetrwHideEdit      :call <SID>NetrwHideEdit(1)<cr>
    70245464-   if !hasmapto('<Plug>NetrwRefresh')
    70255465-    nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
    70265466-    imap <buffer> <unique> <c-l> <Plug>NetrwRefresh
    7027 +
    7028 +   " record current g:netrw_machine, if any
    7029 +   " curmachine used if protocol == ftp and no .netrc
    7030 +   if exists("g:netrw_machine")
    7031 +    let curmachine= g:netrw_machine
    7032 +"    call Decho("curmachine<".curmachine.">")
    7033 +   else
    7034 +    let curmachine= "N O T A HOST"
    7035     endif
     5467-   endif
    70365468-   nnoremap <buffer> <silent> <Plug>NetrwRefresh               :call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
    70375469-   if s:didstarstar || !mapcheck("<s-down>","n")
     
    70645496-    exe 'vnoremap <buffer> <silent> <rightmouse>  <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
    70655497-    exe 'inoremap <buffer> <silent> <rightmouse>  <c-o><leftmouse><c-o>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
    7066 +   if exists("g:netrw_port")
    7067 +    let netrw_port= g:netrw_port
    7068     endif
     5498-   endif
    70695499-   exe 'nnoremap <buffer> <silent> <del>       :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
    70705500-   exe 'nnoremap <buffer> <silent> D           :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
     
    70795509-   exe 'inoremap <buffer> <silent> <Leader>m   <c-o>:call <SID>NetrwMakeDir("")<cr>'
    70805510-   nnoremap <buffer> <F1>              :he netrw-quickhelp<cr>
    7081  
     5511-
    70825512-  else " remote
    70835513-"   call Decho("(NetrwMaps) make remote maps")
     
    71895619-    imap <buffer> <c-l> <Plug>NetrwRefresh
    71905620-   endif
    7191 +   " insure that netrw_ftp_cmd starts off every method determination
    7192 +   " with the current g:netrw_ftp_cmd
    7193 +   let s:netrw_ftp_cmd= g:netrw_ftp_cmd
    7194  
     5621-
    71955622-   let mapsafepath     = escape(s:path, s:netrw_map_escape)
    71965623-   let mapsafeusermach = escape(s:user.s:machine, s:netrw_map_escape)
    7197 +  " initialization
    7198 +  let b:netrw_method  = 0
    7199 +  let g:netrw_machine = ""
    7200 +  let b:netrw_fname   = ""
    7201 +  let g:netrw_port    = ""
    7202 +  let g:netrw_choice  = a:choice
    7203  
     5624-
    72045625-   nnoremap <buffer> <silent> <Plug>NetrwRefresh       :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
    72055626-   if g:netrw_mousemaps == 1
     
    72235644-    exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
    72245645-    exe 'inoremap <buffer> <silent> <rightmouse> <c-o><leftmouse><c-o>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
    7225 +  " Patterns:
    7226 +  " mipf     : a:machine a:id password filename             Use ftp
    7227 +  " mf     : a:machine filename                     Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
    7228 +  " ftpurm   : ftp://[user@]host[[#:]port]/filename  Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
    7229 +  " rcpurm   : rcp://[user@]host/filename           Use rcp
    7230 +  " rcphf    : [user@]host:filename                 Use rcp
    7231 +  " scpurm   : scp://[user@]host[[#:]port]/filename  Use scp
    7232 +  " httpurm  : http[s]://[user@]host/filename       Use wget
    7233 +  " davurm   : dav[s]://host[:port]/path             Use cadaver/curl
    7234 +  " rsyncurm : rsync://host[:port]/path              Use rsync
    7235 +  " fetchurm : fetch://[user@]host[:http]/filename   Use fetch (defaults to ftp, override for http)
    7236 +  " sftpurm  : sftp://[user@]host/filename  Use scp
    7237 +  let mipf     = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
    7238 +  let mf       = '^\(\S\+\)\s\+\(\S\+\)$'
    7239 +"  let ftpurm   = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
    7240 +"  let rcpurm   = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$'
    7241 +"  let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
    7242 +  let ftpurm   = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
    7243 +  let rcpurm   = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
    7244 +  let rcphf    = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
    7245 +  let scpurm   = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
    7246 +  let httpurm  = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
    7247 +  let davurm   = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
    7248 +  let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
    7249 +  let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
    7250 +  let sftpurm  = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
    7251 +
    7252 +"  call Decho("determine method:")
    7253 +  " Determine Method
    7254 +  " Method#1: rcp://user@hostname/...path-to-file {{{3
    7255 +  if match(a:choice,rcpurm) == 0
    7256 +"   call Decho("rcp://...")
    7257 +   let b:netrw_method  = 1
    7258 +   let userid          = substitute(a:choice,rcpurm,'\1',"")
    7259 +   let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
    7260 +   let b:netrw_fname   = substitute(a:choice,rcpurm,'\3',"")
    7261 +   if userid != ""
    7262 +    let g:netrw_uid= userid
    7263     endif
     5646-   endif
    72645647-   exe 'nnoremap <buffer> <silent> <del>       :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
    72655648-   exe 'nnoremap <buffer> <silent> d           :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
     
    72765659-   inoremap <buffer> <F1>                      <c-o>:he netrw-quickhelp<cr>
    72775660-  endif
    7278  
     5661-
    72795662-  keepj call s:SetRexDir(a:islocal,b:netrw_curdir)
    7280 +  " Method#4: scp://user@hostname/...path-to-file {{{3
    7281 +  elseif match(a:choice,scpurm) == 0
    7282 +"   call Decho("scp://...")
    7283 +   let b:netrw_method  = 4
    7284 +   let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
    7285 +   let g:netrw_port    = substitute(a:choice,scpurm,'\2',"")
    7286 +   let b:netrw_fname   = substitute(a:choice,scpurm,'\3',"")
    7287  
     5663-
    72885664-"  call Dret("s:NetrwMaps")
    72895665-endfun
    7290 +  " Method#5: http[s]://user@hostname/...path-to-file {{{3
    7291 +  elseif match(a:choice,httpurm) == 0
    7292 +"   call Decho("http[s]://...")
    7293 +   let b:netrw_method = 5
    7294 +   let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
    7295 +   let b:netrw_fname  = substitute(a:choice,httpurm,'\2',"")
    7296 +   let b:netrw_http   = (a:choice =~ '^https:')? "https" : "http"
    7297  
     5666-
    72985667-" ---------------------------------------------------------------------
    72995668-" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
     
    73085677-  return repat
    73095678-endfun
    7310 +  " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
    7311 +  elseif match(a:choice,davurm) == 0
    7312 +"   call Decho("dav://...")
    7313 +   let b:netrw_method= 6
    7314 +   if a:choice =~ 'davs:'
    7315 +    let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
    7316 +   else
    7317 +    let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
    7318 +   endif
    7319 +   let b:netrw_fname  = substitute(a:choice,davurm,'\3',"")
    7320  
     5679-
    73215680-" ---------------------------------------------------------------------
    73225681-"  s:NetrwBookHistHandler: {{{2
     
    73335692-"   "  call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
    73345693-   return
    7335 -  endif
    7336 +   " Method#7: rsync://user@hostname/...path-to-file {{{3
    7337 +  elseif match(a:choice,rsyncurm) == 0
    7338 +"   call Decho("rsync://...")
    7339 +   let b:netrw_method = 7
    7340 +   let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
    7341 +   let b:netrw_fname  = substitute(a:choice,rsyncurm,'\2',"")
    7342  
    7343 -  let ykeep= @@
    7344 -  if a:chg == 0
    7345 -   " bookmark the current directory
    7346 -"   call Decho("(user: <b>) bookmark the current directory")
    7347 -   if !exists("g:netrw_bookmarklist")
    7348 -    let g:netrw_bookmarklist= []
    7349 -   endif
    7350 -   if index(g:netrw_bookmarklist,a:curdir) == -1
    7351 -    " curdir not currently in g:netrw_bookmarklist, so include it
    7352 -    call add(g:netrw_bookmarklist,a:curdir)
    7353 -    call sort(g:netrw_bookmarklist)
    7354 +   " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
    7355 +  elseif match(a:choice,ftpurm) == 0
    7356 +"   call Decho("ftp://...")
    7357 +   let userid        = substitute(a:choice,ftpurm,'\2',"")
    7358 +   let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
    7359 +   let g:netrw_port   = substitute(a:choice,ftpurm,'\4',"")
    7360 +   let b:netrw_fname  = substitute(a:choice,ftpurm,'\5',"")
    7361 +"   call Decho("g:netrw_machine<".g:netrw_machine.">")
    7362 +   if userid != ""
    7363 +    let g:netrw_uid= userid
    7364     endif
    7365 -   echo "bookmarked the current directory"
    7366  
    7367 -  elseif a:chg == 1
    7368 -   " change to the bookmarked directory
    7369 -"   call Decho("(user: <".v:count."gb>) change to the bookmarked directory")
    7370 -   if exists("g:netrw_bookmarklist[v:count-1]")
    7371 -"    call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist))
    7372 -    exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
    7373 -   else
    7374 -    echomsg "Sorry, bookmark#".v:count." doesn't exist!"
    7375 +   if curmachine != g:netrw_machine
    7376 +    if exists("s:netwr_hup[".g:netrw_machine."]")
    7377 +     call NetUserPass("ftp:".g:netrw_machine)
    7378 +    elseif exists("s:netrw_passwd")
    7379 +     " if there's a change in hostname, require password re-entry
    7380 +     unlet s:netrw_passwd
    7381 +    endif
    7382 +    if exists("netrw_port")
    7383 +     unlet netrw_port
    7384 +    endif
    7385     endif
    7386  
    7387 -  elseif a:chg == 2
    7388 -"   redraw!
    7389 -   let didwork= 0
    7390 -   " list user's bookmarks
    7391 -"   call Decho("(user: <q>) list user's bookmarks")
    7392 -   if exists("g:netrw_bookmarklist")
    7393 -"    call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
    7394 -    let cnt= 1
    7395 -    for bmd in g:netrw_bookmarklist
    7396 -"     call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
    7397 -     echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
    7398 -     let didwork = 1
    7399 -     let cnt     = cnt + 1
    7400 -    endfor
    7401 -   endif
    7402 +   if exists("g:netrw_uid") && exists("s:netrw_passwd")
    7403 +    let b:netrw_method = 3
    7404 +   else
    7405 +    let host= substitute(g:netrw_machine,'\..*$','','')
    7406 +    if exists("s:netrw_hup[host]")
    7407 +     call NetUserPass("ftp:".host)
    7408  
    7409 -   " list directory history
    7410 -   let cnt     = g:netrw_dirhist_cnt
    7411 -   let first   = 1
    7412 -   let histcnt = 0
    7413 -   if g:netrw_dirhistmax > 0
    7414 -    while ( first || cnt != g:netrw_dirhist_cnt )
    7415 -"    call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
    7416 -     if exists("g:netrw_dirhist_{cnt}")
    7417 -"     call Decho("Netrw  History#".histcnt.": ".g:netrw_dirhist_{cnt})
    7418 -      echo printf("Netrw  History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
    7419 -      let didwork= 1
    7420 +    elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~ '-[sS]:'
    7421 +"     call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
    7422 +"     call Decho("          g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">")
    7423 +     if g:netrw_ftp_cmd =~ '-[sS]:\S*MACHINE\>'
    7424 +      let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
    7425 +"      call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">")
    7426       endif
    7427 -     let histcnt = histcnt + 1
    7428 -     let first   = 0
    7429 -     let cnt     = ( cnt - 1 ) % g:netrw_dirhistmax
    7430 -     if cnt < 0
    7431 -      let cnt= cnt + g:netrw_dirhistmax
    7432 +     let b:netrw_method= 2
    7433 +    elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
    7434 +"     call Decho("using <".expand("$HOME/.netrc")."> (readable)")
    7435 +     let b:netrw_method= 2
    7436 +    else
    7437 +     if !exists("g:netrw_uid") || g:netrw_uid == ""
    7438 +      call NetUserPass()
    7439 +     elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
    7440 +      call NetUserPass(g:netrw_uid)
    7441 +    " else just use current g:netrw_uid and s:netrw_passwd
    7442       endif
    7443 -    endwhile
    7444 -   else
    7445 -    let g:netrw_dirhist_cnt= 0
    7446 -   endif
    7447 -   if didwork
    7448 -    call inputsave()|call input("Press <cr> to continue")|call inputrestore()
    7449 -   endif
    7450 -
    7451 -  elseif a:chg == 3
    7452 -   " saves most recently visited directories (when they differ)
    7453 -"   call Decho("(browsing) record curdir history")
    7454 -   if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
    7455 -    if g:netrw_dirhistmax > 0
    7456 -     let g:netrw_dirhist_cnt                   = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
    7457 -     let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
    7458 +     let b:netrw_method= 3
    7459      endif
    7460 -"    call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
    7461     endif
    7462  
    7463 -  elseif a:chg == 4
    7464 -   " u: change to the previous directory stored on the history list
    7465 -"   call Decho("(user: <u>) chg to prev dir from history")
    7466 -   if g:netrw_dirhistmax > 0
    7467 -    let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
    7468 -    if g:netrw_dirhist_cnt < 0
    7469 -     let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
    7470 -    endif
    7471 -   else
    7472 -    let g:netrw_dirhist_cnt= 0
    7473 -   endif
    7474 -   if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
    7475 -"    call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
    7476 -    if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    7477 -     setl ma noro
    7478 -"     call Decho("(NetrwBookHistHandler) setl ma noro")
    7479 -     sil! keepj %d
    7480 -     setl nomod
    7481 -"     call Decho("(NetrwBookHistHandler) setl nomod")
    7482 -"     call Decho("(NetrwBookHistHandler)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    7483 -    endif
    7484 -"    "    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
    7485 -    exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
    7486 -   else
    7487 -    if g:netrw_dirhistmax > 0
    7488 -     let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
    7489 -    else
    7490 -     let g:netrw_dirhist_cnt= 0
    7491 -    endif
    7492 -    echo "Sorry, no predecessor directory exists yet"
    7493 +  " Method#8: fetch {{{3
    7494 +  elseif match(a:choice,fetchurm) == 0
    7495 +"   call Decho("fetch://...")
    7496 +   let b:netrw_method = 8
    7497 +   let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
    7498 +   let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
    7499 +   let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
    7500 +   let b:netrw_fname  = substitute(a:choice,fetchurm,'\5',"")
    7501 +
    7502 +   " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
    7503 +  elseif match(a:choice,mipf) == 0
    7504 +"   call Decho("(ftp) host id pass file")
    7505 +   let b:netrw_method  = 3
    7506 +   let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
    7507 +   let g:netrw_uid     = substitute(a:choice,mipf,'\2',"")
    7508 +   let s:netrw_passwd  = substitute(a:choice,mipf,'\3',"")
    7509 +   let b:netrw_fname   = substitute(a:choice,mipf,'\4',"")
    7510 +   call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
    7511 +
    7512 +  " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
    7513 +  elseif match(a:choice,mf) == 0
    7514 +"   call Decho("(ftp) host file")
    7515 +   if exists("g:netrw_uid") && exists("s:netrw_passwd")
    7516 +    let b:netrw_method  = 3
    7517 +    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
    7518 +    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
    7519 +
    7520 +   elseif s:FileReadable(expand("$HOME/.netrc"))
    7521 +    let b:netrw_method  = 2
    7522 +    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
    7523 +    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
    7524     endif
    7525  
    7526 -  elseif a:chg == 5
    7527 -   " U: change to the subsequent directory stored on the history list
    7528 -"   call Decho("(user: <U>) chg to next dir from history")
    7529 -   if g:netrw_dirhistmax > 0
    7530 -    let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
    7531 -    if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
    7532 -"    call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
    7533 -     if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    7534 -"      call Decho("(NetrwBookHistHandler) setl ma noro")
    7535 -      setl ma noro
    7536 -      sil! keepj %d
    7537 -"      call Decho("removed all lines from buffer (%d)")
    7538 -"      call Decho("(NetrwBookHistHandler) setl nomod")
    7539 -      setl nomod
    7540 -"      call Decho("(set nomod)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    7541 -     endif
    7542 -"    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
    7543 -     exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
    7544 -    else
    7545 -     let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
    7546 -     if g:netrw_dirhist_cnt < 0
    7547 -      let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
    7548 -     endif
    7549 -     echo "Sorry, no successor directory exists yet"
    7550 -    endif
    7551 -   else
    7552 -    let g:netrw_dirhist_cnt= 0
    7553 -    echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
    7554 +  " Method#9: sftp://user@hostname/...path-to-file {{{3
    7555 +  elseif match(a:choice,sftpurm) == 0
    7556 +"   call Decho("sftp://...")
    7557 +   let b:netrw_method = 9
    7558 +   let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
    7559 +   let b:netrw_fname  = substitute(a:choice,sftpurm,'\2',"")
    7560 +
    7561 +  " Method#1: Issue an rcp: hostname:filename"  (this one should be last) {{{3
    7562 +  elseif match(a:choice,rcphf) == 0
    7563 +"   call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">")
    7564 +   let b:netrw_method  = 1
    7565 +   let userid          = substitute(a:choice,rcphf,'\2',"")
    7566 +   let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
    7567 +   let b:netrw_fname   = substitute(a:choice,rcphf,'\4',"")
    7568 +"   call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">")
    7569 +"   call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">")
    7570 +"   call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">")
    7571 +"   call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">")
    7572 +   if userid != ""
    7573 +    let g:netrw_uid= userid
    7574     endif
    7575  
    7576 -  elseif a:chg == 6
    7577 -   " delete the v:count'th bookmark
    7578 -"   call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
    7579 -   let savefile= s:NetrwHome()."/.netrwbook"
    7580 -   if filereadable(savefile)
    7581 -"    call Decho("merge bookmarks (active and file)")
    7582 -    keepj call s:NetrwBookHistSave() " done here to merge bookmarks first
    7583 -"    call Decho("bookmark delete savefile<".savefile.">")
    7584 -    keepj call delete(savefile)
    7585 +  " Cannot Determine Method {{{3
    7586 +  else
    7587 +   if !exists("g:netrw_quiet")
    7588 +    call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
    7589     endif
    7590 -"   call Decho("remove g:netrw_bookmarklist[".(v:count-1)."]")
    7591 -   keepj call remove(g:netrw_bookmarklist,v:count-1)
    7592 -"   call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist))
    7593 +   let b:netrw_method  = -1
    7594    endif
    7595 -  call s:NetrwBookmarkMenu()
    7596 -  call s:NetrwTgtMenu()
    7597 -  let @@= ykeep
    7598 -"  call Dret("s:NetrwBookHistHandler")
    7599 -endfun
    7600 +  "}}}3
    7601  
    7602 -" ---------------------------------------------------------------------
    7603 -" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
    7604 -"                      Sister function: s:NetrwBookHistSave()
    7605 -fun! s:NetrwBookHistRead()
    7606 -"  call Dfunc("s:NetrwBookHistRead()")
    7607 -  if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
    7608 -"   "  call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
    7609 -   return
    7610 +  if g:netrw_port != ""
    7611 +   " remove any leading [:#] from port number
    7612 +   let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
    7613 +  elseif exists("netrw_port")
    7614 +   " retain port number as implicit for subsequent ftp operations
    7615 +   let g:netrw_port= netrw_port
    7616    endif
    7617 -  let ykeep= @@
    7618 -  if !exists("s:netrw_initbookhist")
    7619 -   let home    = s:NetrwHome()
    7620 -   let savefile= home."/.netrwbook"
    7621 -   if filereadable(savefile)
    7622 -"    call Decho("sourcing .netrwbook")
    7623 -    exe "keepalt keepj so ".savefile
    7624 +
    7625 +"  call Decho("a:choice       <".a:choice.">")
    7626 +"  call Decho("b:netrw_method <".b:netrw_method.">")
    7627 +"  call Decho("g:netrw_machine<".g:netrw_machine.">")
    7628 +"  call Decho("g:netrw_port   <".g:netrw_port.">")
    7629 +"  if exists("g:netrw_uid")            "Decho
    7630 +"   call Decho("g:netrw_uid    <".g:netrw_uid.">")
    7631 +"  endif                                       "Decho
    7632 +"  if exists("s:netrw_passwd")         "Decho
    7633 +"   call Decho("s:netrw_passwd <".s:netrw_passwd.">")
    7634 +"  endif                                       "Decho
    7635 +"  call Decho("b:netrw_fname  <".b:netrw_fname.">")
    7636 +"  call Dret("NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
    7637 +endfun
    7638 +
    7639 +" ------------------------------------------------------------------------
    7640 +" NetReadFixup: this sort of function is typically written by the user {{{2
    7641 +"               to handle extra junk that their system's ftp dumps
    7642 +"               into the transfer.  This function is provided as an
    7643 +"               example and as a fix for a Windows 95 problem: in my
    7644 +"               experience, win95's ftp always dumped four blank lines
    7645 +"               at the end of the transfer.
    7646 +if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
    7647 + fun! NetReadFixup(method, line1, line2)
    7648 +"   call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
    7649 +
    7650 +   " sanity checks -- attempt to convert inputs to integers
    7651 +   let method = a:method + 0
    7652 +   let line1  = a:line1 + 0
    7653 +   let line2  = a:line2 + 0
    7654 +   if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
    7655 +"    call Dret("NetReadFixup")
    7656 +    return
    7657     endif
    7658 -   if g:netrw_dirhistmax > 0
    7659 -    let savefile= home."/.netrwhist"
    7660 -    if filereadable(savefile)
    7661 -"    call Decho("sourcing .netrwhist")
    7662 -     exe "keepalt keepj so ".savefile
    7663 +
    7664 +   if method == 3   " ftp (no <.netrc>)
    7665 +    let fourblanklines= line2 - 3
    7666 +    if fourblanklines >= line1
    7667 +     exe "sil keepj ".fourblanklines.",".line2."g/^\s*$/d"
    7668 +     call histdel("/",-1)
    7669      endif
    7670 -    let s:netrw_initbookhist= 1
    7671 -    au VimLeave * call s:NetrwBookHistSave()
    7672     endif
    7673 -  endif
    7674 -  let @@= ykeep
    7675 -"  call Dret("s:NetrwBookHistRead")
    7676 -endfun
    7677 +
    7678 +"   call Dret("NetReadFixup")
    7679 + endfun
    7680 +endif
    7681  
    7682  " ---------------------------------------------------------------------
    7683 -" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
    7684 -"                      Sister function: s:NetrwBookHistRead()
    7685 -"                      I used to do this via viminfo but that appears to
    7686 -"                      be unreliable for long-term storage
    7687 -fun! s:NetrwBookHistSave()
    7688 -"  call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
    7689 -  if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
    7690 -"   call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
    7691 -   return
    7692 -  endif
    7693 +" NetUserPass: set username and password for subsequent ftp transfer {{{2
    7694 +"   Usage:  :call NetUserPass()                               -- will prompt for userid and password
    7695 +"          :call NetUserPass("uid")                   -- will prompt for password
    7696 +"          :call NetUserPass("uid","password")        -- sets global userid and password
    7697 +"          :call NetUserPass("ftp:host")              -- looks up userid and password using hup dictionary
    7698 +"          :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
    7699 +fun! NetUserPass(...)
    7700  
    7701 -  let savefile= s:NetrwHome()."/.netrwhist"
    7702 -  1split
    7703 -  call s:NetrwEnew()
    7704 -  setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
    7705 -  setl nocin noai noci magic nospell nohid wig= noaw
    7706 -  setl ma noro write
    7707 -  if exists("+acd") | setl noacd | endif
    7708 -  sil! keepj keepalt %d
    7709 +" call Dfunc("NetUserPass() a:0=".a:0)
    7710  
    7711 -  " save .netrwhist -- no attempt to merge
    7712 -  sil! keepalt file .netrwhist
    7713 -  call setline(1,"let g:netrw_dirhistmax  =".g:netrw_dirhistmax)
    7714 -  call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
    7715 -  let lastline = line("$")
    7716 -  let cnt      = 1
    7717 -  while cnt <= g:netrw_dirhist_cnt
    7718 -   call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
    7719 -   let cnt= cnt + 1
    7720 -  endwhile
    7721 -  exe "sil! w! ".savefile
    7722 + if !exists('s:netrw_hup')
    7723 +  let s:netrw_hup= {}
    7724 + endif
    7725  
    7726 -  sil keepj %d
    7727 -  if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
    7728 -   " merge and write .netrwbook
    7729 -   let savefile= s:NetrwHome()."/.netrwbook"
    7730 + if a:0 == 0
    7731 +  " case: no input arguments
    7732  
    7733 -   if filereadable(savefile)
    7734 -    let booklist= deepcopy(g:netrw_bookmarklist)
    7735 -    exe "sil keepj keepalt so ".savefile
    7736 -    for bdm in booklist
    7737 -     if index(g:netrw_bookmarklist,bdm) == -1
    7738 -      call add(g:netrw_bookmarklist,bdm)
    7739 -     endif
    7740 -    endfor
    7741 -    call sort(g:netrw_bookmarklist)
    7742 -    exe "sil! w! ".savefile
    7743 -   endif
    7744 +  " change host and username if not previously entered; get new password
    7745 +  if !exists("g:netrw_machine")
    7746 +   let g:netrw_machine= input('Enter hostname: ')
    7747 +  endif
    7748 +  if !exists("g:netrw_uid") || g:netrw_uid == ""
    7749 +   " get username (user-id) via prompt
    7750 +   let g:netrw_uid= input('Enter username: ')
    7751 +  endif
    7752 +  " get password via prompting
    7753 +  let s:netrw_passwd= inputsecret("Enter Password: ")
    7754  
    7755 -   " construct and save .netrwbook
    7756 -   call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
    7757 -   exe "sil! w! ".savefile
    7758 +  " set up hup database
    7759 +  let host = substitute(g:netrw_machine,'\..*$','','')
    7760 +  if !exists('s:netrw_hup[host]')
    7761 +   let s:netrw_hup[host]= {}
    7762    endif
    7763 -  let bgone= bufnr("%")
    7764 -  q!
    7765 -  exe "keepalt ".bgone."bwipe!"
    7766 +  let s:netrw_hup[host].uid    = g:netrw_uid
    7767 +  let s:netrw_hup[host].passwd = s:netrw_passwd
    7768  
    7769 -"  call Dret("s:NetrwBookHistSave")
    7770 -endfun
    7771 + elseif a:0 == 1
    7772 +  " case: one input argument
    7773  
    7774 -" ---------------------------------------------------------------------
    7775 -" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
    7776 -"  list of the contents of a local or remote directory.  It is assumed that the
    7777 -"  g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
    7778 -"  with the requested remote hostname first.
    7779 -fun! s:NetrwBrowse(islocal,dirname)
    7780 -  if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
    7781 -"  call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
    7782 -"  call Decho("(NetrwBrowse) tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
    7783 -  " s:NetrwBrowse: initialize history {{{3
    7784 -  if !exists("s:netrw_initbookhist")
    7785 -   keepj call s:NetrwBookHistRead()
    7786 -  endif
    7787 +  if a:1 =~ '^ftp:'
    7788 +   " get host from ftp:... url
    7789 +   " access userid and password from hup (host-user-passwd) dictionary
    7790 +"   call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)")
    7791 +   let host = substitute(a:1,'^ftp:','','')
    7792 +   let host = substitute(host,'\..*','','')
    7793 +   if exists("s:netrw_hup[host]")
    7794 +    let g:netrw_uid    = s:netrw_hup[host].uid
    7795 +    let s:netrw_passwd = s:netrw_hup[host].passwd
    7796 +"    call Decho("get s:netrw_hup[".host."].uid   <".s:netrw_hup[host].uid.">")
    7797 +"    call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
    7798 +   else
    7799 +    let g:netrw_uid    = input("Enter UserId: ")
    7800 +    let s:netrw_passwd = inputsecret("Enter Password: ")
    7801 +   endif
    7802  
    7803 -  " s:NetrwBrowse: simplify the dirname (especially for ".."s in dirnames) {{{3
    7804 -  if a:dirname !~ '^\a\+://'
    7805 -   let dirname= simplify(a:dirname)
    7806    else
    7807 -   let dirname= a:dirname
    7808 -  endif
    7809 -
    7810 -  if exists("s:netrw_skipbrowse")
    7811 -   unlet s:netrw_skipbrowse
    7812 -"   call Decho("(NetrwBrowse)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    7813 -"   call Dret("s:NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse)
    7814 -   return
    7815 +   " case: one input argument, not an url.  Using it as a new user-id.
    7816 +"   call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)")
    7817 +   if exists("g:netrw_machine")
    7818 +    if g:netrw_machine =~ '[0-9.]\+'
    7819 +     let host= g:netrw_machine
    7820 +    else
    7821 +     let host= substitute(g:netrw_machine,'\..*$','','')
    7822 +    endif
    7823 +   else
    7824 +    let g:netrw_machine= input('Enter hostname: ')
    7825 +   endif
    7826 +   let g:netrw_uid = a:1
    7827 +"   call Decho("set g:netrw_uid= <".g:netrw_uid.">")
    7828 +   if exists("g:netrw_passwd")
    7829 +    " ask for password if one not previously entered
    7830 +    let s:netrw_passwd= g:netrw_passwd
    7831 +   else
    7832 +    let s:netrw_passwd = inputsecret("Enter Password: ")
    7833 +   endif
    7834    endif
    7835  
    7836 -  " s:NetrwBrowse: sanity checks: {{{3
    7837 -  if !exists("*shellescape")
    7838 -   keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
    7839 -"   call Dret("s:NetrwBrowse : missing shellescape()")
    7840 -   return
    7841 -  endif
    7842 -  if !exists("*fnameescape")
    7843 -   keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
    7844 -"   call Dret("s:NetrwBrowse : missing fnameescape()")
    7845 -   return
    7846 +"  call Decho("host<".host.">")
    7847 +  if exists("host")
    7848 +   if !exists('s:netrw_hup[host]')
    7849 +    let s:netrw_hup[host]= {}
    7850 +   endif
    7851 +   let s:netrw_hup[host].uid    = g:netrw_uid
    7852 +   let s:netrw_hup[host].passwd = s:netrw_passwd
    7853    endif
    7854  
    7855 -  " s:NetrwBrowse: save options: {{{3
    7856 -  call s:NetrwOptionSave("w:")                                                                                                           
    7857 + elseif a:0 == 2
    7858 +  let g:netrw_uid    = a:1
    7859 +  let s:netrw_passwd = a:2
    7860  
    7861 -  " s:NetrwBrowse: re-instate any marked files {{{3
    7862 -  if exists("s:netrwmarkfilelist_{bufnr('%')}")
    7863 -"   call Decho("(NetrwBrowse) clearing marked files")
    7864 -   exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
    7865 + elseif a:0 == 3
    7866 +  " enter hostname, user-id, and password into the hup dictionary
    7867 +  let host = substitute(a:1,'^\a\+:','','')
    7868 +  let host = substitute(host,'\..*$','','')
    7869 +  if !exists('s:netrw_hup[host]')
    7870 +   let s:netrw_hup[host]= {}
    7871    endif
    7872 +  let s:netrw_hup[host].uid    = a:2
    7873 +  let s:netrw_hup[host].passwd = a:3
    7874 +  let g:netrw_uid              = s:netrw_hup[host].uid
    7875 +  let s:netrw_passwd           = s:netrw_hup[host].passwd
    7876 +"  call Decho("set s:netrw_hup[".host."].uid   <".s:netrw_hup[host].uid.">")
    7877 +"  call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">")
    7878 + endif
    7879  
    7880 -  if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
    7881 -   " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
    7882 -"   call Decho("(NetrwBrowse) handle w:netrw_acdkeep:")
    7883 -"   call Decho("(NetrwBrowse) keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
    7884 -   exe 'keepj lcd '.fnameescape(dirname)
    7885 -   call s:NetrwSafeOptions()
    7886 -"   call Decho("(NetrwBrowse) getcwd<".getcwd().">")
    7887 +" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
    7888 +endfun
    7889  
    7890 -  elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
    7891 -   " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
    7892 -"   call Decho("(NetrwBrowse) attempt transfer as regular file<".dirname.">")
    7893 +" ===========================================
    7894 +"  Shared Browsing Support:    {{{1
    7895 +" ===========================================
    7896  
    7897 -   " remove any filetype indicator from end of dirname, except for the
    7898 -   " "this is a directory" indicator (/).
    7899 -   " There shouldn't be one of those here, anyway.
    7900 -   let path= substitute(dirname,'[*=@|]\r\=$','','e')
    7901 -"   call Decho("(NetrwBrowse) new path<".path.">")
    7902 -   call s:RemotePathAnalysis(dirname)
    7903 -
    7904 -   " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
    7905 -   keepj mark '
    7906 -   call s:NetrwEnew(dirname)
    7907 -   call s:NetrwSafeOptions()
    7908 -   setl ma noro
    7909 -"   call Decho("(NetrwBrowse) setl ma noro")
    7910 -   let b:netrw_curdir = dirname
    7911 -   let url            = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
    7912 -"   call Decho("(NetrwBrowse) exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
    7913 -   exe "sil! keepj keepalt file ".fnameescape(url)
    7914 -   exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
    7915 -   sil call netrw#NetRead(2,url)
    7916 -   if s:path !~ '.tar.bz2$' && s:path !~ '.tar.gz' && s:path !~ '.tar.xz' && s:path !~ '.txz'
    7917 -    " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
    7918 -    exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
    7919 -   endif
    7920 -
    7921 -   " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
    7922 -   call s:SetBufWinVars()
    7923 -   call s:NetrwOptionRestore("w:")
    7924 -"   call Decho("(NetrwBrowse) setl ma nomod")
    7925 -   setl ma nomod
    7926 -"   call Decho("(NetrwBrowse)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    7927 +" ---------------------------------------------------------------------
    7928 +" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
    7929 +fun! s:ExplorePatHls(pattern)
    7930 +"  call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
    7931 +  let repat= substitute(a:pattern,'^**/\{1,2}','','')
    7932 +"  call Decho("repat<".repat.">")
    7933 +  let repat= escape(repat,'][.\')
    7934 +"  call Decho("repat<".repat.">")
    7935 +  let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
    7936 +"  call Dret("s:ExplorePatHls repat<".repat.">")
    7937 +  return repat
    7938 +endfun
    7939  
    7940 -"   call Dret("s:NetrwBrowse : file<".s:fname.">")
    79415694+" ---------------------------------------------------------------------
    79425695+"  s:NetrwBookHistHandler: {{{2
     
    79525705+  if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
    79535706+"   "  call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
     5707+   return
     5708   endif
     5709 
     5710   let ykeep= @@
     5711@@ -3338,13 +3266,13 @@
     5712 "    call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
     5713     if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
     5714      setl ma noro
     5715-"     call Decho("(NetrwBookHistHandler) setl ma noro")
     5716+"     call Decho("setl ma noro")
     5717      sil! keepj %d
     5718      setl nomod
     5719-"     call Decho("(NetrwBookHistHandler) setl nomod")
     5720-"     call Decho("(NetrwBookHistHandler)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5721+"     call Decho("setl nomod")
     5722+"     call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5723     endif
     5724-"    "    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
     5725+"    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
     5726     exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
     5727    else
     5728     if g:netrw_dirhistmax > 0
     5729@@ -3363,11 +3291,11 @@
     5730     if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
     5731 "    call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
     5732      if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
     5733-"      call Decho("(NetrwBookHistHandler) setl ma noro")
     5734+"      call Decho("setl ma noro")
     5735       setl ma noro
     5736       sil! keepj %d
     5737 "      call Decho("removed all lines from buffer (%d)")
     5738-"      call Decho("(NetrwBookHistHandler) setl nomod")
     5739+"      call Decho("setl nomod")
     5740       setl nomod
     5741 "      call Decho("(set nomod)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5742      endif
     5743@@ -3505,7 +3433,9 @@
     5744 fun! s:NetrwBrowse(islocal,dirname)
     5745   if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
     5746 "  call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
     5747-"  call Decho("(NetrwBrowse) tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
     5748+"  call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
     5749+"  call Dredir("ls!")
     5750+
     5751   " s:NetrwBrowse: initialize history {{{3
     5752   if !exists("s:netrw_initbookhist")
     5753    keepj call s:NetrwBookHistRead()
     5754@@ -3520,8 +3450,8 @@
     5755 
     5756   if exists("s:netrw_skipbrowse")
     5757    unlet s:netrw_skipbrowse
     5758-"   call Decho("(NetrwBrowse)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5759-"   call Dret("s:NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse)
     5760+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">")
     5761+"   call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
    79545762    return
    79555763   endif
    79565764 
    7957 -  " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
    7958 -  call s:UseBufWinVars()
    7959 -
    7960 -  " set up some variables {{{3
    7961 -  let b:netrw_browser_active = 1
    7962 -  let dirname                = dirname
    7963 -  let s:last_sort_by         = g:netrw_sort_by
    7964 -
    7965 -  " set up menu {{{3
    7966 -  keepj call s:NetrwMenu(1)
    7967 -
    7968 -  " get/set-up buffer {{{3
    7969 -  let reusing= s:NetrwGetBuffer(a:islocal,dirname)
    7970 -  " maintain markfile highlighting
    7971 -  if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
     5765@@ -3542,27 +3472,27 @@
     5766 
     5767   " s:NetrwBrowse: re-instate any marked files {{{3
     5768   if exists("s:netrwmarkfilelist_{bufnr('%')}")
     5769-"   call Decho("(NetrwBrowse) clearing marked files")
     5770+"   call Decho("clearing marked files")
     5771    exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
     5772   endif
     5773 
     5774   if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
     5775    " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
     5776-"   call Decho("(NetrwBrowse) handle w:netrw_acdkeep:")
     5777-"   call Decho("(NetrwBrowse) keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
     5778-   exe 'keepj lcd '.fnameescape(dirname)
     5779+"   call Decho("handle w:netrw_acdkeep:")
     5780+"   call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
     5781+   call s:NetrwLcd(dirname)
     5782    call s:NetrwSafeOptions()
     5783-"   call Decho("(NetrwBrowse) getcwd<".getcwd().">")
     5784+"   call Decho("getcwd<".getcwd().">")
     5785 
     5786   elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
     5787    " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
     5788-"   call Decho("(NetrwBrowse) attempt transfer as regular file<".dirname.">")
     5789+"   call Decho("attempt transfer as regular file<".dirname.">")
     5790 
     5791    " remove any filetype indicator from end of dirname, except for the
     5792    " "this is a directory" indicator (/).
     5793    " There shouldn't be one of those here, anyway.
     5794    let path= substitute(dirname,'[*=@|]\r\=$','','e')
     5795-"   call Decho("(NetrwBrowse) new path<".path.">")
     5796+"   call Decho("new path<".path.">")
     5797    call s:RemotePathAnalysis(dirname)
     5798 
     5799    " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
     5800@@ -3570,24 +3500,33 @@
     5801    call s:NetrwEnew(dirname)
     5802    call s:NetrwSafeOptions()
     5803    setl ma noro
     5804-"   call Decho("(NetrwBrowse) setl ma noro")
     5805+"   call Decho("setl ma noro")
     5806    let b:netrw_curdir = dirname
     5807    let url            = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
     5808-"   call Decho("(NetrwBrowse) exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
     5809+"   call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
     5810    exe "sil! keepj keepalt file ".fnameescape(url)
     5811    exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
     5812    sil call netrw#NetRead(2,url)
     5813-   if s:path !~ '.tar.bz2$' && s:path !~ '.tar.gz' && s:path !~ '.tar.xz' && s:path !~ '.txz'
     5814-    " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
     5815+   " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
     5816+"   call Decho("url<".url.">")
     5817+"   call Decho("s:path<".s:path.">")
     5818+"   call Decho("s:fname<".s:fname.">")
     5819+   if s:path =~ '.bz2'
     5820+    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
     5821+   elseif s:path =~ '.gz'
     5822+    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
     5823+   elseif s:path =~ '.gz'
     5824+    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
     5825+   else
     5826     exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
     5827    endif
     5828 
     5829    " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
     5830    call s:SetBufWinVars()
     5831    call s:NetrwOptionRestore("w:")
     5832-"   call Decho("(NetrwBrowse) setl ma nomod")
     5833+"   call Decho("setl ma nomod")
     5834    setl ma nomod
     5835-"   call Decho("(NetrwBrowse)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5836+"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5837 
     5838 "   call Dret("s:NetrwBrowse : file<".s:fname.">")
     5839    return
     5840@@ -3608,28 +3547,31 @@
     5841   let reusing= s:NetrwGetBuffer(a:islocal,dirname)
     5842   " maintain markfile highlighting
     5843   if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
    79725844-"   call Decho("(NetrwBrowse) bufnr(%)=".bufnr('%'))
    79735845-"   call Decho("(NetrwBrowse) exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
    7974 -   exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
    7975 -  else
     5846+"   call Decho("bufnr(%)=".bufnr('%'))
     5847+"   call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
     5848    exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
     5849   else
    79765850-"   call Decho("(NetrwBrowse) 2match none")
    7977 -   2match none
    7978 -  endif
    7979 -  if reusing && line("$") > 1
    7980 -   call s:NetrwOptionRestore("w:")
     5851+"   call Decho("2match none")
     5852    2match none
     5853   endif
     5854   if reusing && line("$") > 1
     5855    call s:NetrwOptionRestore("w:")
    79815856-"   call Decho("(NetrwBrowse) setl noma nomod nowrap")
    7982 -   setl noma nomod nowrap
     5857+"   call Decho("setl noma nomod nowrap")
     5858    setl noma nomod nowrap
    79835859-"   call Decho("(NetrwBrowse) (set noma nomod nowrap)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    7984 -"   call Dret("s:NetrwBrowse : re-using buffer")
    7985 -   return
    7986 -  endif
    7987 +  let ykeep= @@
    7988 +  if a:chg == 0
    7989 +   " bookmark the current directory
    7990 +"   call Decho("(user: <b>) bookmark the current directory")
    7991 +   if !exists("g:netrw_bookmarklist")
    7992 +    let g:netrw_bookmarklist= []
    7993 +   endif
    7994 +   if index(g:netrw_bookmarklist,a:curdir) == -1
    7995 +    " curdir not currently in g:netrw_bookmarklist, so include it
    7996 +    call add(g:netrw_bookmarklist,a:curdir)
    7997 +    call sort(g:netrw_bookmarklist)
    7998 +   endif
    7999 +   echo "bookmarked the current directory"
    8000  
    8001 -  " set b:netrw_curdir to the new directory name {{{3
     5860+"   call Decho("(set noma nomod nowrap)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5861 "   call Dret("s:NetrwBrowse : re-using buffer")
     5862    return
     5863   endif
     5864 
     5865   " set b:netrw_curdir to the new directory name {{{3
    80025866-"  call Decho("(NetrwBrowse) set b:netrw_curdir to the new directory name:  (buf#".bufnr("%").")")
    8003 -  let b:netrw_curdir= dirname
    8004 -  if b:netrw_curdir =~ '[/\\]$'
    8005 -   let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
    8006 -  endif
    8007 -  if b:netrw_curdir == ''
    8008 -   if has("amiga")
    8009 -    " On the Amiga, the empty string connotes the current directory
    8010 -    let b:netrw_curdir= getcwd()
    8011 +  elseif a:chg == 1
    8012 +   " change to the bookmarked directory
    8013 +"   call Decho("(user: <".v:count."gb>) change to the bookmarked directory")
    8014 +   if exists("g:netrw_bookmarklist[v:count-1]")
    8015 +"    call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist))
    8016 +    exe "keepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
    8017     else
    8018 -    " under unix, when the root directory is encountered, the result
    8019 -    " from the preceding substitute is an empty string.
    8020 -    let b:netrw_curdir= '/'
    8021 +    echomsg "Sorry, bookmark#".v:count." doesn't exist!"
    8022     endif
    8023 -  endif
    8024 -  if !a:islocal && b:netrw_curdir !~ '/$'
    8025 -   let b:netrw_curdir= b:netrw_curdir.'/'
    8026 -  endif
     5867+"  call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")")
     5868   let b:netrw_curdir= dirname
     5869   if b:netrw_curdir =~ '[/\\]$'
     5870    let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
     5871   endif
     5872+  if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
     5873+   let b:netrw_curdir= b:netrw_curdir."/"
     5874+  endif
     5875   if b:netrw_curdir == ''
     5876    if has("amiga")
     5877     " On the Amiga, the empty string connotes the current directory
     5878@@ -3643,39 +3585,23 @@
     5879   if !a:islocal && b:netrw_curdir !~ '/$'
     5880    let b:netrw_curdir= b:netrw_curdir.'/'
     5881   endif
    80275882-"  call Decho("(NetrwBrowse) b:netrw_curdir<".b:netrw_curdir.">")
    8028 -
    8029 -  " ------------
    8030 -  " (local only) {{{3
    8031 -  " ------------
    8032 -  if a:islocal
     5883+"  call Decho("b:netrw_curdir<".b:netrw_curdir.">")
     5884 
     5885   " ------------
     5886   " (local only) {{{3
     5887   " ------------
     5888   if a:islocal
    80335889-"   call Decho("(NetrwBrowse) local only:")
    8034 -
    8035 -   " Set up ShellCmdPost handling.  Append current buffer to browselist
    8036 -   call s:LocalFastBrowser()
    8037  
    8038 -  " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
    8039 -   if !g:netrw_keepdir
     5890+"   call Decho("local only:")
     5891 
     5892    " Set up ShellCmdPost handling.  Append current buffer to browselist
     5893    call s:LocalFastBrowser()
     5894 
     5895   " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
     5896    if !g:netrw_keepdir
    80405897-"    call Decho("(NetrwBrowse) handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
    80415898-"    call Decho("(NetrwBrowse) l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
    8042 -    if !exists("&l:acd") || !&l:acd
     5899+"    call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
     5900+"    call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
     5901     if !exists("&l:acd") || !&l:acd
    80435902-"     call Decho('exe keepjumps lcd '.fnameescape(b:netrw_curdir))
    80445903-     try
     
    80585917-      endif
    80595918-     endtry
    8060 -    endif
    8061 +  elseif a:chg == 2
    8062 +"   redraw!
    8063 +   let didwork= 0
    8064 +   " list user's bookmarks
    8065 +"   call Decho("(user: <q>) list user's bookmarks")
    8066 +   if exists("g:netrw_bookmarklist")
    8067 +"    call Decho('list '.len(g:netrw_bookmarklist).' bookmarks')
    8068 +    let cnt= 1
    8069 +    for bmd in g:netrw_bookmarklist
    8070 +"     call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1])
    8071 +     echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
    8072 +     let didwork = 1
    8073 +     let cnt     = cnt + 1
    8074 +    endfor
     5919+     call s:NetrwLcd(b:netrw_curdir)
     5920     endif
    80755921    endif
    80765922 
    8077 -  " --------------------------------
    8078 -  " remote handling: {{{3
    8079 -  " --------------------------------
    8080 -  else
     5923@@ -3683,23 +3609,23 @@
     5924   " remote handling: {{{3
     5925   " --------------------------------
     5926   else
    80815927-"   call Decho("(NetrwBrowse) remote only:")
    8082 -
    8083 -   " analyze dirname and g:netrw_list_cmd {{{3
     5928+"   call Decho("remote only:")
     5929 
     5930    " analyze dirname and g:netrw_list_cmd {{{3
    80845931-"   call Decho("(NetrwBrowse) b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
    8085 -   if dirname =~ "^NetrwTreeListing\>"
    8086 -    let dirname= b:netrw_curdir
     5932+"   call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
     5933    if dirname =~ "^NetrwTreeListing\>"
     5934     let dirname= b:netrw_curdir
    80875935-"    call Decho("(NetrwBrowse) (dirname was <NetrwTreeListing>) dirname<".dirname.">")
    8088 -   elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    8089 -    let dirname= substitute(b:netrw_curdir,'\\','/','g')
    8090 -    if dirname !~ '/$'
    8091 -     let dirname= dirname.'/'
    8092 -    endif
    8093 -    let b:netrw_curdir = dirname
     5936+"    call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
     5937    elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
     5938     let dirname= substitute(b:netrw_curdir,'\\','/','g')
     5939     if dirname !~ '/$'
     5940      let dirname= dirname.'/'
     5941     endif
     5942     let b:netrw_curdir = dirname
    80945943-"    call Decho("(NetrwBrowse) (liststyle is TREELIST) dirname<".dirname.">")
    8095 +   " list directory history
    8096 +   let cnt     = g:netrw_dirhist_cnt
    8097 +   let first   = 1
    8098 +   let histcnt = 0
    8099 +   if g:netrw_dirhistmax > 0
    8100 +    while ( first || cnt != g:netrw_dirhist_cnt )
    8101 +"    call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt)
    8102 +     if exists("g:netrw_dirhist_{cnt}")
    8103 +"     call Decho("Netrw  History#".histcnt.": ".g:netrw_dirhist_{cnt})
    8104 +      echo printf("Netrw  History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
    8105 +      let didwork= 1
    8106 +     endif
    8107 +     let histcnt = histcnt + 1
    8108 +     let first   = 0
    8109 +     let cnt     = ( cnt - 1 ) % g:netrw_dirhistmax
    8110 +     if cnt < 0
    8111 +      let cnt= cnt + g:netrw_dirhistmax
    8112 +     endif
    8113 +    endwhile
     5944+"    call Decho("(liststyle is TREELIST) dirname<".dirname.">")
    81145945    else
    8115 -    let dirname = substitute(dirname,'\\','/','g')
     5946     let dirname = substitute(dirname,'\\','/','g')
    81165947-"    call Decho("(NetrwBrowse) (normal) dirname<".dirname.">")
    8117 +    let g:netrw_dirhist_cnt= 0
    8118 +   endif
    8119 +   if didwork
    8120 +    call inputsave()|call input("Press <cr> to continue")|call inputrestore()
     5948+"    call Decho("(normal) dirname<".dirname.">")
    81215949    endif
    81225950 
    8123 -   let dirpat  = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
    8124 -   if dirname !~ dirpat
    8125 -    if !exists("g:netrw_quiet")
    8126 -     keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
    8127 +  elseif a:chg == 3
    8128 +   " saves most recently visited directories (when they differ)
    8129 +"   call Decho("(browsing) record curdir history")
    8130 +   if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
    8131 +    if g:netrw_dirhistmax > 0
    8132 +     let g:netrw_dirhist_cnt                   = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
    8133 +     let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
     5951    let dirpat  = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
     5952@@ -3708,37 +3634,34 @@
     5953      keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
    81345954     endif
    8135 -    keepj call s:NetrwOptionRestore("w:")
     5955     keepj call s:NetrwOptionRestore("w:")
    81365956-"    call Decho("(NetrwBrowse) setl noma nomod nowrap")
    8137 -    setl noma nomod nowrap
     5957+"    call Decho("setl noma nomod nowrap")
     5958     setl noma nomod nowrap
    81385959-"    call Decho("(NetrwBrowse)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8139 -"    call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
    8140 -    return
    8141 +"    call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
     5960+"    call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5961 "    call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
     5962     return
    81425963    endif
    8143 -   let b:netrw_curdir= dirname
     5964    let b:netrw_curdir= dirname
    81445965-"   call Decho("(NetrwBrowse) b:netrw_curdir<".b:netrw_curdir."> (remote)")
    8145 -  endif  " (additional remote handling)
    8146 -
    8147 -  " -----------------------
    8148 -  " Directory Listing: {{{3
    8149 -  " -----------------------
    8150 -  keepj call s:NetrwMaps(a:islocal)
    8151 -  keepj call s:PerformListing(a:islocal)
    8152 -  if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
     5966+"   call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
     5967   endif  " (additional remote handling)
     5968 
     5969   " -----------------------
     5970   " Directory Listing: {{{3
     5971   " -----------------------
     5972   keepj call s:NetrwMaps(a:islocal)
     5973+  keepj call s:NetrwCommands(a:islocal)
     5974   keepj call s:PerformListing(a:islocal)
     5975   if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
    81535976-   let &l:bexpr= "netrw#NetrwBalloonHelp()"
    81545977-"   call Decho("(NetrwBrowse) set up balloon help: l:bexpr=".&l:bexpr)
    81555978-   set beval
    8156 -  endif
    8157 -  call s:NetrwOptionRestore("w:")
    8158 -
     5979+   let &l:bexpr= "netrw#BalloonHelp()"
     5980+"   call Decho("set up balloon help: l:bexpr=".&l:bexpr)
     5981+   setl beval
     5982   endif
     5983   call s:NetrwOptionRestore("w:")
     5984 
    81595985-  " The s:LocalBrowseShellCmdRefresh() function is called by an autocmd
    8160 -  " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
     5986+  " The s:LocalBrowseRefresh() function is called by an autocmd
     5987   " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
    81615988-  " However, s:NetrwBrowse() causes the ShellCmdPost event itself to fire once; setting
    81625989-  " the variable below avoids that second refresh of the screen.  The s:LocalBrowseShellCmdRefresh()
     
    81645991-  " and skips the refresh and sets s:locbrowseshellcmd to zero. Oct 13, 2008
    81655992-  let s:locbrowseshellcmd= 1
    8166 -
     5993+  " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
     5994 
    81675995-"  call Decho("(NetrwBrowse) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8168 -"  call Dret("s:NetrwBrowse : did PerformListing  ft<".&ft.">")
    8169 -  return
    8170 -endfun
    8171  
    8172 -" ---------------------------------------------------------------------
    8173 -" s:NetrwFileInfo: supports qf (query for file information) {{{2
    8174 -fun! s:NetrwFileInfo(islocal,fname)
     5996+"  call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     5997 "  call Dret("s:NetrwBrowse : did PerformListing  ft<".&ft.">")
     5998   return
     5999 endfun
     6000@@ -3746,20 +3669,33 @@
     6001 " ---------------------------------------------------------------------
     6002 " s:NetrwFileInfo: supports qf (query for file information) {{{2
     6003 fun! s:NetrwFileInfo(islocal,fname)
    81756004-"  call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">)")
    8176 -  let ykeep= @@
    8177 -  if a:islocal
    8178 -   if (has("unix") || has("macunix")) && executable("/bin/ls")
     6005+"  call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
     6006   let ykeep= @@
     6007   if a:islocal
     6008    if (has("unix") || has("macunix")) && executable("/bin/ls")
    81796009-    if exists("b:netrw_curdir")
    81806010-"     call Decho('using ls with b:netrw_curdir<'.b:netrw_curdir.'>')
    8181 -     if b:netrw_curdir =~ '/$'
    8182 -      echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
    8183 -     else
    8184 -      echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
    8185 -     endif
    8186 -    else
    8187 -"     call Decho('using ls '.a:fname." using cwd<".getcwd().">")
    8188 -     echo system("/bin/ls -lsad ".shellescape(a:fname))
    8189 +  elseif a:chg == 4
    8190 +   " u: change to the previous directory stored on the history list
    8191 +"   call Decho("(user: <u>) chg to prev dir from history")
    8192 +   if g:netrw_dirhistmax > 0
    8193 +    let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
    8194 +    if g:netrw_dirhist_cnt < 0
    8195 +     let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
     6011+
     6012+    if getline(".") == "../"
     6013+     echo system("/bin/ls -lsad ".shellescape(".."))
     6014+"     call Decho("#1: echo system(/bin/ls -lsad ".shellescape(..).")")
     6015+
     6016+    elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
     6017+     echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir))
     6018+"     call Decho("#2: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir).")")
     6019+
     6020+    elseif exists("b:netrw_curdir")
     6021      if b:netrw_curdir =~ '/$'
     6022       echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
     6023+"      call Decho("#3: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname).")")
     6024+
     6025      else
     6026       echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
     6027+"      call Decho("#4: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname).")")
     6028      endif
     6029+
     6030     else
     6031 "     call Decho('using ls '.a:fname." using cwd<".getcwd().">")
     6032      echo system("/bin/ls -lsad ".shellescape(a:fname))
     6033+"     call Decho("#5: echo system(/bin/ls -lsad ".shellescape(a:fname).")")
    81966034     endif
    81976035    else
    8198 -    " use vim functions to return information about file below cursor
    8199 -"    call Decho("using vim functions to query for file info")
    8200 -    if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
    8201 -     let fname= substitute(a:fname,".$","","")
    8202 +    let g:netrw_dirhist_cnt= 0
    8203 +   endif
    8204 +   if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
    8205 +"    call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
    8206 +    if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    8207 +     setl ma noro
    8208 +"     call Decho("setl ma noro")
    8209 +     sil! keepj %d
    8210 +     setl nomod
    8211 +"     call Decho("setl nomod")
    8212 +"     call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8213 +    endif
    8214 +"    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
    8215 +    exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
    8216 +   else
    8217 +    if g:netrw_dirhistmax > 0
    8218 +     let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
    8219      else
    8220 -     let fname= a:fname
    8221 -    endif
    8222 -    let t  = getftime(fname)
    8223 -    let sz = getfsize(fname)
    8224 -    echo a:fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname))
     6036     " use vim functions to return information about file below cursor
     6037@@ -3772,7 +3708,7 @@
     6038     let t  = getftime(fname)
     6039     let sz = getfsize(fname)
     6040     echo a:fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname))
    82256041-"    call Decho(fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname)))
    8226 -   endif
    8227 -  else
    8228 -   echo "sorry, \"qf\" not supported yet for remote files"
    8229 -  endif
    8230 -  let @@= ykeep
    8231 -"  call Dret("s:NetrwFileInfo")
    8232 -endfun
    8233 -
    8234 -" ---------------------------------------------------------------------
    8235 -" s:NetrwGetBuffer: {{{2
    8236 -"   returns 0=cleared buffer
    8237 -"           1=re-used buffer
    8238 -fun! s:NetrwGetBuffer(islocal,dirname)
    8239 -"  call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
     6042+"    call Decho("fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname)))
     6043    endif
     6044   else
     6045    echo "sorry, \"qf\" not supported yet for remote files"
     6046@@ -3787,40 +3723,42 @@
     6047 "           1=re-used buffer
     6048 fun! s:NetrwGetBuffer(islocal,dirname)
     6049 "  call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
    82406050-"  call Decho("(NetrwGetBuffer) modiable=".&mod." modifiable=".&ma." readonly=".&ro)
    8241 -  let dirname= a:dirname
    8242 -
    8243 -  " re-use buffer if possible {{{3
     6051+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6052   let dirname= a:dirname
     6053 
     6054   " re-use buffer if possible {{{3
    82446055-"  call Decho("(NetrwGetBuffer) --re-use a buffer if possible--")
    8245 -  if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
    8246 -   " find NetrwTreeList buffer if there is one
     6056+"  call Decho("--re-use a buffer if possible--")
     6057   if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
     6058    " find NetrwTreeList buffer if there is one
    82476059-"   call Decho("(NetrwGetBuffer) case liststyle=treelist: find NetrwTreeList buffer if there is one")
    8248 -   if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
     6060+"   call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
     6061    if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
    82496062-"    call Decho("(NetrwGetBuffer)   re-using w:netrw_treebufnr=".w:netrw_treebufnr)
    82506063-    setl mod
    82516064-    sil! keepj %d
    8252 -    let eikeep= &ei
     6065+"    call Decho("  re-using w:netrw_treebufnr=".w:netrw_treebufnr)
     6066     let eikeep= &ei
    82536067-    set ei=all
    82546068-    exe "sil! keepalt b ".w:netrw_treebufnr
    8255 -    let &ei= eikeep
    8256 -"    call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
    8257 -    return 0
    8258 -   endif
    8259 -   let bufnum= -1
     6069+    setl ei=all
     6070+    exe "sil! noswapfile keepalt b ".w:netrw_treebufnr
     6071     let &ei= eikeep
     6072+    setl ma
     6073+    sil! keepj %d
     6074+"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6075 "    call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
     6076     return 0
     6077    endif
     6078    let bufnum= -1
    82606079-"   call Decho("(NetrwGetBuffer)   liststyle=TREE but w:netrw_treebufnr doesn't exist")
    8261 -
    8262 -  else
    8263 -   " find buffer number of buffer named precisely the same as dirname {{{3
     6080+"   call Decho("  liststyle=TREE but w:netrw_treebufnr doesn't exist")
     6081 
     6082   else
     6083    " find buffer number of buffer named precisely the same as dirname {{{3
    82646084-"   call Decho("(NetrwGetBuffer) case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
    8265 -
    8266 -   " get dirname and associated buffer number
    8267 -   let bufnum  = bufnr(escape(dirname,'\'))
     6085+"   call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
     6086+"   call Dredir("(NetrwGetBuffer) ls!","ls!")
     6087 
     6088    " get dirname and associated buffer number
     6089    let bufnum  = bufnr(escape(dirname,'\'))
    82686090-"   call Decho("(NetrwGetBuffer)   find buffer<".dirname.">'s number ")
    82696091-"   call Decho("(NetrwGetBuffer)   bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
    8270 -
    8271 -   if bufnum < 0 && dirname !~ '/$'
    8272 -    " try appending a trailing /
     6092+"   call Decho("  find buffer<".dirname.">'s number ")
     6093+"   call Decho("  bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
     6094 
     6095    if bufnum < 0 && dirname !~ '/$'
     6096     " try appending a trailing /
    82736097-"    call Decho("(NetrwGetBuffer)   try appending a trailing / to dirname<".dirname.">")
    8274 -    let bufnum= bufnr(escape(dirname.'/','\'))
    8275 -    if bufnum > 0
    8276 -     let dirname= dirname.'/'
    8277 -    endif
    8278 -   endif
    8279 -
    8280 -   if bufnum < 0 && dirname =~ '/$'
    8281 -    " try removing a trailing /
     6098+"    call Decho("  try appending a trailing / to dirname<".dirname.">")
     6099     let bufnum= bufnr(escape(dirname.'/','\'))
     6100     if bufnum > 0
     6101      let dirname= dirname.'/'
     6102@@ -3829,30 +3767,30 @@
     6103 
     6104    if bufnum < 0 && dirname =~ '/$'
     6105     " try removing a trailing /
    82826106-"    call Decho("(NetrwGetBuffer)   try removing a trailing / from dirname<".dirname.">")
    8283 -    let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
    8284 -    if bufnum > 0
    8285 -     let dirname= substitute(dirname,'/$','','')
    8286 +     let g:netrw_dirhist_cnt= 0
     6107+"    call Decho("  try removing a trailing / from dirname<".dirname.">")
     6108     let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
     6109     if bufnum > 0
     6110      let dirname= substitute(dirname,'/$','','')
    82876111     endif
    8288 +    echo "Sorry, no predecessor directory exists yet"
    82896112    endif
    82906113 
    82916114-"   call Decho("(NetrwGetBuffer)   findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
    8292 -   " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/  and abc/ matches)
    8293 -   if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
    8294 -    " handle approximate matches
     6115+"   call Decho("  findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
     6116    " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/  and abc/ matches)
     6117    if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
     6118     " handle approximate matches
    82956119-"    call Decho("(NetrwGetBuffer)   handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
    8296 -    let ibuf    = 1
    8297 -    let buflast = bufnr("$")
     6120+"    call Decho("  handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
     6121     let ibuf    = 1
     6122     let buflast = bufnr("$")
    82986123-"    call Decho("(NetrwGetBuffer)   findbuf2: buflast=bufnr($)=".buflast)
    8299 -    while ibuf <= buflast
    8300 -     let bname= substitute(bufname(ibuf),'\\','/','g')
    8301 -     let bname= substitute(bname,'.\zs/$','','')
     6124+"    call Decho("  findbuf2: buflast=bufnr($)=".buflast)
     6125     while ibuf <= buflast
     6126      let bname= substitute(bufname(ibuf),'\\','/','g')
     6127      let bname= substitute(bname,'.\zs/$','','')
    83026128-"     call Decho("(NetrwGetBuffer)   findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
    8303 -     if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
    8304 -      " bname is not empty
    8305 -      " dirname ends with bname,
    8306 -      " dirname doesn't start with /, so its not a absolute path
     6129+"     call Decho("  findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
     6130      if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
     6131       " bname is not empty
     6132       " dirname ends with bname,
     6133       " dirname doesn't start with /, so its not a absolute path
    83076134-"      call Decho("(NetrwGetBuffer)   findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
    8308 -      break
    8309 -     endif
    8310 -     if bname =~ '^'.dirname.'/\=$'
    8311 -      " bname begins with dirname
    8312 -"      call Decho('  findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
    8313 -      break
    8314 -     endif
    8315 -     if dirname =~ '^'.bname.'/$'
    8316 -"      call Decho('  findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
    8317 -      break
    8318 -     endif
    8319 -     if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
    8320 -"      call Decho('  findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
    8321 -      break
    8322 +  elseif a:chg == 5
    8323 +   " U: change to the subsequent directory stored on the history list
    8324 +"   call Decho("(user: <U>) chg to next dir from history")
    8325 +   if g:netrw_dirhistmax > 0
    8326 +    let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
    8327 +    if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
    8328 +"    call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">")
    8329 +     if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    8330 +"      call Decho("setl ma noro")
    8331 +      setl ma noro
    8332 +      sil! keepj %d
    8333 +"      call Decho("removed all lines from buffer (%d)")
    8334 +"      call Decho("setl nomod")
    8335 +      setl nomod
    8336 +"      call Decho("(set nomod)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     6135+"      call Decho("  findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
     6136       break
    83376137      endif
    8338 -     let ibuf= ibuf + 1
    8339 -    endwhile
    8340 -    if ibuf > buflast
    8341 -     let bufnum= -1
    8342 -    else
    8343 -     let bufnum= ibuf
    8344 -    endif
     6138      if bname =~ '^'.dirname.'/\=$'
     6139@@ -3875,79 +3813,83 @@
     6140     else
     6141      let bufnum= ibuf
     6142     endif
    83456143-"    call Decho("(NetrwGetBuffer)   findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
    8346 -   endif
    8347 -  endif
    8348 -
    8349 -  " get enew buffer and name it -or- re-use buffer {{{3
     6144+"    call Decho("  findbuf4: bufnum=".bufnum." (ibuf=".ibuf." buflast=".buflast.")")
     6145    endif
     6146   endif
     6147 
     6148   " get enew buffer and name it -or- re-use buffer {{{3
    83506149-"  call Decho("(NetrwGetBuffer)   get enew buffer and name it OR re-use buffer")
    8351 -  sil! keepj keepalt mark '
    8352 -  if bufnum < 0 || !bufexists(bufnum)
     6150+"  call Decho("  get enew buffer and name it OR re-use buffer")
     6151   sil! keepj keepalt mark '
     6152   if bufnum < 0 || !bufexists(bufnum)
    83536153-"   call Decho("(NetrwGetBuffer) --get enew buffer and name it  (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
    8354 -   call s:NetrwEnew(dirname)
     6154+"   call Decho("--get enew buffer and name it  (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)")
     6155    call s:NetrwEnew(dirname)
    83556156-"   call Decho("(NetrwGetBuffer)   got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
    8356 -   " name the buffer
    8357 -   if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
    8358 -    " Got enew buffer; transform into a NetrwTreeListing
     6157+"   call Decho("  got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)")
     6158    " name the buffer
     6159    if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
     6160     " Got enew buffer; transform into a NetrwTreeListing
    83596161-"    call Decho("(NetrwGetBuffer) --transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
    8360 -    if !exists("s:netrw_treelistnum")
    8361 -     let s:netrw_treelistnum= 1
    8362 +"    call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}))
    8363 +     exe "keepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
     6162+"    call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --")
     6163     if !exists("s:netrw_treelistnum")
     6164      let s:netrw_treelistnum= 1
    83646165     else
    8365 -     let s:netrw_treelistnum= s:netrw_treelistnum + 1
    8366 +     let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
    8367 +     if g:netrw_dirhist_cnt < 0
    8368 +      let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
    8369 +     endif
    8370 +     echo "Sorry, no successor directory exists yet"
     6166      let s:netrw_treelistnum= s:netrw_treelistnum + 1
    83716167     endif
    8372 -    let w:netrw_treebufnr= bufnr("%")
     6168     let w:netrw_treebufnr= bufnr("%")
    83736169-"    call Decho("(NetrwGetBuffer)   exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
    8374 -    exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
     6170+"    call Decho("  exe sil! keepalt file NetrwTreeListing ".fnameescape(s:netrw_treelistnum))
     6171     exe 'sil! keepalt file NetrwTreeListing\ '.fnameescape(s:netrw_treelistnum)
    83756172-    set bt=nofile noswf
    8376 -    nnoremap <silent> <buffer> [       :sil call <SID>TreeListMove('[')<cr>
    8377 -    nnoremap <silent> <buffer> ]       :sil call <SID>TreeListMove(']')<cr>
    8378 -    nnoremap <silent> <buffer> [[       :sil call <SID>TreeListMove('[')<cr>
    8379 -    nnoremap <silent> <buffer> ]]       :sil call <SID>TreeListMove(']')<cr>
     6173+    setl bt=nofile noswf
     6174     nnoremap <silent> <buffer> [       :sil call <SID>TreeListMove('[')<cr>
     6175     nnoremap <silent> <buffer> ]       :sil call <SID>TreeListMove(']')<cr>
     6176     nnoremap <silent> <buffer> [[       :sil call <SID>TreeListMove('[')<cr>
     6177     nnoremap <silent> <buffer> ]]       :sil call <SID>TreeListMove(']')<cr>
    83806178-"    call Decho("(NetrwGetBuffer)   tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
     6179+"    call Decho("  tree listing#".s:netrw_treelistnum." bufnr=".w:netrw_treebufnr)
    83816180    else
    8382 -"    let v:errmsg= "" " Decho
    8383 -    let escdirname= fnameescape(dirname)
     6181 "    let v:errmsg= "" " Decho
     6182     let escdirname= fnameescape(dirname)
    83846183-"    call Decho("(NetrwGetBuffer)   errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
    8385 -"    call Decho('  exe sil! keepalt file '.escdirname)
    8386 -"    let v:errmsg= "" " Decho
    8387 -    exe 'sil! keepalt file '.escdirname
     6184+"    call Decho("  errmsg<".v:errmsg."> bufnr(escdirname<".escdirname.">)=".bufnr(escdirname)." bufname()<".bufname(bufnr(escdirname)).">")
     6185 "    call Decho('  exe sil! keepalt file '.escdirname)
     6186 "    let v:errmsg= "" " Decho
     6187     exe 'sil! keepalt file '.escdirname
    83886188-"    call Decho("(NetrwGetBuffer)   errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
    8389 +    let g:netrw_dirhist_cnt= 0
    8390 +    echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
     6189+"    call Decho("  errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">")
    83916190    endif
    83926191-"   call Decho("(NetrwGetBuffer)   named enew buffer#".bufnr("%")."<".bufname("%").">")
    8393  
    8394 -  else " Re-use the buffer
     6192+"   call Decho("  named enew buffer#".bufnr("%")."<".bufname("%").">")
     6193 
     6194   else " Re-use the buffer
    83956195-"   call Decho("(NetrwGetBuffer) --re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
    8396 -   let eikeep= &ei
     6196+"   call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)")
     6197    let eikeep= &ei
    83976198-   set ei=all
    8398 -   if getline(2) =~ '^" Netrw Directory Listing'
     6199+   setl ei=all
     6200    if getline(2) =~ '^" Netrw Directory Listing'
    83996201-"    call Decho("(NetrwGetBuffer)   getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
    84006202-    exe "sil! keepalt b ".bufnum
    8401 -   else
     6203+"    call Decho("  getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum)
     6204+    exe "sil! noswapfile keepalt b ".bufnum
     6205    else
    84026206-"    call Decho("(NetrwGetBuffer)   getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
    84036207-    exe "sil! keepalt b ".bufnum
    8404 -   endif
    8405 -   if bufname("%") == '.'
     6208+"    call Decho("  getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum)
     6209+    exe "sil! noswapfile keepalt b ".bufnum
     6210    endif
     6211    if bufname("%") == '.'
    84066212-"    call Decho("(NetrwGetBuffer) exe sil! keepalt file ".fnameescape(getcwd()))
    8407 -    exe "sil! keepalt file ".fnameescape(getcwd())
    8408 -   endif
    8409 -   let &ei= eikeep
    8410 -   if line("$") <= 1
    8411 -    keepj call s:NetrwListSettings(a:islocal)
    8412 -"    call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
    8413 -    return 0
    8414 -   elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
    8415 -    keepj call s:NetrwListSettings(a:islocal)
    8416 -    sil keepj %d
    8417 -"    call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
    8418 -    return 0
    8419 -   elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
     6213+"    call Decho("exe sil! keepalt file ".fnameescape(getcwd()))
     6214     exe "sil! keepalt file ".fnameescape(getcwd())
     6215    endif
     6216    let &ei= eikeep
     6217    if line("$") <= 1
     6218     keepj call s:NetrwListSettings(a:islocal)
     6219+"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6220 "    call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
     6221     return 0
     6222    elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
     6223     keepj call s:NetrwListSettings(a:islocal)
     6224     sil keepj %d
     6225+"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6226 "    call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
     6227     return 0
     6228    elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
    84206229-"    call Decho("(NetrwGetBuffer) --re-use tree listing--")
    84216230-"    call Decho("(NetrwGetBuffer)   clear buffer<".expand("%")."> with :%d")
    8422 -    sil keepj %d
    8423 -    keepj call s:NetrwListSettings(a:islocal)
    8424 -"    call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
    8425 -    return 0
    8426 -   else
    8427 -"    call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
    8428 -    return 1
    8429 +  elseif a:chg == 6
    8430 +   " delete the v:count'th bookmark
    8431 +"   call Decho("delete bookmark#".v:count."<".g:netrw_bookmarklist[v:count-1].">")
    8432 +   let savefile= s:NetrwHome()."/.netrwbook"
    8433 +   if filereadable(savefile)
    8434 +"    call Decho("merge bookmarks (active and file)")
    8435 +    keepj call s:NetrwBookHistSave() " done here to merge bookmarks first
    8436 +"    call Decho("bookmark delete savefile<".savefile.">")
    8437 +    keepj call delete(savefile)
     6231+"    call Decho("--re-use tree listing--")
     6232+"    call Decho("  clear buffer<".expand("%")."> with :%d")
     6233     sil keepj %d
     6234     keepj call s:NetrwListSettings(a:islocal)
     6235+"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6236 "    call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
     6237     return 0
     6238    else
     6239+"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6240 "    call Dret("s:NetrwGetBuffer 1<buffer not cleared> : buf#".bufnr("%"))
     6241     return 1
    84386242    endif
    8439 +"   call Decho("remove g:netrw_bookmarklist[".(v:count-1)."]")
    8440 +   keepj call remove(g:netrw_bookmarklist,v:count-1)
    8441 +"   call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist))
    8442    endif
    8443 -
    8444 -  " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
    8445 -  "     fastbrowse  Local  Remote   Hiding a buffer implies it may be re-used (fast)
    8446 -  "  slow   0         D      D      Deleting a buffer implies it will not be re-used (slow)
    8447 -  "  med    1         D      H
    8448 -  "  fast   2         H      H
     6243@@ -3958,18 +3900,19 @@
     6244   "  slow   0         D      D      Deleting a buffer implies it will not be re-used (slow)
     6245   "  med    1         D      H
     6246   "  fast   2         H      H
    84496247-"  call Decho("(NetrwGetBuffer) --do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
    8450 -  let fname= expand("%")
    8451 -  keepj call s:NetrwListSettings(a:islocal)
     6248+"  call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--")
     6249   let fname= expand("%")
     6250   keepj call s:NetrwListSettings(a:islocal)
    84526251-"  call Decho("(NetrwGetBuffer) exe sil! keepalt file ".fnameescape(fname))
    8453 -  exe "sil! keepj keepalt file ".fnameescape(fname)
    8454 -
    8455 -  " delete all lines from buffer {{{3
     6252+"  call Decho("exe sil! keepalt file ".fnameescape(fname))
     6253   exe "sil! keepj keepalt file ".fnameescape(fname)
     6254 
     6255   " delete all lines from buffer {{{3
    84566256-"  call Decho("(NetrwGetBuffer) --delete all lines from buffer--")
    84576257-"  call Decho("(NetrwGetBuffer)   clear buffer<".expand("%")."> with :%d")
    8458 -  sil! keepalt keepj %d
    8459 -
     6258+"  call Decho("--delete all lines from buffer--")
     6259+"  call Decho("  clear buffer<".expand("%")."> with :%d")
     6260   sil! keepalt keepj %d
     6261 
    84606262-"  call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
    8461 -  return 0
    8462 +  call s:NetrwBookmarkMenu()
    8463 +  call s:NetrwTgtMenu()
    8464 +  let @@= ykeep
    8465 +"  call Dret("s:NetrwBookHistHandler")
     6263+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6264+"  call Dret("s:NetrwGetBuffer 0<cleared buffer> : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%"))
     6265   return 0
    84666266 endfun
    84676267 
    8468  " ---------------------------------------------------------------------
    8469 -" s:NetrwGetcwd: get the current directory. {{{2
    8470 -"   Change backslashes to forward slashes, if any.
    8471 -"   If doesc is true, escape certain troublesome characters
    8472 -fun! s:NetrwGetcwd(doesc)
    8473 -"  call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
    8474 -  let curdir= substitute(getcwd(),'\\','/','ge')
    8475 -  if curdir !~ '[\/]$'
    8476 -   let curdir= curdir.'/'
    8477 +" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
    8478 +"                      Sister function: s:NetrwBookHistSave()
    8479 +fun! s:NetrwBookHistRead()
    8480 +"  call Dfunc("s:NetrwBookHistRead()")
    8481 +  if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
    8482 +"   "  call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
    8483 +   return
    8484    endif
    8485 -  if a:doesc
    8486 -   let curdir= fnameescape(curdir)
    8487 +  let ykeep= @@
    8488 +  if !exists("s:netrw_initbookhist")
    8489 +   let home    = s:NetrwHome()
    8490 +   let savefile= home."/.netrwbook"
    8491 +   if filereadable(savefile)
    8492 +"    call Decho("sourcing .netrwbook")
    8493 +    exe "keepalt keepj so ".savefile
    8494 +   endif
    8495 +   if g:netrw_dirhistmax > 0
    8496 +    let savefile= home."/.netrwhist"
    8497 +    if filereadable(savefile)
    8498 +"    call Decho("sourcing .netrwhist")
    8499 +     exe "keepalt keepj so ".savefile
    8500 +    endif
    8501 +    let s:netrw_initbookhist= 1
    8502 +    au VimLeave * call s:NetrwBookHistSave()
    8503 +   endif
    8504    endif
    8505 -"  call Dret("NetrwGetcwd <".curdir.">")
    8506 -  return curdir
    8507 +  let @@= ykeep
    8508 +"  call Dret("s:NetrwBookHistRead")
    8509  endfun
    8510  
    8511  " ---------------------------------------------------------------------
    8512 -"  s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
    8513 -fun! s:NetrwGetWord()
    8514 -"  call Dfunc("s:NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol("."))
    8515 -  call s:UseBufWinVars()
    8516 -
    8517 -  " insure that w:netrw_liststyle is set up
    8518 -  if !exists("w:netrw_liststyle")
    8519 -   if exists("g:netrw_liststyle")
    8520 -    let w:netrw_liststyle= g:netrw_liststyle
    8521 -   else
    8522 -    let w:netrw_liststyle= s:THINLIST
    8523 -   endif
    8524 -"   call Decho("w:netrw_liststyle=".w:netrw_liststyle)
    8525 +" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
    8526 +"                      Sister function: s:NetrwBookHistRead()
    8527 +"                      I used to do this via viminfo but that appears to
    8528 +"                      be unreliable for long-term storage
    8529 +fun! s:NetrwBookHistSave()
    8530 +"  call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
    8531 +  if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
    8532 +"   call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
    8533 +   return
    8534    endif
    8535  
    8536 -  if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
    8537 -   " Active Banner support
    8538 -"   call Decho("active banner handling")
    8539 -   keepj norm! 0
    8540 -   let dirname= "./"
    8541 -   let curline= getline('.')
    8542 -
    8543 -   if curline =~ '"\s*Sorted by\s'
    8544 -    keepj norm s
    8545 -    let s:netrw_skipbrowse= 1
    8546 -    echo 'Pressing "s" also works'
    8547 -
    8548 -   elseif curline =~ '"\s*Sort sequence:'
    8549 -    let s:netrw_skipbrowse= 1
    8550 -    echo 'Press "S" to edit sorting sequence'
    8551 +  let savefile= s:NetrwHome()."/.netrwhist"
    8552 +  1split
    8553 +  call s:NetrwEnew()
    8554 +  setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
    8555 +  setl nocin noai noci magic nospell nohid wig= noaw
    8556 +  setl ma noro write
    8557 +  if exists("+acd") | setl noacd | endif
    8558 +  sil! keepj keepalt %d
    8559  
    8560 -   elseif curline =~ '"\s*Quick Help:'
    8561 -    keepj norm ?
    8562 -    let s:netrw_skipbrowse= 1
    8563 -    echo 'Pressing "?" also works'
    8564 +  " save .netrwhist -- no attempt to merge
    8565 +  sil! keepalt file .netrwhist
    8566 +  call setline(1,"let g:netrw_dirhistmax  =".g:netrw_dirhistmax)
    8567 +  call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
    8568 +  let lastline = line("$")
    8569 +  let cnt      = 1
    8570 +  while cnt <= g:netrw_dirhist_cnt
    8571 +   call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
    8572 +   let cnt= cnt + 1
    8573 +  endwhile
    8574 +  exe "sil! w! ".savefile
    8575  
    8576 -   elseif curline =~ '"\s*\%(Hiding\|Showing\):'
    8577 -    keepj norm a
    8578 -    let s:netrw_skipbrowse= 1
    8579 -    echo 'Pressing "a" also works'
    8580 +  sil keepj %d
    8581 +  if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
    8582 +   " merge and write .netrwbook
    8583 +   let savefile= s:NetrwHome()."/.netrwbook"
    8584  
    8585 -   elseif line("$") > w:netrw_bannercnt
    8586 -    exe 'sil keepj '.w:netrw_bannercnt
    8587 +   if filereadable(savefile)
    8588 +    let booklist= deepcopy(g:netrw_bookmarklist)
    8589 +    exe "sil keepj keepalt so ".savefile
    8590 +    for bdm in booklist
    8591 +     if index(g:netrw_bookmarklist,bdm) == -1
    8592 +      call add(g:netrw_bookmarklist,bdm)
    8593 +     endif
    8594 +    endfor
    8595 +    call sort(g:netrw_bookmarklist)
    8596 +    exe "sil! w! ".savefile
    8597     endif
    8598  
    8599 -  elseif w:netrw_liststyle == s:THINLIST
    8600 -"   call Decho("thin column handling")
    8601 -   keepj norm! 0
    8602 -   let dirname= getline('.')
    8603 -
    8604 -  elseif w:netrw_liststyle == s:LONGLIST
    8605 -"   call Decho("long column handling")
    8606 -   keepj norm! 0
    8607 -   let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
    8608 +   " construct and save .netrwbook
    8609 +   call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
    8610 +   exe "sil! w! ".savefile
    8611 +  endif
    8612 +  let bgone= bufnr("%")
    8613 +  q!
    8614 +  exe "keepalt ".bgone."bwipe!"
    8615  
    8616 -  elseif w:netrw_liststyle == s:TREELIST
    8617 -"   call Decho("treelist handling")
     6268@@ -4048,7 +3991,7 @@
     6269 
     6270   elseif w:netrw_liststyle == s:TREELIST
     6271 "   call Decho("treelist handling")
    86186272-   let dirname= substitute(getline('.'),'^\(| \)*','','e')
    8619 +"  call Dret("s:NetrwBookHistSave")
    8620 +endfun
    8621  
    8622 -  else
    8623 -"   call Decho("obtain word from wide listing")
    8624 -   let dirname= getline('.')
    8625 +" ---------------------------------------------------------------------
    8626 +" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
    8627 +"  list of the contents of a local or remote directory.  It is assumed that the
    8628 +"  g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
    8629 +"  with the requested remote hostname first.
    8630 +fun! s:NetrwBrowse(islocal,dirname)
    8631 +  if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
    8632 +"  call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
    8633 +"  call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")." modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
    8634 +"  call Dredir("ls!")
    8635  
    8636 -   if !exists("b:netrw_cpf")
    8637 -    let b:netrw_cpf= 0
    8638 -    exe 'sil keepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
    8639 -    call histdel("/",-1)
    8640 -"   call Decho("computed cpf=".b:netrw_cpf)
    8641 -   endif
    8642 +  " s:NetrwBrowse: initialize history {{{3
    8643 +  if !exists("s:netrw_initbookhist")
    8644 +   keepj call s:NetrwBookHistRead()
    8645 +  endif
    8646  
    8647 -"   call Decho("buf#".bufnr("%")."<".bufname("%").">")
    8648 -   let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
    8649 -"   call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart."  bannercnt=".w:netrw_bannercnt)
    8650 -"   call Decho("1: dirname<".dirname.">")
    8651 -   if filestart == 0
    8652 -    keepj norm! 0ma
    8653 -   else
    8654 -    call cursor(line("."),filestart+1)
    8655 -    keepj norm! ma
    8656 -   endif
    8657 -   let rega= @a
    8658 -   let eofname= filestart + b:netrw_cpf + 1
    8659 -   if eofname <= col("$")
    8660 -    call cursor(line("."),filestart+b:netrw_cpf+1)
    8661 -    keepj norm! "ay`a
    8662 -   else
    8663 -    keepj norm! "ay$
    8664 -   endif
    8665 -   let dirname = @a
    8666 -   let @a      = rega
    8667 -"   call Decho("2: dirname<".dirname.">")
    8668 -   let dirname= substitute(dirname,'\s\+$','','e')
    8669 -"   call Decho("3: dirname<".dirname.">")
    8670 +  " s:NetrwBrowse: simplify the dirname (especially for ".."s in dirnames) {{{3
    8671 +  if a:dirname !~ '^\a\+://'
    8672 +   let dirname= simplify(a:dirname)
    8673 +  else
    8674 +   let dirname= a:dirname
    8675    endif
    8676  
    8677 -  " symlinks are indicated by a trailing "@".  Remove it before further processing.
    8678 -  let dirname= substitute(dirname,"@$","","")
    8679 +  if exists("s:netrw_skipbrowse")
    8680 +   unlet s:netrw_skipbrowse
    8681 +"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">")
    8682 +"   call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
    8683 +   return
    8684 +  endif
    8685  
    8686 -  " executables are indicated by a trailing "*".  Remove it before further processing.
    8687 -  let dirname= substitute(dirname,"\*$","","")
    8688 +  " s:NetrwBrowse: sanity checks: {{{3
    8689 +  if !exists("*shellescape")
    8690 +   keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
    8691 +"   call Dret("s:NetrwBrowse : missing shellescape()")
    8692 +   return
    8693 +  endif
    8694 +  if !exists("*fnameescape")
    8695 +   keepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
    8696 +"   call Dret("s:NetrwBrowse : missing fnameescape()")
    8697 +   return
    8698 +  endif
    8699  
    8700 -"  call Dret("s:NetrwGetWord <".dirname.">")
    8701 -  return dirname
    8702 -endfun
    8703 +  " s:NetrwBrowse: save options: {{{3
    8704 +  call s:NetrwOptionSave("w:")                                                                                                           
    8705  
    8706 -" ---------------------------------------------------------------------
    8707 -" s:NetrwListSettings: make standard settings for a netrw listing {{{2
    8708 -fun! s:NetrwListSettings(islocal)
    8709 -"  call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
    8710 -  let fname= bufname("%")
     6273+   let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
     6274 
     6275   else
     6276 "   call Decho("obtain word from wide listing")
     6277@@ -4100,14 +4043,16 @@
     6278 " s:NetrwListSettings: make standard settings for a netrw listing {{{2
     6279 fun! s:NetrwListSettings(islocal)
     6280 "  call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
     6281+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6282   let fname= bufname("%")
    87116283-"  call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro")
    87126284-  setl bt=nofile nobl ma nonu nowrap noro
    8713 -"  call Decho("(NetrwListSettings) exe sil! keepalt file ".fnameescape(fname))
    8714 -  exe "sil! keepalt file ".fnameescape(fname)
    8715 -  if g:netrw_use_noswf
    8716 -   setl noswf
    8717 -  endif
    8718 -"  call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1))
    8719 -  exe "setl ts=".(g:netrw_maxfilenamelen+1)
    8720 -  setl isk+=.,~,-
    8721 -  if g:netrw_fastbrowse > a:islocal
    8722 -   setl bh=hide
    8723 -  else
    8724 -   setl bh=delete
    8725 +  " s:NetrwBrowse: re-instate any marked files {{{3
    8726 +  if exists("s:netrwmarkfilelist_{bufnr('%')}")
    8727 +"   call Decho("clearing marked files")
    8728 +   exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
     6285+"  "  call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro nornu")
     6286+  setl bt=nofile nobl ma nonu nowrap noro nornu
     6287 "  call Decho("(NetrwListSettings) exe sil! keepalt file ".fnameescape(fname))
     6288   exe "sil! keepalt file ".fnameescape(fname)
     6289   if g:netrw_use_noswf
     6290    setl noswf
    87296291   endif
    8730 -"  call Dret("s:NetrwListSettings")
    8731 -endfun
    8732  
    8733 -" ---------------------------------------------------------------------
    8734 -"  s:NetrwListStyle: {{{2
    8735 -"  islocal=0: remote browsing
    8736 -"         =1: local browsing
    8737 -fun! s:NetrwListStyle(islocal)
    8738 -"  call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
    8739 -  let ykeep             = @@
    8740 -  let fname             = s:NetrwGetWord()
    8741 -  if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
    8742 -  let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
    8743 -"  call Decho("fname<".fname.">")
    8744 -"  call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
    8745 -"  call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">")
    8746 +  if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
    8747 +   " s:NetrwBrowse: set up "safe" options for local directory/file {{{3
    8748 +"   call Decho("handle w:netrw_acdkeep:")
    8749 +"   call Decho("keepjumps lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")")
    8750 +   call s:NetrwLcd(dirname)
    8751 +   call s:NetrwSafeOptions()
    8752 +"   call Decho("getcwd<".getcwd().">")
    8753  
    8754 -  if w:netrw_liststyle == s:THINLIST
    8755 -   " use one column listing
    8756 -"   call Decho("use one column list")
    8757 -   let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
    8758 +  elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
    8759 +   " s:NetrwBrowse: looks like a remote regular file, attempt transfer {{{3
    8760 +"   call Decho("attempt transfer as regular file<".dirname.">")
    8761  
    8762 -  elseif w:netrw_liststyle == s:LONGLIST
    8763 -   " use long list
    8764 -"   call Decho("use long list")
    8765 -   let g:netrw_list_cmd = g:netrw_list_cmd." -l"
    8766 +   " remove any filetype indicator from end of dirname, except for the
    8767 +   " "this is a directory" indicator (/).
    8768 +   " There shouldn't be one of those here, anyway.
    8769 +   let path= substitute(dirname,'[*=@|]\r\=$','','e')
    8770 +"   call Decho("new path<".path.">")
    8771 +   call s:RemotePathAnalysis(dirname)
    8772  
    8773 -  elseif w:netrw_liststyle == s:WIDELIST
    8774 -   " give wide list
    8775 -"   call Decho("use wide list")
    8776 -   let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
    8777 +   " s:NetrwBrowse: remote-read the requested file into current buffer {{{3
    8778 +   keepj mark '
    8779 +   call s:NetrwEnew(dirname)
    8780 +   call s:NetrwSafeOptions()
    8781 +   setl ma noro
    8782 +"   call Decho("setl ma noro")
    8783 +   let b:netrw_curdir = dirname
    8784 +   let url            = s:method."://".s:user.s:machine.(s:port ? ":".s:port : "")."/".s:path
    8785 +"   call Decho("exe sil! keepalt file ".fnameescape(url)." (bt=".&bt.")")
    8786 +   exe "sil! keepj keepalt file ".fnameescape(url)
    8787 +   exe "sil! keepj keepalt doau BufReadPre ".fnameescape(s:fname)
    8788 +   sil call netrw#NetRead(2,url)
    8789 +   " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
    8790 +"   call Decho("url<".url.">")
    8791 +"   call Decho("s:path<".s:path.">")
    8792 +"   call Decho("s:fname<".s:fname.">")
    8793 +   if s:path =~ '.bz2'
    8794 +    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
    8795 +   elseif s:path =~ '.gz'
    8796 +    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
    8797 +   elseif s:path =~ '.gz'
    8798 +    exe "sil keepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
    8799 +   else
    8800 +    exe "sil keepj keepalt doau BufReadPost ".fnameescape(s:fname)
    8801 +   endif
    8802  
    8803 -  elseif w:netrw_liststyle == s:TREELIST
    8804 -"   call Decho("use tree list")
    8805 -   let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
    8806 +   " s:NetrwBrowse: save certain window-oriented variables into buffer-oriented variables {{{3
    8807 +   call s:SetBufWinVars()
    8808 +   call s:NetrwOptionRestore("w:")
    8809 +"   call Decho("setl ma nomod")
    8810 +   setl ma nomod
    8811 +"   call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8812  
    8813 -  else
    8814 -   keepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
    8815 -   let g:netrw_liststyle = s:THINLIST
    8816 -   let w:netrw_liststyle = g:netrw_liststyle
    8817 -   let g:netrw_list_cmd  = substitute(g:netrw_list_cmd,' -l','','ge')
    8818 +"   call Dret("s:NetrwBrowse : file<".s:fname.">")
    8819 +   return
     6292+"  call Dredir("ls!")
     6293 "  call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1))
     6294   exe "setl ts=".(g:netrw_maxfilenamelen+1)
     6295   setl isk+=.,~,-
     6296@@ -4116,6 +4061,7 @@
     6297   else
     6298    setl bh=delete
    88206299   endif
    8821 -  setl ma noro
    8822 -"  call Decho("setl ma noro")
    8823 -
    8824 -  " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
    8825 -"  call Decho("clear buffer<".expand("%")."> with :%d")
    8826 -  sil! keepj %d
    8827 -  " following prevents tree listing buffer from being marked "modified"
     6300+"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
     6301 "  call Dret("s:NetrwListSettings")
     6302 endfun
     6303 
     6304@@ -4125,9 +4071,11 @@
     6305 "         =1: local browsing
     6306 fun! s:NetrwListStyle(islocal)
     6307 "  call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
     6308+
     6309   let ykeep             = @@
     6310   let fname             = s:NetrwGetWord()
     6311   if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
     6312+  let svpos            = netrw#SavePosn()
     6313   let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
     6314 "  call Decho("fname<".fname.">")
     6315 "  call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle)
     6316@@ -4165,24 +4113,17 @@
     6317 "  call Decho("clear buffer<".expand("%")."> with :%d")
     6318   sil! keepj %d
     6319   " following prevents tree listing buffer from being marked "modified"
    88286320-"  call Decho("(NetrwListStyle) setl nomod")
    8829 -  setl nomod
     6321+"  call Decho("setl nomod")
     6322   setl nomod
    88306323-"  call Decho("(NetrwListStyle) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8831  
    8832 -  " refresh the listing
     6324+"  call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
     6325 
     6326   " refresh the listing
    88336327-"  call Decho("(NetrwListStyle) refresh the listing")
    88346328-  let svpos= netrw#NetrwSavePosn()
    8835 -  keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
     6329+"  call Decho("refresh the listing")
     6330   keepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
    88366331-  keepj call netrw#NetrwRestorePosn(svpos)
    8837 -  keepj call s:NetrwCursor()
    8838 +  " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
    8839 +  call s:UseBufWinVars()
     6332   keepj call s:NetrwCursor()
    88406333 
    88416334-  " keep cursor on the filename
     
    88466339-   exe "sil! keepj ".w:netrw_bannercnt
    88476340-  endif
    8848 -  let @@= ykeep
    8849 +  " set up some variables {{{3
    8850 +  let b:netrw_browser_active = 1
    8851 +  let dirname                = dirname
    8852 +  let s:last_sort_by         = g:netrw_sort_by
    8853  
    8854 -"  call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
    8855 -endfun
    8856 +  " set up menu {{{3
    8857 +  keepj call s:NetrwMenu(1)
    8858  
    8859 -" ---------------------------------------------------------------------
    8860 -" s:NetrwBannerCtrl: toggles the display of the banner {{{2
    8861 -fun! s:NetrwBannerCtrl(islocal)
    8862 -"  call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
    8863 -
    8864 -  let ykeep= @@
    8865 -  " toggle the banner (enable/suppress)
    8866 -  let g:netrw_banner= !g:netrw_banner
    8867 -
    8868 -  " refresh the listing
     6341+  " restore position; keep cursor on the filename
     6342+  keepj call netrw#RestorePosn(svpos)
     6343   let @@= ykeep
     6344 
     6345 "  call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
     6346@@ -4198,7 +4139,7 @@
     6347   let g:netrw_banner= !g:netrw_banner
     6348 
     6349   " refresh the listing
    88696350-  let svpos= netrw#NetrwSavePosn()
    8870 -  call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
    8871 -
    8872 -  " keep cursor on the filename
    8873 -  let fname= s:NetrwGetWord()
    8874 -  sil keepj $
    8875 -  let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
    8876 -"  call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'))
    8877 -  if result <= 0 && exists("w:netrw_bannercnt")
    8878 -   exe "keepj ".w:netrw_bannercnt
    8879 +  " get/set-up buffer {{{3
    8880 +  let reusing= s:NetrwGetBuffer(a:islocal,dirname)
    8881 +  " maintain markfile highlighting
    8882 +  if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
    8883 +"   call Decho("bufnr(%)=".bufnr('%'))
    8884 +"   call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/")
    8885 +   exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
    8886 +  else
    8887 +"   call Decho("2match none")
    8888 +   2match none
    8889    endif
    8890 -  let @@= ykeep
    8891 -"  call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
    8892 -endfun
    8893 -
    8894 -" ---------------------------------------------------------------------
    8895 -" s:NetrwBookmarkMenu: Uses menu priorities {{{2
    8896 -"                      .2.[cnt] for bookmarks, and
    8897 -"                      .3.[cnt] for history
    8898 -"                      (see s:NetrwMenu())
    8899 -fun! s:NetrwBookmarkMenu()
    8900 -  if !exists("s:netrw_menucnt")
    8901 +  if reusing && line("$") > 1
    8902 +   call s:NetrwOptionRestore("w:")
    8903 +"   call Decho("setl noma nomod nowrap")
    8904 +   setl noma nomod nowrap
    8905 +"   call Decho("(set noma nomod nowrap)  ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    8906 +"   call Dret("s:NetrwBrowse : re-using buffer")
    8907     return
    8908    endif
    8909 -"  call Dfunc("NetrwBookmarkMenu()  histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
    8910  
    8911 -  " the following test assures that gvim is running, has menus available, and has menus enabled.
    8912 -  if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
    8913 -   if exists("g:NetrwTopLvlMenu")
    8914 -"    call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)")
    8915 -    exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
    8916 -    exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
    8917 -   endif
    8918 -   if !exists("s:netrw_initbookhist")
    8919 -    call s:NetrwBookHistRead()
    8920 +  " set b:netrw_curdir to the new directory name {{{3
    8921 +"  call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")")
    8922 +  let b:netrw_curdir= dirname
    8923 +  if b:netrw_curdir =~ '[/\\]$'
    8924 +   let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
    8925 +  endif
    8926 +  if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
    8927 +   let b:netrw_curdir= b:netrw_curdir."/"
    8928 +  endif
    8929 +  if b:netrw_curdir == ''
    8930 +   if has("amiga")
    8931 +    " On the Amiga, the empty string connotes the current directory
    8932 +    let b:netrw_curdir= getcwd()
    8933 +   else
    8934 +    " under unix, when the root directory is encountered, the result
    8935 +    " from the preceding substitute is an empty string.
    8936 +    let b:netrw_curdir= '/'
    8937     endif
    8938 +  endif
    8939 +  if !a:islocal && b:netrw_curdir !~ '/$'
    8940 +   let b:netrw_curdir= b:netrw_curdir.'/'
    8941 +  endif
    8942 +"  call Decho("b:netrw_curdir<".b:netrw_curdir.">")
    8943  
    8944 -   " show bookmarked places
    8945 -   if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
    8946 -    let cnt= 1
    8947 -    for bmd in g:netrw_bookmarklist
     6351+  let svpos= netrw#SavePosn()
     6352   call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
     6353 
     6354   " keep cursor on the filename
     6355@@ -4239,14 +4180,14 @@
     6356    if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
     6357     let cnt= 1
     6358     for bmd in g:netrw_bookmarklist
    89486359-     let ebmd= escape(bmd,g:netrw_menu_escape)
    89496360-"     call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.ebmd.'   :e '.bmd)
    8950 +  " ------------
    8951 +  " (local only) {{{3
    8952 +  " ------------
    8953 +  if a:islocal
    8954 +"   call Decho("local only:")
    8955  
    8956 -     " show bookmarks for goto menu
     6361+"     call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.'    :e '.bmd)
     6362+     let bmd= escape(bmd,g:netrw_menu_escape)
     6363 
     6364      " show bookmarks for goto menu
    89576365-     exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.ebmd.'  :e '.bmd."\<cr>"
    8958 +   " Set up ShellCmdPost handling.  Append current buffer to browselist
    8959 +   call s:LocalFastBrowser()
    8960  
    8961 -     " show bookmarks for deletion menu
     6366+     exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.'   :e '.bmd."\<cr>"
     6367 
     6368      " show bookmarks for deletion menu
    89626369-     exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.ebmd.' '.cnt."mB"
    8963 -     let cnt= cnt + 1
    8964 -    endfor
    8965 +  " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
    8966 +   if !g:netrw_keepdir
    8967 +"    call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd)
    8968 +"    call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"))
    8969 +    if !exists("&l:acd") || !&l:acd
    8970 +     call s:NetrwLcd(b:netrw_curdir)
    8971 +    endif
    8972 +   endif
    8973 +
    8974 +  " --------------------------------
    8975 +  " remote handling: {{{3
    8976 +  " --------------------------------
    8977 +  else
    8978 +"   call Decho("remote only:")
    8979  
    8980 +   " analyze dirname and g:netrw_list_cmd {{{3
    8981 +"   call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">")
    8982 +   if dirname =~ "^NetrwTreeListing\>"
    8983 +    let dirname= b:netrw_curdir
    8984 +"    call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">")
    8985 +   elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
    8986 +    let dirname= substitute(b:netrw_curdir,'\\','/','g')
    8987 +    if dirname !~ '/$'
    8988 +     let dirname= dirname.'/'
    8989 +    endif
    8990 +    let b:netrw_curdir = dirname
    8991 +"    call Decho("(liststyle is TREELIST) dirname<".dirname.">")
    8992 +   else
    8993 +    let dirname = substitute(dirname,'\\','/','g')
    8994 +"    call Decho("(normal) dirname<".dirname.">")
    8995     endif
    8996  
    8997 -   " show directory browsing history
    8998 -   if g:netrw_dirhistmax > 0
    8999 -    let cnt     = g:netrw_dirhist_cnt
    9000 -    let first   = 1
    9001 -    let histcnt = 0
    9002 -    while ( first || cnt != g:netrw_dirhist_cnt )
    9003 -     let histcnt  = histcnt + 1
    9004 -     let priority = g:netrw_dirhist_cnt + histcnt
    9005 -     if exists("g:netrw_dirhist_{cnt}")
    9006 -      let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
    9007 -"     call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.'    :e '.histdir)
    9008 -      exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.'   :e '.histdir."\<cr>"
    9009 -     endif
    9010 -     let first = 0
    9011 -     let cnt   = ( cnt - 1 ) % g:netrw_dirhistmax
    9012 -     if cnt < 0
    9013 -      let cnt= cnt + g:netrw_dirhistmax
    9014 -     endif
    9015 -    endwhile
    9016 +   let dirpat  = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
    9017 +   if dirname !~ dirpat
    9018 +    if !exists("g:netrw_quiet")
    9019 +     keepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
    9020 +    endif
    9021 +    keepj call s:NetrwOptionRestore("w:")
    9022 +"    call Decho("setl noma nomod nowrap")
    9023 +    setl noma nomod nowrap
    9024 +"    call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    9025 +"    call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
    9026 +    return
    9027     endif
    9028 +   let b:netrw_curdir= dirname
    9029 +"   call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)")
    9030 +  endif  " (additional remote handling)
    9031  
    9032 +  " -----------------------
    9033 +  " Directory Listing: {{{3
    9034 +  " -----------------------
    9035 +  keepj call s:NetrwMaps(a:islocal)
    9036 +  keepj call s:NetrwCommands(a:islocal)
    9037 +  keepj call s:PerformListing(a:islocal)
    9038 +  if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
    9039 +   let &l:bexpr= "netrw#BalloonHelp()"
    9040 +"   call Decho("set up balloon help: l:bexpr=".&l:bexpr)
    9041 +   setl beval
    9042    endif
    9043 -"  call Dret("NetrwBookmarkMenu")
    9044 +  call s:NetrwOptionRestore("w:")
    9045 +
    9046 +  " The s:LocalBrowseRefresh() function is called by an autocmd
    9047 +  " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
    9048 +  " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
    9049 +
    9050 +"  call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)")
    9051 +"  call Dret("s:NetrwBrowse : did PerformListing  ft<".&ft.">")
    9052 +  return
    9053  endfun
    9054  
    9055  " ---------------------------------------------------------------------
    9056 -"  s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
    9057 -"                       directory and a new directory name.  Also, if the
    9058 -"                       "new directory name" is actually a file,
    9059 -"                       NetrwBrowseChgDir() edits the file.
    9060 -fun! s:NetrwBrowseChgDir(islocal,newdir,...)
    9061 -"  call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
    9062 -
    9063 +" s:NetrwFileInfo: supports qf (query for file information) {{{2
    9064 +fun! s:NetrwFileInfo(islocal,fname)
    9065 +"  call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
     6370+     exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.'  '.cnt."mB"
     6371      let cnt= cnt + 1
     6372     endfor
     6373 
     6374@@ -4284,78 +4225,109 @@
     6375 "                       NetrwBrowseChgDir() edits the file.
     6376 fun! s:NetrwBrowseChgDir(islocal,newdir,...)
     6377 "  call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
     6378+"  call Decho("win#".winnr())
     6379 
    90666380   let ykeep= @@
    9067 -  if !exists("b:netrw_curdir")
    9068 -   " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
    9069 -   " and the current window is the NetrwMessage window.
    9070 -   let @@= ykeep
     6381   if !exists("b:netrw_curdir")
     6382    " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
     6383    " and the current window is the NetrwMessage window.
     6384    let @@= ykeep
    90716385-"   call Decho("(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!")
    90726386-"   call Decho("(NetrwBrowseChgDir) getcwd<".getcwd().">")
    9073 -"   call Dret("s:NetrwBrowseChgDir")
    9074 -   return
    9075 -  endif
    9076 +  if a:islocal
    9077 +   if (has("unix") || has("macunix")) && executable("/bin/ls")
    9078  
    9079 -  " NetrwBrowseChgDir: save options and initialize {{{3
    9080 -  keepj call s:NetrwOptionSave("s:")
    9081 -  keepj call s:NetrwSafeOptions()
    9082 -  let nbcd_curpos                = netrw#NetrwSavePosn()
    9083 -  let s:nbcd_curpos_{bufnr('%')} = nbcd_curpos
    9084 -"  call Decho("(NetrwBrowseChgDir) setting s:nbcd_curpos_".bufnr('%')." to SavePosn")
    9085 -  if (has("win32") || has("win95") || has("win64") || has("win16"))
    9086 -   let dirname                   = substitute(b:netrw_curdir,'\\','/','ge')
    9087 -  else
    9088 -   let dirname= b:netrw_curdir
    9089 -  endif
    9090 -  let newdir    = a:newdir
    9091 -  let dolockout = 0
    9092 +    if getline(".") == "../"
    9093 +     echo system("/bin/ls -lsad ".shellescape(".."))
    9094 +"     call Decho("#1: echo system(/bin/ls -lsad ".shellescape(..).")")
    9095 +
    9096 +    elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
    9097 +     echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir))
    9098 +"     call Decho("#2: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir).")")
    9099  
    9100 -  " set up o/s-dependent directory recognition pattern
    9101 -  if has("amiga")
    9102 -   let dirpat= '[\/:]$'
    9103 +    elseif exists("b:netrw_curdir")
    9104 +     if b:netrw_curdir =~ '/$'
    9105 +      echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname))
    9106 +"      call Decho("#3: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir.a:fname).")")
    9107 +
    9108 +     else
    9109 +      echo system("/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname))
    9110 +"      call Decho("#4: echo system(/bin/ls -lsad ".shellescape(b:netrw_curdir."/".a:fname).")")
    9111 +     endif
    9112 +
    9113 +    else
    9114 +"     call Decho('using ls '.a:fname." using cwd<".getcwd().">")
    9115 +     echo system("/bin/ls -lsad ".shellescape(a:fname))
    9116 +"     call Decho("#5: echo system(/bin/ls -lsad ".shellescape(a:fname).")")
    9117 +    endif
    9118 +   else
    9119 +    " use vim functions to return information about file below cursor
    9120 +"    call Decho("using vim functions to query for file info")
    9121 +    if !isdirectory(a:fname) && !filereadable(a:fname) && a:fname =~ '[*@/]'
    9122 +     let fname= substitute(a:fname,".$","","")
    9123 +    else
    9124 +     let fname= a:fname
    9125 +    endif
    9126 +    let t  = getftime(fname)
    9127 +    let sz = getfsize(fname)
    9128 +    echo a:fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname))
    9129 +"    call Decho("fname.":  ".sz."  ".strftime(g:netrw_timefmt,getftime(fname)))
    9130 +   endif
    9131    else
    9132 -   let dirpat= '[\/]$'
    9133 +   echo "sorry, \"qf\" not supported yet for remote files"
    9134    endif
    9135 -"  call Decho("(NetrwBrowseChgDir) dirname<".dirname.">  dirpat<".dirpat.">")
    9136 +  let @@= ykeep
    9137 +"  call Dret("s:NetrwFileInfo")
    9138 +endfun
    9139  
    9140 -  if dirname !~ dirpat
    9141 -   " apparently vim is "recognizing" that it is in a directory and
    9142 -   " is removing the trailing "/".  Bad idea, so let's put it back.
    9143 -   let dirname= dirname.'/'
    9144 -"   call Decho("(NetrwBrowseChgDir) adjusting dirname<".dirname.">")
    9145 -  endif
    9146 +" ---------------------------------------------------------------------
    9147 +" s:NetrwGetBuffer: {{{2
    9148 +"   returns 0=cleared buffer
    9149 +"           1=re-used buffer
    9150 +fun! s:NetrwGetBuffer(islocal,dirname)
    9151 +"  call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
    9152 +"  call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
    9153 +  let dirname= a:dirname
    9154  
    9155 -  if newdir !~ dirpat
    9156 -   " ------------------------------
    9157 -   " NetrwBrowseChgDir: edit a file {{{3
    9158 -   " ------------------------------
    9159 -"   call Decho('(NetrwBrowseChgDir:edit-a-file) case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">")
    9160 +  " re-use buffer if possible {{{3
    9161 +"  call Decho("--re-use a buffer if possible--")
    9162 +  if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
    9163 +   " find NetrwTreeList buffer if there is one
    9164 +"   call Decho("case liststyle=treelist: find NetrwTreeList buffer if there is one")
    9165 +   if exists("w:netrw_treebufnr") && w:netrw_treebufnr > 0
    9166 +"    call Decho("  re-using w:netrw_treebufnr=".w:netrw_treebufnr)
    9167 +    let eikeep= &ei
    9168 +    setl ei=all
    9169 +    exe "sil! keepalt b ".w:netrw_treebufnr
    9170 +    let &ei= eikeep
    9171 +    setl ma
    9172 +    sil! keepj %d
    9173 +"    call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo)
    9174 +"    call Dret("s:NetrwGetBuffer 0<buffer cleared> : bufnum#".w:netrw_treebufnr."<NetrwTreeListing>")
    9175 +    return 0
    9176 +   endif
    9177 +   let bufnum= -1
    9178 +"   call Decho("  liststyle=TREE but w:netrw_treebufnr doesn't exist")
    9179  
    9180 -   " save position for benefit of Rexplore
    9181 -   let s:rexposn_{bufnr("%")}= netrw#NetrwSavePosn()
    9182 +  else
    9183 +   " find buffer number of buffer named precisely the same as dirname {{{3
    9184 +"   call Decho("case listtyle not treelist: find buffer numnber of buffer named precisely the same as dirname--")
    9185 +"   call Dredir("(NetrwGetBuffer) ls!","ls!")
    9186  
    9187 -"   call Decho("(NetrwBrowseChgDir:edit-a-file) setting s:rexposn_".bufnr("%")." to SavePosn")
    9188 -   if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
    9189 -    let dirname= s:NetrwTreeDir()
    9190 -    if dirname =~ '/$'
    9191 -     let dirname= dirname.newdir
    9192 -    else
    9193 -     let dirname= s:NetrwTreeDir()."/".newdir
    9194 +   " get dirname and associated buffer number
    9195 +   let bufnum  = bufnr(escape(dirname,'\'))
    9196 +"   call Decho("  find buffer<".dirname.">'s number ")
    9197 +"   call Decho("  bufnr(dirname<".escape(dirname,'\').">)=".bufnum)
    9198 +
    9199 +   if bufnum < 0 && dirname !~ '/$'
    9200 +    " try appending a trailing /
    9201 +"    call Decho("  try appending a trailing / to dirname<".dirname.">")
    9202 +    let bufnum= bufnr(escape(dirname.'/','\'))
    9203 +    if bufnum > 0
    9204 +     let dirname= dirname.'/'
    9205      endif
    9206 -"    call Decho("(NetrwBrowseChgDir:edit-a-file) dirname<".dirname.">")
    9207 -"    call Decho("(NetrwBrowseChgDir:edit-a-file) tree listing")
    9208 -   elseif newdir =~ '^\(/\|\a:\)'
    9209 -    let dirname= newdir
    9210 -   else
    9211 -    let dirname= s:ComposePath(dirname,newdir)
    9212     endif
    9213 -"   call Decho("(NetrwBrowseChgDir:edit-a-file) handling a file: dirname<".dirname."> (a:0=".a:0.")")
    9214 -   " this lets NetrwBrowseX avoid the edit
    9215 -   if a:0 < 1
    9216 -"    call Decho("(NetrwBrowseChgDir:edit-a-file) set up windows for editing<".fnameescape(dirname).">  didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"))
    9217 -    keepj call s:NetrwOptionRestore("s:")
    9218 -    if !exists("s:didsplit")
    9219 -"     call Decho("(NetrwBrowseChgDir:edit-a-file) s:didsplit does not exist; g:netrw_browse_split=".g:netrw_browse_split." win#".winnr())
    9220 -     if     g:netrw_browse_split == 1
    9221 -      " horizontally splitting the window first
    9222 -      keepalt new
    9223 -      if !&ea
    9224 -       keepalt wincmd _
    9225 -      endif
    9226 -     elseif g:netrw_browse_split == 2
    9227 -      " vertically splitting the window first
    9228 -      keepalt rightb vert new
    9229 -      if !&ea
    9230 -       keepalt wincmd |
    9231 -      endif
    9232 -     elseif g:netrw_browse_split == 3
    9233 -      " open file in new tab
    9234 -      keepalt tabnew
    9235 -     elseif g:netrw_browse_split == 4
    9236 -      " act like "P" (ie. open previous window)
    9237 -      if s:NetrwPrevWinOpen(2) == 3
    9238 -       let @@= ykeep
    9239 -"       call Dret("s:NetrwBrowseChgDir")
    9240 -       return
    9241 -      endif
    9242 -     else
    9243 -      " handling a file, didn't split, so remove menu
    9244 -"      call Decho("(NetrwBrowseChgDir:edit-a-file) handling a file+didn't split, so remove menu")
    9245 -      call s:NetrwMenu(0)
    9246 -      " optional change to window
    9247 -      if g:netrw_chgwin >= 1
    9248 -       exe "keepj keepalt ".g:netrw_chgwin."wincmd w"
    9249 -      endif
    9250 -     endif
    9251 -    endif
    9252  
    9253 -    " the point where netrw actually edits the (local) file
    9254 -    " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
    9255 -    if a:islocal
    9256 -"     call Decho("(NetrwBrowseChgDir:edit-a-file) edit local file: exe e! ".fnameescape(dirname))
    9257 -     exe "keepj keepalt e! ".fnameescape(dirname)
    9258 -     call s:NetrwCursor()
    9259 -    else
    9260 -"     call Decho("(NetrwBrowseChgDir:edit-a-file) remote file: NetrwBrowse will edit it")
    9261 +   if bufnum < 0 && dirname =~ '/$'
    9262 +    " try removing a trailing /
    9263 +"    call Decho("  try removing a trailing / from dirname<".dirname.">")
    9264 +    let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\'))
    9265 +    if bufnum > 0
    9266 +     let dirname= substitute(dirname,'/$','','')
    9267      endif
    9268 -    let dolockout= 1
    9269 +   endif
    9270  
    9271 -    " handle g:Netrw_funcref -- call external-to-netrw functions
    9272 -    "   This code will handle g:Netrw_funcref as an individual function reference
    9273 -    "   or as a list of function references.  It will ignore anything that's not
    9274 -    "   a function reference.  See  :help Funcref  for information about function references.
    9275 -    if exists("g:Netrw_funcref")
    9276 -"     call Decho("(NetrwBrowseChgDir:edit-a-file) handle optional Funcrefs")
    9277 -     if type(g:Netrw_funcref) == 2
    9278 -"      call Decho("(NetrwBrowseChgDir:edit-a-file) handling a g:Netrw_funcref")
    9279 -      keepj call g:Netrw_funcref()
    9280 -     elseif type(g:Netrw_funcref) == 3
    9281 -"      call Decho("(NetrwBrowseChgDir:edit-a-file) handling a list of g:Netrw_funcrefs")
    9282 -      for Fncref in g:Netrw_funcref
    9283 -       if type(FncRef) == 2
    9284 -        keepj call FncRef()
    9285 -       endif
    9286 -      endfor
    9287 +"   call Decho("  findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)")
    9288 +   " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/  and abc/ matches)
    9289 +   if bufnum > 0 && bufname(bufnum) != dirname && bufname(bufnum) != '.'
    9290 +    " handle approximate matches
    9291 +"    call Decho("  handling approx match: bufnum#".bufnum.">0 AND bufname<".bufname(bufnum).">!=dirname<".dirname."> AND bufname(".bufnum.")!='.'")
    9292 +    let ibuf    = 1
    9293 +    let buflast = bufnr("$")
    9294 +"    call Decho("  findbuf2: buflast=bufnr($)=".buflast)
    9295 +    while ibuf <= buflast
    9296 +     let bname= substitute(bufname(ibuf),'\\','/','g')
    9297 +     let bname= substitute(bname,'.\zs/$','','')
    9298 +"     call Decho("  findbuf3: while [ibuf=",ibuf."]<=[buflast=".buflast."]: dirname<".dirname."> bname=bufname(".ibuf.")<".bname.">")
    9299 +     if bname != '' && dirname =~ '/'.bname.'/\=$' && dirname !~ '^/'
    9300 +      " bname is not empty
    9301 +      " dirname ends with bname,
    9302 +      " dirname doesn't start with /, so its not a absolute path
    9303 +"      call Decho("  findbuf3a: passes test 1 : dirname<".dirname.'> =~ /'.bname.'/\=$ && dirname !~ ^/')
    9304 +      break
    9305 +     endif
    9306 +     if bname =~ '^'.dirname.'/\=$'
    9307 +      " bname begins with dirname
    9308 +"      call Decho('  findbuf3b: passes test 2 : bname<'.bname.'>=~^'.dirname.'/\=$')
    9309 +      break
    9310 +     endif
    9311 +     if dirname =~ '^'.bname.'/$'
    9312 +"      call Decho('  findbuf3c: passes test 3 : dirname<'.dirname.'>=~^'.bname.'/$')
    9313 +      break
    9314 +     endif
    9315 +     if bname != '' && dirname =~ '/'.bname.'$' && bname == bufname("%") && line("$") == 1
    9316 +"      call Decho('  findbuf3d: passes test 4 : dirname<'.dirname.'>=~ /'.bname.'$')
    9317 +      break
    9318       endif
    9319 +     let ibuf= ibuf + 1
    9320 +    endwhile
    9321 +    if ibuf > buflast
    9322 +     let bufnum= -1
    9323 +    else
    9324 +     let bufnum= ibuf