netrw.vim (396845B)
1 " Creator: Charles E Campbell 2 " Previous Maintainer: Luca Saccarola <github.e41mv@aleeas.com> 3 " Maintainer: This runtime file is looking for a new maintainer. 4 " Last Change: 2026 Sep 07 5 " Copyright: Copyright (C) 2016 Charles E. Campbell {{{1 6 " Permission is hereby granted to use and distribute this code, 7 " with or without modifications, provided that this copyright 8 " notice is copied with it. Like anything else that's free, 9 " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided 10 " *as is* and come with no warranty of any kind, either 11 " expressed or implied. By using this plugin, you agree that 12 " in no event will the copyright holder be liable for any damages 13 " resulting from the use of this software. 14 " 15 " Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing 16 " code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7). 17 18 " Load Once: {{{1 19 if &cp || exists("g:loaded_netrw") 20 finish 21 endif 22 23 let g:loaded_netrw = "v184" 24 25 if !has("patch-9.1.1054") && !has('nvim') 26 echoerr 'netrw needs Vim v9.1.1054' 27 finish 28 endif 29 30 let s:keepcpo= &cpo 31 setl cpo&vim 32 33 " Netrw Variables: {{{1 34 35 " s:NetrwInit: initializes variables if they haven't been defined {{{2 36 37 function s:NetrwInit(name, default) 38 if !exists(a:name) 39 let {a:name} = a:default 40 endif 41 endfunction 42 43 " Netrw Constants: {{{2 44 call s:NetrwInit("g:netrw_dirhistcnt",0) 45 if !exists("s:LONGLIST") 46 call s:NetrwInit("s:THINLIST",0) 47 call s:NetrwInit("s:LONGLIST",1) 48 call s:NetrwInit("s:WIDELIST",2) 49 call s:NetrwInit("s:TREELIST",3) 50 call s:NetrwInit("s:MAXLIST" ,4) 51 endif 52 53 " Default option values: {{{2 54 call s:NetrwInit("g:netrw_localcopycmdopt","") 55 call s:NetrwInit("g:netrw_localcopydircmdopt","") 56 call s:NetrwInit("g:netrw_localmkdiropt","") 57 call s:NetrwInit("g:netrw_localmovecmdopt","") 58 59 " Default values for netrw's global protocol variables {{{2 60 61 if !exists("g:netrw_dav_cmd") 62 if executable("cadaver") 63 let g:netrw_dav_cmd = "cadaver" 64 elseif executable("curl") 65 let g:netrw_dav_cmd = "curl" 66 else 67 let g:netrw_dav_cmd = "" 68 endif 69 endif 70 if !exists("g:netrw_fetch_cmd") 71 if executable("fetch") 72 let g:netrw_fetch_cmd = "fetch -o" 73 else 74 let g:netrw_fetch_cmd = "" 75 endif 76 endif 77 if !exists("g:netrw_file_cmd") 78 if executable("elinks") 79 call s:NetrwInit("g:netrw_file_cmd","elinks") 80 elseif executable("links") 81 call s:NetrwInit("g:netrw_file_cmd","links") 82 endif 83 endif 84 if !exists("g:netrw_ftp_cmd") 85 let g:netrw_ftp_cmd = "ftp" 86 endif 87 let s:netrw_ftp_cmd= g:netrw_ftp_cmd 88 if !exists("g:netrw_ftp_options") 89 let g:netrw_ftp_options= "-i -n" 90 endif 91 if !exists("g:netrw_http_cmd") 92 if executable("wget") 93 let g:netrw_http_cmd = "wget" 94 call s:NetrwInit("g:netrw_http_xcmd","-q -O") 95 elseif executable("curl") 96 let g:netrw_http_cmd = "curl" 97 call s:NetrwInit("g:netrw_http_xcmd","-L -o") 98 elseif executable("elinks") 99 let g:netrw_http_cmd = "elinks" 100 call s:NetrwInit("g:netrw_http_xcmd","-source >") 101 elseif executable("fetch") 102 let g:netrw_http_cmd = "fetch" 103 call s:NetrwInit("g:netrw_http_xcmd","-o") 104 elseif executable("links") 105 let g:netrw_http_cmd = "links" 106 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >") 107 else 108 let g:netrw_http_cmd = "" 109 endif 110 endif 111 call s:NetrwInit("g:netrw_http_put_cmd","curl -T") 112 call s:NetrwInit("g:netrw_keepj","keepj") 113 call s:NetrwInit("g:netrw_rcp_cmd" , "rcp") 114 call s:NetrwInit("g:netrw_rsync_cmd", "rsync") 115 call s:NetrwInit("g:netrw_rsync_sep", "/") 116 if !exists("g:netrw_scp_cmd") 117 if executable("scp") 118 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q") 119 elseif executable("pscp") 120 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q') 121 else 122 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q") 123 endif 124 endif 125 call s:NetrwInit("g:netrw_sftp_cmd" , "sftp") 126 call s:NetrwInit("g:netrw_ssh_cmd" , "ssh") 127 128 if has("win32") 129 \ && exists("g:netrw_use_nt_rcp") 130 \ && g:netrw_use_nt_rcp 131 \ && executable( $SystemRoot .'/system32/rcp.exe') 132 let s:netrw_has_nt_rcp = 1 133 let s:netrw_rcpmode = '-b' 134 else 135 let s:netrw_has_nt_rcp = 0 136 let s:netrw_rcpmode = '' 137 endif 138 139 " Default values for netrw's global variables {{{2 140 " Cygwin Detection ------- {{{3 141 if !exists("g:netrw_cygwin") 142 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' 143 let g:netrw_cygwin= 1 144 else 145 let g:netrw_cygwin= 0 146 endif 147 endif 148 " Default values - a-c ---------- {{{3 149 call s:NetrwInit("g:netrw_alto" , &sb) 150 call s:NetrwInit("g:netrw_altv" , &spr) 151 call s:NetrwInit("g:netrw_banner" , 1) 152 call s:NetrwInit("g:netrw_browse_split", 0) 153 call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu") 154 call s:NetrwInit("g:netrw_chgwin" , -1) 155 call s:NetrwInit("g:netrw_clipboard" , 1) 156 call s:NetrwInit("g:netrw_compress" , "gzip") 157 call s:NetrwInit("g:netrw_ctags" , "ctags") 158 call s:NetrwInit("g:netrw_cursor" , 2) 159 let s:netrw_usercul = &cursorline 160 let s:netrw_usercuc = &cursorcolumn 161 call s:NetrwInit("g:netrw_cygdrive","/cygdrive") 162 " Default values - d-g ---------- {{{3 163 call s:NetrwInit("s:didstarstar",0) 164 call s:NetrwInit("g:netrw_dirhistcnt" , 0) 165 let s:xz_opt = has('unix') ? "XZ_OPT=-T0" : 166 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ? 167 \ "setx XZ_OPT=-T0 &&" : "") 168 call s:NetrwInit("g:netrw_decompress", { 169 \ '.lz4': 'lz4 -d', 170 \ '.lzo': 'lzop -d', 171 \ '.lz': 'lzip -dk', 172 \ '.7z': '7za x', 173 \ '.001': '7za x', 174 \ '.zip': 'unzip', 175 \ '.bz': 'bunzip2 -k', 176 \ '.bz2': 'bunzip2 -k', 177 \ '.gz': 'gunzip -k', 178 \ '.lzma': 'unlzma -T0 -k', 179 \ '.xz': 'unxz -T0 -k', 180 \ '.zst': 'zstd -T0 -d', 181 \ '.Z': 'uncompress -k', 182 \ '.tar': 'tar -xvf', 183 \ '.tar.bz': 'tar -xvjf', 184 \ '.tar.bz2': 'tar -xvjf', 185 \ '.tbz': 'tar -xvjf', 186 \ '.tbz2': 'tar -xvjf', 187 \ '.tar.gz': 'tar -xvzf', 188 \ '.tgz': 'tar -xvzf', 189 \ '.tar.lzma': s:xz_opt .. ' tar -xvf --lzma', 190 \ '.tlz': s:xz_opt .. ' tar -xvf --lzma', 191 \ '.tar.xz': s:xz_opt .. ' tar -xvfJ', 192 \ '.txz': s:xz_opt .. ' tar -xvfJ', 193 \ '.tar.zst': s:xz_opt .. ' tar -xvf --use-compress-program=unzstd', 194 \ '.tzst': s:xz_opt .. ' tar -xvf --use-compress-program=unzstd', 195 \ '.rar': (executable("unrar")?"unrar x -ad":"rar x -ad"), 196 \ }) 197 unlet s:xz_opt 198 call s:NetrwInit("g:netrw_dirhistmax" , 10) 199 call s:NetrwInit("g:netrw_fastbrowse" , 1) 200 call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$') 201 if !exists("g:netrw_ftp_list_cmd") 202 if has("unix") || g:netrw_cygwin 203 let g:netrw_ftp_list_cmd = "ls -lF" 204 let g:netrw_ftp_timelist_cmd = "ls -tlF" 205 let g:netrw_ftp_sizelist_cmd = "ls -slF" 206 else 207 let g:netrw_ftp_list_cmd = "dir" 208 let g:netrw_ftp_timelist_cmd = "dir" 209 let g:netrw_ftp_sizelist_cmd = "dir" 210 endif 211 endif 212 call s:NetrwInit("g:netrw_ftpmode",'binary') 213 " Default values - h-lh ---------- {{{3 214 call s:NetrwInit("g:netrw_hide",1) 215 if !exists("g:netrw_ignorenetrc") 216 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$' 217 let g:netrw_ignorenetrc= 1 218 else 219 let g:netrw_ignorenetrc= 0 220 endif 221 endif 222 call s:NetrwInit("g:netrw_keepdir",1) 223 if !exists("g:netrw_list_cmd") 224 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp") 225 if exists("g:netrw_list_cmd_options") 226 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options 227 else 228 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:" 229 endif 230 elseif executable(g:netrw_ssh_cmd) 231 " provide a scp-based default listing command 232 if exists("g:netrw_list_cmd_options") 233 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options 234 else 235 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa" 236 endif 237 else 238 let g:netrw_list_cmd= "" 239 endif 240 endif 241 call s:NetrwInit("g:netrw_list_hide","") 242 " Default values - lh-lz ---------- {{{3 243 if !exists("g:netrw_localcmdshell") 244 let g:netrw_localcmdshell= "" 245 endif 246 247 if !exists("g:netrw_localcopycmd") 248 let g:netrw_localcopycmd = 'cp' 249 let g:netrw_localcopycmdopt = '' 250 251 if has("win32") && !g:netrw_cygwin 252 let g:netrw_localcopycmd = $COMSPEC 253 let g:netrw_localcopycmdopt = ' /c copy' 254 endif 255 endif 256 257 if !exists("g:netrw_localcopydircmd") 258 let g:netrw_localcopydircmd = 'cp' 259 let g:netrw_localcopydircmdopt = '-R' 260 261 if has("win32") && !g:netrw_cygwin 262 let g:netrw_localcopydircmd = "xcopy" 263 let g:netrw_localcopydircmdopt = " /E /I /H /C /Y" 264 endif 265 endif 266 267 if !exists("g:netrw_localmkdir") 268 if has("win32") 269 if g:netrw_cygwin 270 let g:netrw_localmkdir= "mkdir" 271 else 272 let g:netrw_localmkdir = $COMSPEC 273 let g:netrw_localmkdiropt= " /c mkdir" 274 endif 275 else 276 let g:netrw_localmkdir= "mkdir" 277 endif 278 endif 279 280 if !exists("g:netrw_localmovecmd") 281 if has("win32") 282 if g:netrw_cygwin 283 let g:netrw_localmovecmd= "mv" 284 else 285 let g:netrw_localmovecmd = $COMSPEC 286 let g:netrw_localmovecmdopt= " /c move" 287 endif 288 elseif has("unix") || has("macunix") 289 let g:netrw_localmovecmd= "mv" 290 else 291 let g:netrw_localmovecmd= "" 292 endif 293 endif 294 295 call s:NetrwInit("g:netrw_liststyle" , s:THINLIST) 296 " sanity checks 297 if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST 298 let g:netrw_liststyle= s:THINLIST 299 endif 300 if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp' 301 let g:netrw_list_cmd= g:netrw_list_cmd." -l" 302 endif 303 " Default values - m-r ---------- {{{3 304 call s:NetrwInit("g:netrw_markfileesc" , '*./[\~') 305 call s:NetrwInit("g:netrw_maxfilenamelen", 32) 306 call s:NetrwInit("g:netrw_menu" , 1) 307 call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir") 308 call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]')) 309 call s:NetrwInit("g:netrw_retmap" , 0) 310 if has("unix") || g:netrw_cygwin 311 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME") 312 elseif has("win32") 313 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM") 314 else 315 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME") 316 endif 317 call s:NetrwInit("g:netrw_preview" , 0) 318 call s:NetrwInit("g:netrw_scpport" , "-P") 319 call s:NetrwInit("g:netrw_servername" , "NETRWSERVER") 320 call s:NetrwInit("g:netrw_sshport" , "-p") 321 call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv") 322 call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm") 323 call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir") 324 call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ") 325 " Default values - q-s ---------- {{{3 326 call s:NetrwInit("g:netrw_quickhelp",0) 327 let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special", 328 \ "(create new) %:file d:directory", 329 \ "(windows split&open) o:horz v:vert p:preview", 330 \ "i:style qf:file info O:obtain r:reverse", 331 \ "(marks) mf:mark file mt:set target mm:move mc:copy", 332 \ "(bookmarks) mb:make mB:delete qb:list gb:go to", 333 \ "(history) qb:list u:go up U:go down", 334 \ "(targets) mt:target Tb:use bookmark Th:use history"] 335 " g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename 336 call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>") 337 if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj" 338 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ") 339 else 340 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ") 341 endif 342 call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size 343 call s:NetrwInit("g:netrw_sort_options" , "") 344 call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...) 345 if !exists("g:netrw_sort_sequence") 346 let g:netrw_sort_sequence = !empty(&suffixes) 347 \ ? printf('[\/]$,*,\%(%s\)[*@]\=$', &suffixes->split(',')->map('escape(v:val, ".*$~")')->join('\|')) 348 \ : '[\/]$,*' 349 endif 350 call s:NetrwInit("g:netrw_special_syntax" , 0) 351 call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$') 352 call s:NetrwInit("g:netrw_use_noswf" , 1) 353 call s:NetrwInit("g:netrw_sizestyle" ,"b") 354 " Default values - t-w ---------- {{{3 355 call s:NetrwInit("g:netrw_timefmt","%c") 356 if !exists("g:netrw_xstrlen") 357 if exists("g:Align_xstrlen") 358 let g:netrw_xstrlen= g:Align_xstrlen 359 elseif exists("g:drawit_xstrlen") 360 let g:netrw_xstrlen= g:drawit_xstrlen 361 elseif &enc == "latin1" || !has("multi_byte") 362 let g:netrw_xstrlen= 0 363 else 364 let g:netrw_xstrlen= 1 365 endif 366 endif 367 call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.") 368 call s:NetrwInit("g:netrw_winsize",50) 369 call s:NetrwInit("g:netrw_wiw",1) 370 if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif 371 " Default values for netrw's script variables: {{{2 372 call s:NetrwInit("g:netrw_fname_escape",' ?&;%') 373 if has("win32") 374 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$') 375 else 376 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\') 377 endif 378 call s:NetrwInit("g:netrw_menu_escape",'.&? \|') 379 call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"") 380 if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4') 381 let s:treedepthstring= "│ " 382 else 383 let s:treedepthstring= "| " 384 endif 385 call s:NetrwInit("s:netrw_posn", {}) 386 387 " BufEnter event ignored by decho when following variable is true 388 " Has a side effect that doau BufReadPost doesn't work, so 389 " files read by network transfer aren't appropriately highlighted. 390 391 " Netrw Initialization: {{{1 392 393 au WinEnter * if &ft == "netrw" | call s:NetrwInsureWinVars() | endif 394 395 if g:netrw_keepj =~# "keepj" 396 com! -nargs=* NetrwKeepj keepj <args> 397 else 398 let g:netrw_keepj= "" 399 com! -nargs=* NetrwKeepj <args> 400 endif 401 402 " Netrw Utility Functions: {{{1 403 " netrw#Explore: launch the local browser in the directory of the current file {{{2 404 " indx: == -1: Nexplore 405 " == -2: Pexplore 406 " == +: this is overloaded: 407 " * If Nexplore/Pexplore is in use, then this refers to the 408 " indx'th item in the w:netrw_explore_list[] of items which 409 " matched the */pattern **/pattern *//pattern **//pattern 410 " * If Hexplore or Vexplore, then this will override 411 " g:netrw_winsize to specify the qty of rows or columns the 412 " newly split window should have. 413 " dosplit==0: the window will be split iff the current file has been modified and hidden not set 414 " dosplit==1: the window will be split before running the local browser 415 " style == 0: Explore style == 1: Explore! 416 " == 2: Hexplore style == 3: Hexplore! 417 " == 4: Vexplore style == 5: Vexplore! 418 " == 6: Texplore 419 function netrw#Explore(indx,dosplit,style,...) 420 if !exists("b:netrw_curdir") 421 let b:netrw_curdir= netrw#fs#Cwd(0) 422 endif 423 424 " record current file for Rexplore's benefit 425 if &ft != "netrw" 426 let w:netrw_rexfile= expand("%:p") 427 endif 428 429 " record current directory 430 let curdir = simplify(b:netrw_curdir) 431 if !g:netrw_cygwin && has("win32") 432 let curdir= substitute(curdir,'\','/','g') 433 endif 434 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e') 435 if &buftype == "terminal" 436 let curfiledir = curdir 437 endif 438 439 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea) 440 " will end up with backslashes here. Solution: strip off backslashes that precede white space and 441 " try Explore again. 442 if a:0 > 0 443 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1)) 444 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g') 445 if a1 != a:1 446 call netrw#Explore(a:indx, a:dosplit, a:style, a1) 447 return 448 endif 449 endif 450 endif 451 452 " save registers 453 if has("clipboard") && g:netrw_clipboard 454 sil! let keepregstar = @* 455 sil! let keepregplus = @+ 456 endif 457 sil! let keepregslash= @/ 458 459 " if dosplit 460 " -or- buffer is not a terminal AND file has been modified AND file not hidden when abandoned 461 " -or- Texplore used 462 if a:dosplit || (&buftype != "terminal" && &modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6 463 call s:SaveWinVars() 464 let winsz= g:netrw_winsize 465 if a:indx > 0 466 let winsz= a:indx 467 endif 468 469 if a:style == 0 " Explore, Sexplore 470 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz 471 if winsz == 0|let winsz= ""|endif 472 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s" 473 474 elseif a:style == 1 " Explore!, Sexplore! 475 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz 476 if winsz == 0|let winsz= ""|endif 477 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v" 478 479 elseif a:style == 2 " Hexplore 480 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz 481 if winsz == 0|let winsz= ""|endif 482 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s" 483 484 elseif a:style == 3 " Hexplore! 485 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz 486 if winsz == 0|let winsz= ""|endif 487 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s" 488 489 elseif a:style == 4 " Vexplore 490 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz 491 if winsz == 0|let winsz= ""|endif 492 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v" 493 494 elseif a:style == 5 " Vexplore! 495 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz 496 if winsz == 0|let winsz= ""|endif 497 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v" 498 499 elseif a:style == 6 " Texplore 500 call s:SaveBufVars() 501 exe "keepalt tabnew ".fnameescape(curdir) 502 call s:RestoreBufVars() 503 endif 504 call s:RestoreWinVars() 505 endif 506 NetrwKeepj norm! 0 507 508 if a:0 > 0 509 if a:1 =~ '^\~' && (has("unix") || has("win32") || g:netrw_cygwin) 510 let dirname= simplify(substitute(a:1,'^\~',escape(expand("$HOME"),'\&~'),'')) 511 elseif a:1 == '.' 512 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd()) 513 if dirname !~ '/$' 514 let dirname= dirname."/" 515 endif 516 elseif a:1 =~ '\$' 517 let dirname= simplify(expand(a:1)) 518 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://' 519 let dirname= simplify(a:1) 520 else 521 let dirname= a:1 522 endif 523 else 524 " clear explore 525 call s:NetrwClearExplore() 526 return 527 endif 528 " Win32: Use forward slashes 529 if !g:netrw_cygwin && has("win32") 530 let dirname= substitute(dirname,'\','/','g') 531 endif 532 533 if dirname =~ '\.\./\=$' 534 let dirname= simplify(fnamemodify(dirname,':p:h')) 535 elseif dirname =~ '\.\.' || dirname == '.' 536 let dirname= simplify(fnamemodify(dirname,':p')) 537 endif 538 539 if dirname =~ '^\*//' 540 " starpat=1: Explore *//pattern (current directory only search for files containing pattern) 541 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','') 542 let starpat= 1 543 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif 544 545 elseif dirname =~ '^\*\*//' 546 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) 547 let pattern= substitute(dirname,'^\*\*//','','') 548 let starpat= 2 549 550 elseif dirname =~ '/\*\*/' 551 " handle .../**/.../filepat 552 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','') 553 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32")) 554 let b:netrw_curdir = prefixdir 555 else 556 let b:netrw_curdir= getcwd().'/'.prefixdir 557 endif 558 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','') 559 let starpat= 4 560 561 elseif dirname =~ '^\*/' 562 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat) 563 let starpat= 3 564 565 elseif dirname=~ '^\*\*/' 566 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) 567 let starpat= 4 568 569 else 570 let starpat= 0 571 endif 572 573 if starpat == 0 && a:indx >= 0 574 if dirname == "" 575 let dirname= curfiledir 576 endif 577 " [Explore Hexplore Vexplore Sexplore] [dirname] 578 if dirname =~# '^scp://' || dirname =~ '^ftp://' 579 call netrw#Nread(2,dirname) 580 else 581 if dirname == "" 582 let dirname= netrw#fs#Cwd(0) 583 elseif has("win32") && !g:netrw_cygwin 584 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo', 585 " depending on whether backslashes have been converted to forward slashes by earlier code). 586 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+' 587 let dirname= b:netrw_curdir."/".dirname 588 endif 589 elseif dirname !~ '^/' 590 let dirname= b:netrw_curdir."/".dirname 591 endif 592 call netrw#LocalBrowseCheck(dirname) 593 endif 594 if exists("w:netrw_bannercnt") 595 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner. 596 " If one wants to return the same place in the netrw window, use :Rex instead. 597 exe w:netrw_bannercnt 598 endif 599 600 601 " starpat=1: Explore *//pattern (current directory only search for files containing pattern) 602 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) 603 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) 604 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) 605 elseif a:indx <= 0 606 " Nexplore, Pexplore, Explore: handle starpat 607 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir") 608 let s:didstarstar= 1 609 nnoremap <buffer> <silent> <s-up> :Pexplore<cr> 610 nnoremap <buffer> <silent> <s-down> :Nexplore<cr> 611 endif 612 613 if has("path_extra") 614 if !exists("w:netrw_explore_indx") 615 let w:netrw_explore_indx= 0 616 endif 617 618 let indx = a:indx 619 620 if indx == -1 621 " Nexplore 622 if !exists("w:netrw_explore_list") " sanity check 623 call netrw#msg#Notify('WARNING', 'using Nexplore or <s-down> improperly; see help for netrw-starstar') 624 if has("clipboard") && g:netrw_clipboard 625 if @* != keepregstar | sil! let @* = keepregstar | endif 626 if @+ != keepregplus | sil! let @+ = keepregplus | endif 627 endif 628 sil! let @/ = keepregslash 629 return 630 endif 631 let indx= w:netrw_explore_indx 632 if indx < 0 | let indx= 0 | endif 633 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif 634 let curfile= w:netrw_explore_list[indx] 635 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx] 636 let indx= indx + 1 637 endwhile 638 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif 639 640 elseif indx == -2 641 " Pexplore 642 if !exists("w:netrw_explore_list") " sanity check 643 call netrw#msg#Notify('WARNING', 'using Pexplore or <s-up> improperly; see help for netrw-starstar') 644 if has("clipboard") && g:netrw_clipboard 645 if @* != keepregstar | sil! let @* = keepregstar | endif 646 if @+ != keepregplus | sil! let @+ = keepregplus | endif 647 endif 648 sil! let @/ = keepregslash 649 return 650 endif 651 let indx= w:netrw_explore_indx 652 if indx < 0 | let indx= 0 | endif 653 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif 654 let curfile= w:netrw_explore_list[indx] 655 while indx >= 0 && curfile == w:netrw_explore_list[indx] 656 let indx= indx - 1 657 endwhile 658 if indx < 0 | let indx= 0 | endif 659 660 else 661 " Explore -- initialize 662 " build list of files to Explore with Nexplore/Pexplore 663 NetrwKeepj keepalt call s:NetrwClearExplore() 664 let w:netrw_explore_indx= 0 665 if !exists("b:netrw_curdir") 666 let b:netrw_curdir= getcwd() 667 endif 668 669 " switch on starpat to build the w:netrw_explore_list of files 670 if starpat == 1 671 " starpat=1: Explore *//pattern (current directory only search for files containing pattern) 672 try 673 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*" 674 catch /^Vim\%((\a\+)\)\=:E480/ 675 call netrw#msg#Notify('WARNING', printf("no match with pattern<%s>", pattern)) 676 return 677 endtry 678 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)')) 679 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif 680 681 elseif starpat == 2 682 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern) 683 try 684 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*" 685 catch /^Vim\%((\a\+)\)\=:E480/ 686 call netrw#msg#Notify('WARNING', printf('no files matched pattern<%s>', pattern)) 687 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif 688 if has("clipboard") && g:netrw_clipboard 689 if @* != keepregstar | sil! let @* = keepregstar | endif 690 if @+ != keepregplus | sil! let @+ = keepregplus | endif 691 endif 692 sil! let @/ = keepregslash 693 return 694 endtry 695 let s:netrw_curdir = b:netrw_curdir 696 let w:netrw_explore_list = getqflist() 697 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)')) 698 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif 699 700 elseif starpat == 3 701 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat) 702 let filepat= substitute(dirname,'^\*/','','') 703 let filepat= substitute(filepat,'^[%#<]','\\&','') 704 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n')) 705 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif 706 707 elseif starpat == 4 708 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) 709 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n')) 710 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif 711 endif " switch on starpat to build w:netrw_explore_list 712 713 let w:netrw_explore_listlen = len(w:netrw_explore_list) 714 715 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/') 716 call netrw#msg#Notify('WARNING', 'no files matched') 717 if has("clipboard") && g:netrw_clipboard 718 if @* != keepregstar | sil! let @* = keepregstar | endif 719 if @+ != keepregplus | sil! let @+ = keepregplus | endif 720 endif 721 sil! let @/ = keepregslash 722 return 723 endif 724 endif " if indx ... endif 725 726 " NetrwStatusLine support - for exploring support 727 let w:netrw_explore_indx= indx 728 729 " wrap the indx around, but issue a note 730 if indx >= w:netrw_explore_listlen || indx < 0 731 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0 732 let w:netrw_explore_indx= indx 733 call netrw#msg#Notify('NOTE', 'no more files match Explore pattern') 734 endif 735 736 exe "let dirfile= w:netrw_explore_list[".indx."]" 737 let newdir= substitute(dirfile,'/[^/]*$','','e') 738 739 call netrw#LocalBrowseCheck(newdir) 740 if !exists("w:netrw_liststyle") 741 let w:netrw_liststyle= g:netrw_liststyle 742 endif 743 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST 744 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W") 745 else 746 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w") 747 endif 748 let w:netrw_explore_mtchcnt = indx + 1 749 let w:netrw_explore_bufnr = bufnr("%") 750 let w:netrw_explore_line = line(".") 751 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}') 752 753 else 754 call netrw#msg#Notify('WARNING', 'your vim needs the +path_extra feature for Exploring with **!') 755 if has("clipboard") && g:netrw_clipboard 756 if @* != keepregstar | sil! let @* = keepregstar | endif 757 if @+ != keepregplus | sil! let @+ = keepregplus | endif 758 endif 759 sil! let @/ = keepregslash 760 return 761 endif 762 763 else 764 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/' 765 sil! unlet w:netrw_treedict 766 sil! unlet w:netrw_treetop 767 endif 768 let newdir= dirname 769 if !exists("b:netrw_curdir") 770 NetrwKeepj call netrw#LocalBrowseCheck(getcwd()) 771 else 772 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0)) 773 endif 774 endif 775 776 " visual display of **/ **// */ Exploration files 777 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir") 778 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir 779 " only update match list when current directory isn't the same as before 780 let s:explore_prvdir = b:netrw_curdir 781 let s:explore_match = "" 782 let dirlen = strlen(b:netrw_curdir) 783 if b:netrw_curdir !~ '/$' 784 let dirlen= dirlen + 1 785 endif 786 let prvfname= "" 787 for fname in w:netrw_explore_list 788 if fname =~ '^'.b:netrw_curdir 789 if s:explore_match == "" 790 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' 791 else 792 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>' 793 endif 794 elseif fname !~ '^/' && fname != prvfname 795 if s:explore_match == "" 796 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>' 797 else 798 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>' 799 endif 800 endif 801 let prvfname= fname 802 endfor 803 if has("syntax") && exists("g:syntax_on") && g:syntax_on 804 exe "2match netrwMarkFile /".s:explore_match."/" 805 endif 806 endif 807 echo "<s-up>==Pexplore <s-down>==Nexplore" 808 else 809 2match none 810 if exists("s:explore_match") | unlet s:explore_match | endif 811 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif 812 endif 813 814 " since Explore may be used to initialize netrw's browser, 815 " there's no danger of a late FocusGained event on initialization. 816 " Consequently, set s:netrw_events to 2. 817 let s:netrw_events= 2 818 if has("clipboard") && g:netrw_clipboard 819 if @* != keepregstar | sil! let @* = keepregstar | endif 820 if @+ != keepregplus | sil! let @+ = keepregplus | endif 821 endif 822 sil! let @/ = keepregslash 823 endfunction 824 825 " netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2 826 " Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened 827 " t:netrw_lexposn : winsaveview() output (used on Lexplore window) 828 " t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function) 829 " s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window) 830 " w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window) 831 function netrw#Lexplore(count,rightside,...) 832 let curwin= winnr() 833 834 if a:0 > 0 && a:1 != "" 835 " if a netrw window is already on the left-side of the tab 836 " and a directory has been specified, explore with that 837 " directory. 838 let a1 = expand(a:1) 839 exe "1wincmd w" 840 if &ft == "netrw" 841 exe "Explore ".fnameescape(a1) 842 exe curwin."wincmd w" 843 let s:lexplore_win= curwin 844 let w:lexplore_buf= bufnr("%") 845 if exists("t:netrw_lexposn") 846 unlet t:netrw_lexposn 847 endif 848 return 849 endif 850 exe curwin."wincmd w" 851 else 852 let a1= "" 853 endif 854 855 if exists("t:netrw_lexbufnr") 856 " check if t:netrw_lexbufnr refers to a netrw window 857 let lexwinnr = bufwinnr(t:netrw_lexbufnr) 858 else 859 let lexwinnr= 0 860 endif 861 862 if lexwinnr > 0 863 " close down netrw explorer window 864 exe lexwinnr."wincmd w" 865 let g:netrw_winsize = -winwidth(0) 866 let t:netrw_lexposn = winsaveview() 867 close 868 if lexwinnr < curwin 869 let curwin= curwin - 1 870 endif 871 if lexwinnr != curwin 872 exe curwin."wincmd w" 873 endif 874 unlet t:netrw_lexbufnr 875 876 else 877 " open netrw explorer window 878 exe "1wincmd w" 879 let keep_altv = g:netrw_altv 880 let g:netrw_altv = 0 881 if a:count != 0 882 let netrw_winsize = g:netrw_winsize 883 let g:netrw_winsize = a:count 884 endif 885 let curfile= expand("%") 886 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new" 887 if a:0 > 0 && a1 != "" 888 call netrw#Explore(0,0,0,a1) 889 exe "Explore ".fnameescape(a1) 890 elseif curfile =~ '^\a\{3,}://' 891 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','','')) 892 else 893 call netrw#Explore(0,0,0,".") 894 endif 895 if a:count != 0 896 let g:netrw_winsize = netrw_winsize 897 endif 898 setlocal winfixwidth 899 let g:netrw_altv = keep_altv 900 let t:netrw_lexbufnr = bufnr("%") 901 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore. 902 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra 903 " effort to prevent mis-use of :Lex is warranted. 904 set bh=wipe 905 if exists("t:netrw_lexposn") 906 call winrestview(t:netrw_lexposn) 907 unlet t:netrw_lexposn 908 endif 909 endif 910 911 " set up default window for editing via <cr> 912 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1 913 if a:rightside 914 let g:netrw_chgwin= 1 915 else 916 let g:netrw_chgwin= 2 917 endif 918 endif 919 920 endfunction 921 922 " netrw#MakeTgt: make a target out of the directory name provided {{{2 923 function netrw#MakeTgt(dname) 924 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi) 925 let svpos = winsaveview() 926 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://') 927 if s:netrwmftgt_islocal 928 let netrwmftgt= simplify(a:dname) 929 else 930 let netrwmftgt= a:dname 931 endif 932 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt 933 " re-selected target, so just clear it 934 unlet s:netrwmftgt s:netrwmftgt_islocal 935 else 936 let s:netrwmftgt= netrwmftgt 937 endif 938 if g:netrw_fastbrowse <= 1 939 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir) 940 endif 941 call winrestview(svpos) 942 endfunction 943 944 " netrw#Obtain: {{{2 945 " netrw#Obtain(islocal,fname[,tgtdirectory]) 946 " islocal=0 obtain from remote source 947 " =1 obtain from local source 948 " fname : a filename or a list of filenames 949 " tgtdir : optional place where files are to go (not present, uses getcwd()) 950 function netrw#Obtain(islocal,fname,...) 951 " NetrwStatusLine support - for obtaining support 952 953 if type(a:fname) == 1 954 let fnamelist= [ a:fname ] 955 elseif type(a:fname) == 3 956 let fnamelist= a:fname 957 else 958 call netrw#msg#Notify('ERROR', 'attempting to use NetrwObtain on something not a filename or a list') 959 return 960 endif 961 if a:0 > 0 962 let tgtdir= a:1 963 else 964 let tgtdir= getcwd() 965 endif 966 967 if exists("b:netrw_islocal") && b:netrw_islocal 968 " obtain a file from local b:netrw_curdir to (local) tgtdir 969 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir 970 let topath = netrw#fs#ComposePath(tgtdir,"") 971 if has("win32") && !g:netrw_cygwin 972 " transfer files one at time 973 for fname in fnamelist 974 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".netrw#os#Escape(fname)." ".netrw#os#Escape(topath)) 975 if v:shell_error != 0 976 call netrw#msg#Notify('WARNING', printf('consider setting g:netrw_localcopycmd<%s> to something that works', g:netrw_localcopycmd)) 977 return 978 endif 979 endfor 980 else 981 " transfer files with one command 982 let filelist= join(map(deepcopy(fnamelist),"netrw#os#Escape(v:val)")) 983 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".netrw#os#Escape(topath)) 984 if v:shell_error != 0 985 call netrw#msg#Notify('WARNING', printf('consider setting g:netrw_localcopycmd<%s> to something that works', g:netrw_localcopycmd)) 986 return 987 endif 988 endif 989 elseif !exists("b:netrw_curdir") 990 call netrw#msg#Notify('ERROR', "local browsing directory doesn't exist!") 991 else 992 call netrw#msg#Notify('WARNING', 'local browsing directory and current directory are identical') 993 endif 994 995 else 996 " obtain files from remote b:netrw_curdir to local tgtdir 997 if type(a:fname) == 1 998 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname) 999 endif 1000 call s:NetrwMethod(b:netrw_curdir) 1001 if !s:NetrwValidateHostname(g:netrw_machine) 1002 call netrw#msg#Notify('ERROR', 'Rejecting invalid hostname: <%s>', g:netrw_machine) 1003 return 1004 endif 1005 1006 if b:netrw_method == 4 1007 " obtain file using scp 1008 if exists("g:netrw_port") && g:netrw_port != "" 1009 let useport= " ".g:netrw_scpport." ".g:netrw_port 1010 else 1011 let useport= "" 1012 endif 1013 if b:netrw_fname =~ '/' 1014 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','') 1015 else 1016 let path= "" 1017 endif 1018 let filelist= join(map(deepcopy(fnamelist),'escape(netrw#os#Escape(g:netrw_machine.":".path.v:val,1)," ")')) 1019 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_scp_cmd.netrw#os#Escape(useport,1)." ".filelist." ".netrw#os#Escape(tgtdir,1)) 1020 1021 elseif b:netrw_method == 2 1022 " obtain file using ftp + .netrc 1023 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars() 1024 let tmpbufnr= bufnr("%") 1025 setl ff=unix 1026 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" 1027 NetrwKeepj put =g:netrw_ftpmode 1028 endif 1029 1030 if exists("b:netrw_fname") && b:netrw_fname != "" 1031 call setline(line("$")+1,'cd "'.b:netrw_fname.'"') 1032 endif 1033 1034 if exists("g:netrw_ftpextracmd") 1035 NetrwKeepj put =g:netrw_ftpextracmd 1036 endif 1037 for fname in fnamelist 1038 call setline(line("$")+1,'get "'.fname.'"') 1039 endfor 1040 if exists("g:netrw_port") && g:netrw_port != "" 1041 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)." ".netrw#os#Escape(g:netrw_port,1)) 1042 else 1043 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)) 1044 endif 1045 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1046 if getline(1) !~ "^$" && getline(1) !~ '^Trying ' 1047 let debugkeep= &debug 1048 setl debug=msg 1049 call netrw#msg#Notify('ERROR', getline(1)) 1050 let &debug= debugkeep 1051 endif 1052 1053 elseif b:netrw_method == 3 1054 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc) 1055 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars() 1056 let tmpbufnr= bufnr("%") 1057 setl ff=unix 1058 1059 if exists("g:netrw_port") && g:netrw_port != "" 1060 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 1061 else 1062 NetrwKeepj put ='open '.g:netrw_machine 1063 endif 1064 1065 if exists("g:netrw_uid") && g:netrw_uid != "" 1066 if exists("g:netrw_ftp") && g:netrw_ftp == 1 1067 NetrwKeepj put =g:netrw_uid 1068 if exists("s:netrw_passwd") && s:netrw_passwd != "" 1069 NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 1070 endif 1071 elseif exists("s:netrw_passwd") 1072 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 1073 endif 1074 endif 1075 1076 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" 1077 NetrwKeepj put =g:netrw_ftpmode 1078 endif 1079 1080 if exists("b:netrw_fname") && b:netrw_fname != "" 1081 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"') 1082 endif 1083 1084 if exists("g:netrw_ftpextracmd") 1085 NetrwKeepj put =g:netrw_ftpextracmd 1086 endif 1087 1088 if exists("g:netrw_ftpextracmd") 1089 NetrwKeepj put =g:netrw_ftpextracmd 1090 endif 1091 for fname in fnamelist 1092 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"') 1093 endfor 1094 1095 " perform ftp: 1096 " -i : turns off interactive prompting from ftp 1097 " -n unix : DON'T use <.netrc>, even though it exists 1098 " -n win32: quit being obnoxious about password 1099 " Note: using "_dd to delete to the black hole register; avoids messing up @@ 1100 NetrwKeepj norm! 1G"_dd 1101 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) 1102 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1103 if getline(1) !~ "^$" 1104 call netrw#msg#Notify('ERROR', getline(1)) 1105 endif 1106 1107 elseif b:netrw_method == 9 1108 " obtain file using sftp 1109 if a:fname =~ '/' 1110 let localfile= substitute(a:fname,'^.*/','','') 1111 else 1112 let localfile= a:fname 1113 endif 1114 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".netrw#os#Escape(g:netrw_machine.":".b:netrw_fname,1).netrw#os#Escape(localfile)." ".netrw#os#Escape(tgtdir)) 1115 1116 elseif !exists("b:netrw_method") || b:netrw_method < 0 1117 " probably a badly formed url; protocol not recognized 1118 return 1119 1120 else 1121 " protocol recognized but not supported for Obtain (yet?) 1122 call netrw#msg#Notify('ERROR', 'current protocol not supported for obtaining file') 1123 return 1124 endif 1125 1126 " restore status line 1127 if type(a:fname) == 1 && exists("s:netrw_users_stl") 1128 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl) 1129 endif 1130 1131 endif 1132 1133 " cleanup 1134 if exists("tmpbufnr") 1135 if bufnr("%") != tmpbufnr 1136 exe tmpbufnr."bw!" 1137 else 1138 q! 1139 endif 1140 endif 1141 1142 endfunction 1143 1144 " netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2 1145 function netrw#Nread(mode,fname) 1146 let svpos= winsaveview() 1147 call netrw#NetRead(a:mode,a:fname) 1148 call winrestview(svpos) 1149 1150 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST 1151 if exists("w:netrw_bannercnt") 1152 " start with cursor just after the banner 1153 exe w:netrw_bannercnt 1154 endif 1155 endif 1156 endfunction 1157 1158 " s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2 1159 " Options get restored by s:NetrwOptionsRestore() 1160 " 1161 " Option handling: 1162 " * save user's options (s:NetrwOptionsSave) 1163 " * set netrw-safe options (s:NetrwOptionsSafe) 1164 " - change an option only when user option != safe option (s:netrwSetSafeSetting) 1165 " * restore user's options (s:netrwOPtionsRestore) 1166 " - restore a user option when != safe option (s:NetrwRestoreSetting) 1167 " vt: (variable type) normally its either "w:" or "s:" 1168 function s:NetrwOptionsSave(vt) 1169 1170 if !exists("{a:vt}netrw_optionsave") 1171 let {a:vt}netrw_optionsave= 1 1172 else 1173 return 1174 endif 1175 1176 " Save current settings and current directory 1177 let s:yykeep = @@ 1178 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif 1179 let {a:vt}netrw_aikeep = &l:ai 1180 let {a:vt}netrw_awkeep = &l:aw 1181 let {a:vt}netrw_bhkeep = &l:bh 1182 let {a:vt}netrw_blkeep = &l:bl 1183 let {a:vt}netrw_btkeep = &l:bt 1184 let {a:vt}netrw_bombkeep = &l:bomb 1185 let {a:vt}netrw_cedit = &cedit 1186 let {a:vt}netrw_cikeep = &l:ci 1187 let {a:vt}netrw_cinkeep = &l:cin 1188 let {a:vt}netrw_cinokeep = &l:cino 1189 let {a:vt}netrw_comkeep = &l:com 1190 let {a:vt}netrw_cpokeep = &l:cpo 1191 let {a:vt}netrw_cuckeep = &l:cuc 1192 let {a:vt}netrw_culkeep = &l:cul 1193 let {a:vt}netrw_diffkeep = &l:diff 1194 let {a:vt}netrw_fenkeep = &l:fen 1195 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep 1196 let {a:vt}netrw_ffkeep = &l:ff 1197 endif 1198 let {a:vt}netrw_fokeep = &l:fo " formatoptions 1199 let {a:vt}netrw_gdkeep = &l:gd " gdefault 1200 let {a:vt}netrw_gokeep = &go " guioptions 1201 let {a:vt}netrw_hidkeep = &l:hidden 1202 let {a:vt}netrw_imkeep = &l:im 1203 let {a:vt}netrw_iskkeep = &l:isk 1204 let {a:vt}netrw_lines = &lines 1205 let {a:vt}netrw_lskeep = &l:ls 1206 let {a:vt}netrw_makeep = &l:ma 1207 let {a:vt}netrw_magickeep = &l:magic 1208 let {a:vt}netrw_modkeep = &l:mod 1209 let {a:vt}netrw_nukeep = &l:nu 1210 let {a:vt}netrw_rnukeep = &l:rnu 1211 let {a:vt}netrw_repkeep = &l:report 1212 let {a:vt}netrw_rokeep = &l:ro 1213 let {a:vt}netrw_selkeep = &l:sel 1214 let {a:vt}netrw_spellkeep = &l:spell 1215 if !g:netrw_use_noswf 1216 let {a:vt}netrw_swfkeep = &l:swf 1217 endif 1218 let {a:vt}netrw_tskeep = &l:ts 1219 let {a:vt}netrw_twkeep = &l:tw " textwidth 1220 let {a:vt}netrw_wigkeep = &l:wig " wildignore 1221 let {a:vt}netrw_wrapkeep = &l:wrap 1222 let {a:vt}netrw_writekeep = &l:write 1223 1224 " save a few selected netrw-related variables 1225 if g:netrw_keepdir 1226 let {a:vt}netrw_dirkeep = getcwd() 1227 endif 1228 if has("clipboard") && g:netrw_clipboard 1229 sil! let {a:vt}netrw_starkeep = @* 1230 sil! let {a:vt}netrw_pluskeep = @+ 1231 endif 1232 sil! let {a:vt}netrw_slashkeep= @/ 1233 1234 endfunction 1235 1236 " s:NetrwOptionsSafe: sets options to help netrw do its job {{{2 1237 " Use s:NetrwSaveOptions() to save user settings 1238 " Use s:NetrwOptionsRestore() to restore user settings 1239 function s:NetrwOptionsSafe(islocal) 1240 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif 1241 call s:NetrwSetSafeSetting("&l:ai",0) 1242 call s:NetrwSetSafeSetting("&l:aw",0) 1243 call s:NetrwSetSafeSetting("&l:bl",0) 1244 call s:NetrwSetSafeSetting("&l:bomb",0) 1245 if a:islocal 1246 call s:NetrwSetSafeSetting("&l:bt","nofile") 1247 else 1248 call s:NetrwSetSafeSetting("&l:bt","acwrite") 1249 endif 1250 call s:NetrwSetSafeSetting("&l:ci",0) 1251 call s:NetrwSetSafeSetting("&l:cin",0) 1252 if g:netrw_fastbrowse > a:islocal 1253 call s:NetrwSetSafeSetting("&l:bh","hide") 1254 else 1255 call s:NetrwSetSafeSetting("&l:bh","delete") 1256 endif 1257 call s:NetrwSetSafeSetting("&l:cino","") 1258 call s:NetrwSetSafeSetting("&l:com","") 1259 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif 1260 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif 1261 setl fo=nroql2 1262 if &go =~ 'a' | set go-=a | endif 1263 if &go =~ 'A' | set go-=A | endif 1264 if &go =~ 'P' | set go-=P | endif 1265 call s:NetrwSetSafeSetting("&l:hid",0) 1266 call s:NetrwSetSafeSetting("&l:im",0) 1267 setl isk+=@ isk+=* isk+=/ 1268 call s:NetrwSetSafeSetting("&l:magic",1) 1269 if g:netrw_use_noswf 1270 call s:NetrwSetSafeSetting("swf",0) 1271 endif 1272 call s:NetrwSetSafeSetting("&l:report",10000) 1273 call s:NetrwSetSafeSetting("&l:sel","inclusive") 1274 call s:NetrwSetSafeSetting("&l:spell",0) 1275 call s:NetrwSetSafeSetting("&l:tw",0) 1276 call s:NetrwSetSafeSetting("&l:wig","") 1277 setl cedit& 1278 1279 " set up cuc and cul based on g:netrw_cursor and listing style 1280 " COMBAK -- cuc cul related 1281 call s:NetrwCursor(0) 1282 1283 " allow the user to override safe options 1284 if &ft == "netrw" 1285 keepalt NetrwKeepj doau FileType netrw 1286 endif 1287 1288 endfunction 1289 1290 " s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2 1291 function s:NetrwOptionsRestore(vt) 1292 if !exists("{a:vt}netrw_optionsave") 1293 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab) 1294 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match 1295 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+' 1296 filetype detect 1297 else 1298 setl ft=netrw 1299 endif 1300 return 1301 endif 1302 unlet {a:vt}netrw_optionsave 1303 1304 if exists("+acd") 1305 if exists("{a:vt}netrw_acdkeep") 1306 let curdir = getcwd() 1307 let &l:acd = {a:vt}netrw_acdkeep 1308 unlet {a:vt}netrw_acdkeep 1309 if &l:acd 1310 call s:NetrwLcd(curdir) 1311 endif 1312 endif 1313 endif 1314 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai") 1315 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw") 1316 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl") 1317 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt") 1318 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb") 1319 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit") 1320 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci") 1321 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin") 1322 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino") 1323 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com") 1324 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo") 1325 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff") 1326 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen") 1327 if exists("g:netrw_ffkeep") && g:netrw_ffkeep 1328 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff") 1329 endif 1330 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo") 1331 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd") 1332 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go") 1333 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden") 1334 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im") 1335 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk") 1336 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines") 1337 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls") 1338 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma") 1339 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic") 1340 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod") 1341 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu") 1342 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu") 1343 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report") 1344 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro") 1345 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel") 1346 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell") 1347 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw") 1348 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig") 1349 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap") 1350 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write") 1351 call s:NetrwRestoreSetting("s:yykeep","@@") 1352 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts. 1353 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces 1354 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018) 1355 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts") 1356 1357 if exists("{a:vt}netrw_swfkeep") 1358 if &directory == "" 1359 " user hasn't specified a swapfile directory; 1360 " netrw will temporarily set the swapfile directory 1361 " to the current directory as returned by getcwd(). 1362 let &l:directory= getcwd() 1363 sil! let &l:swf = {a:vt}netrw_swfkeep 1364 setl directory= 1365 unlet {a:vt}netrw_swfkeep 1366 elseif &l:swf != {a:vt}netrw_swfkeep 1367 if !g:netrw_use_noswf 1368 " following line causes a Press ENTER in windows -- can't seem to work around it!!! 1369 sil! let &l:swf= {a:vt}netrw_swfkeep 1370 endif 1371 unlet {a:vt}netrw_swfkeep 1372 endif 1373 endif 1374 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir 1375 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g') 1376 if exists("{a:vt}netrw_dirkeep") 1377 call s:NetrwLcd(dirkeep) 1378 unlet {a:vt}netrw_dirkeep 1379 endif 1380 endif 1381 if has("clipboard") && g:netrw_clipboard 1382 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*") 1383 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+") 1384 endif 1385 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/") 1386 1387 " Moved the filetype detect here from NetrwGetFile() because remote files 1388 " were having their filetype detect-generated settings overwritten by 1389 " NetrwOptionRestore. 1390 if &ft != "netrw" 1391 filetype detect 1392 endif 1393 endfunction 1394 1395 " s:NetrwSetSafeSetting: sets an option to a safe setting {{{2 1396 " but only when the options' value and the safe setting differ 1397 " Doing this means that netrw will not come up as having changed a 1398 " setting last when it really didn't actually change it. 1399 " 1400 " Called from s:NetrwOptionsSafe 1401 " ex. call s:NetrwSetSafeSetting("&l:sel","inclusive") 1402 function s:NetrwSetSafeSetting(setting,safesetting) 1403 1404 if a:setting =~ '^&' 1405 exe "let settingval= ".a:setting 1406 1407 if settingval != a:safesetting 1408 if type(a:safesetting) == 0 1409 exe "let ".a:setting."=".a:safesetting 1410 elseif type(a:safesetting) == 1 1411 exe "let ".a:setting."= '".a:safesetting."'" 1412 else 1413 call netrw#msg#Notify('ERROR', printf("(s:NetrwRestoreSetting) doesn't know how to restore %s with a safesetting of type#%s", a:setting, type(a:safesetting))) 1414 endif 1415 endif 1416 endif 1417 1418 endfunction 1419 1420 " s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2 1421 " but only if the setting value differs from the associated keepvar. 1422 " Doing this means that netrw will not come up as having changed a 1423 " setting last when it really didn't actually change it. 1424 " 1425 " Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting 1426 " keepvars are set up by s:NetrwOptionsSave 1427 function s:NetrwRestoreSetting(keepvar,setting) 1428 1429 " typically called from s:NetrwOptionsRestore 1430 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option') 1431 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel") 1432 " Restores option (but only if different) from a:keepvar 1433 if exists(a:keepvar) 1434 exe "let keepvarval= ".a:keepvar 1435 exe "let setting= ".a:setting 1436 1437 1438 if setting != keepvarval 1439 if type(a:setting) == 0 1440 exe "let ".a:setting."= ".keepvarval 1441 elseif type(a:setting) == 1 1442 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'" 1443 else 1444 call netrw#msg#Notify('ERROR', printf("(s:NetrwRestoreSetting) doesn't know how to restore %s with a setting of type#%s", a:keepvar, type(a:setting))) 1445 endif 1446 endif 1447 1448 exe "unlet ".a:keepvar 1449 endif 1450 1451 endfunction 1452 1453 " NetrwStatusLine: {{{2 1454 1455 function NetrwStatusLine() 1456 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") 1457 let &stl= s:netrw_explore_stl 1458 unlet! w:netrw_explore_bufnr w:netrw_explore_line 1459 return "" 1460 else 1461 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen 1462 endif 1463 endfunction 1464 1465 " Netrw Transfer Functions: {{{1 1466 1467 " netrw#NetRead: responsible for reading a file over the net {{{2 1468 " mode: =0 read remote file and insert before current line 1469 " =1 read remote file and insert after current line 1470 " =2 replace with remote file 1471 " =3 obtain file, but leave in temporary format 1472 function netrw#NetRead(mode,...) 1473 1474 " NetRead: save options {{{3 1475 call s:NetrwOptionsSave("w:") 1476 call s:NetrwOptionsSafe(0) 1477 call s:RestoreCursorline() 1478 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off. 1479 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still. 1480 setl bl 1481 1482 " NetRead: interpret mode into a readcmd {{{3 1483 if a:mode == 0 " read remote file before current line 1484 let readcmd = "0r" 1485 elseif a:mode == 1 " read file after current line 1486 let readcmd = "r" 1487 elseif a:mode == 2 " replace with remote file 1488 let readcmd = "%r" 1489 elseif a:mode == 3 " skip read of file (leave as temporary) 1490 let readcmd = "t" 1491 else 1492 exe a:mode 1493 let readcmd = "r" 1494 endif 1495 let ichoice = (a:0 == 0)? 0 : 1 1496 1497 " NetRead: get temporary filename {{{3 1498 let tmpfile= s:GetTempfile("") 1499 if tmpfile == "" 1500 return 1501 endif 1502 1503 while ichoice <= a:0 1504 1505 " attempt to repeat with previous host-file-etc 1506 if exists("b:netrw_lastfile") && a:0 == 0 1507 let choice = b:netrw_lastfile 1508 let ichoice= ichoice + 1 1509 1510 else 1511 exe "let choice= a:" . ichoice 1512 1513 if match(choice,"?") == 0 1514 " give help 1515 echomsg 'NetRead Usage:' 1516 echomsg ':Nread machine:path uses rcp' 1517 echomsg ':Nread "machine path" uses ftp with <.netrc>' 1518 echomsg ':Nread "machine id password path" uses ftp' 1519 echomsg ':Nread dav://machine[:port]/path uses cadaver' 1520 echomsg ':Nread fetch://machine/path uses fetch' 1521 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' 1522 echomsg ':Nread http://[user@]machine/path uses http wget' 1523 echomsg ':Nread file:///path uses elinks' 1524 echomsg ':Nread https://[user@]machine/path uses http wget' 1525 echomsg ':Nread rcp://[user@]machine/path uses rcp' 1526 echomsg ':Nread rsync://machine[:port]/path uses rsync' 1527 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp' 1528 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' 1529 sleep 4 1530 break 1531 1532 elseif match(choice,'^"') != -1 1533 " Reconstruct Choice if choice starts with '"' 1534 if match(choice,'"$') != -1 1535 " case "..." 1536 let choice= strpart(choice,1,strlen(choice)-2) 1537 else 1538 " case "... ... ..." 1539 let choice = strpart(choice,1,strlen(choice)-1) 1540 let wholechoice = "" 1541 1542 while match(choice,'"$') == -1 1543 let wholechoice = wholechoice . " " . choice 1544 let ichoice = ichoice + 1 1545 if ichoice > a:0 1546 call netrw#msg#Notify('ERROR', printf('Unbalanced string in filename "%s"', wholechoice)) 1547 return 1548 endif 1549 let choice= a:{ichoice} 1550 endwhile 1551 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) 1552 endif 1553 endif 1554 endif 1555 1556 let ichoice= ichoice + 1 1557 1558 " NetRead: Determine method of read (ftp, rcp, etc) {{{3 1559 call s:NetrwMethod(choice) 1560 if !exists("b:netrw_method") || b:netrw_method < 0 1561 return 1562 endif 1563 if !s:NetrwValidateHostname(g:netrw_machine) 1564 call netrw#msg#Notify('ERROR', printf('Rejecting invalid hostname: <%s>', g:netrw_machine)) 1565 return 1566 endif 1567 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix 1568 1569 " Check whether or not NetrwBrowse() should be handling this request 1570 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://' 1571 NetrwKeepj call s:NetrwBrowse(0,choice) 1572 return 1573 endif 1574 1575 " ============ 1576 " NetRead: Perform Protocol-Based Read {{{3 1577 " =========================== 1578 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 1579 echo "(netrw) Processing your read request..." 1580 endif 1581 1582 "......................................... 1583 " NetRead: (rcp) NetRead Method #1 {{{3 1584 if b:netrw_method == 1 " read with rcp 1585 " ER: nothing done with g:netrw_uid yet? 1586 " ER: on Win2K" rcp machine[.user]:file tmpfile 1587 " ER: when machine contains '.' adding .user is required (use $USERNAME) 1588 " ER: the tmpfile is full path: rcp sees C:\... as host C 1589 if s:netrw_has_nt_rcp == 1 1590 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) 1591 let uid_machine = g:netrw_machine .'.'. g:netrw_uid 1592 else 1593 " Any way needed it machine contains a '.' 1594 let uid_machine = g:netrw_machine .'.'. $USERNAME 1595 endif 1596 else 1597 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) 1598 let uid_machine = g:netrw_uid .'@'. g:netrw_machine 1599 else 1600 let uid_machine = g:netrw_machine 1601 endif 1602 endif 1603 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".netrw#os#Escape(uid_machine.":".b:netrw_fname,1)." ".netrw#os#Escape(tmpfile,1)) 1604 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1605 let b:netrw_lastfile = choice 1606 1607 "......................................... 1608 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3 1609 elseif b:netrw_method == 2 " read with ftp + <.netrc> 1610 let netrw_fname= b:netrw_fname 1611 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars() 1612 let filtbuf= bufnr("%") 1613 setl ff=unix 1614 NetrwKeepj put =g:netrw_ftpmode 1615 if exists("g:netrw_ftpextracmd") 1616 NetrwKeepj put =g:netrw_ftpextracmd 1617 endif 1618 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile) 1619 if exists("g:netrw_port") && g:netrw_port != "" 1620 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)." ".netrw#os#Escape(g:netrw_port,1)) 1621 else 1622 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)) 1623 endif 1624 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1625 if getline(1) !~ "^$" && getline(1) !~ '^Trying ' 1626 let debugkeep = &debug 1627 setl debug=msg 1628 call netrw#msg#Notify('ERROR', getline(1)) 1629 let &debug = debugkeep 1630 endif 1631 call s:SaveBufVars() 1632 keepj bd! 1633 if bufname("%") == "" && getline("$") == "" && line('$') == 1 1634 " needed when one sources a file in a nolbl setting window via ftp 1635 q! 1636 endif 1637 call s:RestoreBufVars() 1638 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1639 let b:netrw_lastfile = choice 1640 1641 "......................................... 1642 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3 1643 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname 1644 " Construct execution string (four lines) which will be passed through filter 1645 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) 1646 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars() 1647 let filtbuf= bufnr("%") 1648 setl ff=unix 1649 if exists("g:netrw_port") && g:netrw_port != "" 1650 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 1651 else 1652 NetrwKeepj put ='open '.g:netrw_machine 1653 endif 1654 1655 if exists("g:netrw_uid") && g:netrw_uid != "" 1656 if exists("g:netrw_ftp") && g:netrw_ftp == 1 1657 NetrwKeepj put =g:netrw_uid 1658 if exists("s:netrw_passwd") 1659 NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 1660 endif 1661 elseif exists("s:netrw_passwd") 1662 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 1663 endif 1664 endif 1665 1666 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" 1667 NetrwKeepj put =g:netrw_ftpmode 1668 endif 1669 if exists("g:netrw_ftpextracmd") 1670 NetrwKeepj put =g:netrw_ftpextracmd 1671 endif 1672 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile 1673 1674 " perform ftp: 1675 " -i : turns off interactive prompting from ftp 1676 " -n unix : DON'T use <.netrc>, even though it exists 1677 " -n win32: quit being obnoxious about password 1678 NetrwKeepj norm! 1G"_dd 1679 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) 1680 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1681 if getline(1) !~ "^$" 1682 call netrw#msg#Notify('ERROR', getline(1)) 1683 endif 1684 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars() 1685 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1686 let b:netrw_lastfile = choice 1687 1688 "......................................... 1689 " NetRead: (scp) NetRead Method #4 {{{3 1690 elseif b:netrw_method == 4 " read with scp 1691 if exists("g:netrw_port") && g:netrw_port != "" 1692 let useport= " ".g:netrw_scpport." ".g:netrw_port 1693 else 1694 let useport= "" 1695 endif 1696 " Using UNC notation in windows to get a unix like path. 1697 " This is workaround to avoid mis-handle windows local-path: 1698 if g:netrw_scp_cmd =~ '^scp' && has("win32") 1699 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '//' .. $COMPUTERNAME .. '/\1$/\2', '') 1700 else 1701 let tmpfile_get = tmpfile 1702 endif 1703 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(netrw#os#Escape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".netrw#os#Escape(tmpfile_get,1)) 1704 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1705 let b:netrw_lastfile = choice 1706 1707 "......................................... 1708 " NetRead: (http) NetRead Method #5 (wget) {{{3 1709 elseif b:netrw_method == 5 1710 if g:netrw_http_cmd == "" 1711 call netrw#msg#Notify('ERROR', 'neither the wget nor the fetch command is available') 1712 return 1713 endif 1714 1715 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd") 1716 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch) 1717 if exists("g:netrw_http_xcmd") 1718 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_http_cmd." ".netrw#os#Escape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".netrw#os#Escape(tmpfile,1)) 1719 else 1720 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_http_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)) 1721 endif 1722 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1723 1724 else 1725 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) 1726 let netrw_html= substitute(b:netrw_fname,"#.*$","","") 1727 let netrw_tag = substitute(b:netrw_fname,"^.*#","","") 1728 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_http_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(b:netrw_http."://".g:netrw_machine.netrw_html,1)) 1729 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1730 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>" 1731 endif 1732 let b:netrw_lastfile = choice 1733 setl ro nomod 1734 1735 "......................................... 1736 " NetRead: (dav) NetRead Method #6 {{{3 1737 elseif b:netrw_method == 6 1738 1739 if !executable(g:netrw_dav_cmd) 1740 call netrw#msg#Notify('ERROR', printf('%s is not executable', g:netrw_dav_cmd)) 1741 return 1742 endif 1743 if g:netrw_dav_cmd =~ "curl" 1744 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".netrw#os#Escape("dav://".g:netrw_machine.b:netrw_fname,1)." ".netrw#os#Escape(tmpfile,1)) 1745 else 1746 " Construct execution string (four lines) which will be passed through filter 1747 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) 1748 new 1749 setl ff=unix 1750 if exists("g:netrw_port") && g:netrw_port != "" 1751 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 1752 else 1753 NetrwKeepj put ='open '.g:netrw_machine 1754 endif 1755 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != "" 1756 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd 1757 endif 1758 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile 1759 NetrwKeepj put ='quit' 1760 1761 " perform cadaver operation: 1762 NetrwKeepj norm! 1G"_dd 1763 call netrw#os#Execute(s:netrw_silentxfer."%!".g:netrw_dav_cmd) 1764 keepj bd! 1765 endif 1766 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1767 let b:netrw_lastfile = choice 1768 1769 "......................................... 1770 " NetRead: (rsync) NetRead Method #7 {{{3 1771 elseif b:netrw_method == 7 1772 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".netrw#os#Escape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".netrw#os#Escape(tmpfile,1)) 1773 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) 1774 let b:netrw_lastfile = choice 1775 1776 "......................................... 1777 " NetRead: (fetch) NetRead Method #8 {{{3 1778 " fetch://[user@]host[:http]/path 1779 elseif b:netrw_method == 8 1780 if g:netrw_fetch_cmd == "" 1781 call netrw#msg#Notify('ERROR', "fetch command not available") 1782 return 1783 endif 1784 if exists("g:netrw_option") && g:netrw_option =~ ":https\=" 1785 let netrw_option= "http" 1786 else 1787 let netrw_option= "ftp" 1788 endif 1789 1790 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != "" 1791 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1)) 1792 else 1793 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1)) 1794 endif 1795 1796 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) 1797 let b:netrw_lastfile = choice 1798 setl ro nomod 1799 1800 "......................................... 1801 " NetRead: (sftp) NetRead Method #9 {{{3 1802 elseif b:netrw_method == 9 1803 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".netrw#os#Escape(g:netrw_machine.":".b:netrw_fname,1)." ".netrw#os#Escape(tmpfile,1)) 1804 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1805 let b:netrw_lastfile = choice 1806 1807 "......................................... 1808 " NetRead: (file) NetRead Method #10 {{{3 1809 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd") 1810 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_file_cmd." ".netrw#os#Escape(b:netrw_fname,1)." ".netrw#os#Escape(tmpfile,1)) 1811 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) 1812 let b:netrw_lastfile = choice 1813 1814 "......................................... 1815 " NetRead: Complain {{{3 1816 else 1817 call netrw#msg#Notify('WARNING', printf('unable to comply with your request<%s>', choice)) 1818 endif 1819 endwhile 1820 1821 " NetRead: cleanup {{{3 1822 if exists("b:netrw_method") 1823 unlet b:netrw_method 1824 unlet b:netrw_fname 1825 endif 1826 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz' 1827 call netrw#fs#Remove(tmpfile) 1828 endif 1829 NetrwKeepj call s:NetrwOptionsRestore("w:") 1830 1831 endfunction 1832 1833 " netrw#NetWrite: responsible for writing a file over the net {{{2 1834 function netrw#NetWrite(...) range 1835 1836 " NetWrite: option handling {{{3 1837 let mod= 0 1838 call s:NetrwOptionsSave("w:") 1839 call s:NetrwOptionsSafe(0) 1840 1841 " NetWrite: Get Temporary Filename {{{3 1842 let tmpfile= s:GetTempfile("") 1843 if tmpfile == "" 1844 return 1845 endif 1846 1847 if a:0 == 0 1848 let ichoice = 0 1849 else 1850 let ichoice = 1 1851 endif 1852 1853 let curbufname= expand("%") 1854 if &binary 1855 " For binary writes, always write entire file. 1856 " (line numbers don't really make sense for that). 1857 " Also supports the writing of tar and zip files. 1858 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile) 1859 elseif g:netrw_cygwin 1860 " write (selected portion of) file to temporary 1861 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','') 1862 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile) 1863 else 1864 " write (selected portion of) file to temporary 1865 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile) 1866 endif 1867 1868 if curbufname == "" 1869 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes 1870 " on the temporary file's name. Deletion of the temporary file during 1871 " cleanup then causes an error message. 1872 0file! 1873 endif 1874 1875 " NetWrite: while choice loop: {{{3 1876 while ichoice <= a:0 1877 1878 " Process arguments: {{{4 1879 " attempt to repeat with previous host-file-etc 1880 if exists("b:netrw_lastfile") && a:0 == 0 1881 let choice = b:netrw_lastfile 1882 let ichoice= ichoice + 1 1883 else 1884 exe "let choice= a:" . ichoice 1885 1886 " Reconstruct Choice when choice starts with '"' 1887 if match(choice,"?") == 0 1888 echomsg 'NetWrite Usage:"' 1889 echomsg ':Nwrite machine:path uses rcp' 1890 echomsg ':Nwrite "machine path" uses ftp with <.netrc>' 1891 echomsg ':Nwrite "machine id password path" uses ftp' 1892 echomsg ':Nwrite dav://[user@]machine/path uses cadaver' 1893 echomsg ':Nwrite fetch://[user@]machine/path uses fetch' 1894 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' 1895 echomsg ':Nwrite rcp://machine/path uses rcp' 1896 echomsg ':Nwrite rsync://[user@]machine/path uses rsync' 1897 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' 1898 echomsg ':Nwrite sftp://[user@]machine/path uses sftp' 1899 sleep 4 1900 break 1901 1902 elseif match(choice,"^\"") != -1 1903 if match(choice,"\"$") != -1 1904 " case "..." 1905 let choice=strpart(choice,1,strlen(choice)-2) 1906 else 1907 " case "... ... ..." 1908 let choice = strpart(choice,1,strlen(choice)-1) 1909 let wholechoice = "" 1910 1911 while match(choice,"\"$") == -1 1912 let wholechoice= wholechoice . " " . choice 1913 let ichoice = ichoice + 1 1914 if choice > a:0 1915 call netrw#msg#Notify('ERROR', printf('Unbalanced string in filename "%s"', wholechoice)) 1916 return 1917 endif 1918 let choice= a:{ichoice} 1919 endwhile 1920 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) 1921 endif 1922 endif 1923 endif 1924 let ichoice= ichoice + 1 1925 1926 " Determine method of write (ftp, rcp, etc) {{{4 1927 NetrwKeepj call s:NetrwMethod(choice) 1928 if !exists("b:netrw_method") || b:netrw_method < 0 1929 return 1930 endif 1931 if !s:NetrwValidateHostname(g:netrw_machine) 1932 call netrw#msg#Notify('ERROR', printf('Rejecting invalid hostname: <%s>', g:netrw_machine)) 1933 return 1934 endif 1935 1936 " ============= 1937 " NetWrite: Perform Protocol-Based Write {{{3 1938 " ============================ 1939 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 1940 echo "(netrw) Processing your write request..." 1941 endif 1942 1943 "......................................... 1944 " NetWrite: (rcp) NetWrite Method #1 {{{3 1945 if b:netrw_method == 1 1946 if s:netrw_has_nt_rcp == 1 1947 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) 1948 let uid_machine = g:netrw_machine .'.'. g:netrw_uid 1949 else 1950 let uid_machine = g:netrw_machine .'.'. $USERNAME 1951 endif 1952 else 1953 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) 1954 let uid_machine = g:netrw_uid .'@'. g:netrw_machine 1955 else 1956 let uid_machine = g:netrw_machine 1957 endif 1958 endif 1959 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(uid_machine.":".b:netrw_fname,1)) 1960 let b:netrw_lastfile = choice 1961 1962 "......................................... 1963 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3 1964 elseif b:netrw_method == 2 1965 let netrw_fname = b:netrw_fname 1966 1967 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 1968 let bhkeep = &l:bh 1969 let curbuf = bufnr("%") 1970 setl bh=hide 1971 keepj keepalt enew 1972 1973 setl ff=unix 1974 NetrwKeepj put =g:netrw_ftpmode 1975 if exists("g:netrw_ftpextracmd") 1976 NetrwKeepj put =g:netrw_ftpextracmd 1977 endif 1978 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"') 1979 if exists("g:netrw_port") && g:netrw_port != "" 1980 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)." ".netrw#os#Escape(g:netrw_port,1)) 1981 else 1982 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)) 1983 endif 1984 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1985 if getline(1) !~ "^$" 1986 call netrw#msg#Notify('ERROR', getline(1)) 1987 let mod=1 1988 endif 1989 1990 " remove enew buffer (quietly) 1991 let filtbuf= bufnr("%") 1992 exe curbuf."b!" 1993 let &l:bh = bhkeep 1994 exe filtbuf."bw!" 1995 1996 let b:netrw_lastfile = choice 1997 1998 "......................................... 1999 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3 2000 elseif b:netrw_method == 3 2001 " Construct execution string (three or more lines) which will be passed through filter 2002 let netrw_fname = b:netrw_fname 2003 let bhkeep = &l:bh 2004 2005 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2006 let curbuf = bufnr("%") 2007 setl bh=hide 2008 keepj keepalt enew 2009 setl ff=unix 2010 2011 if exists("g:netrw_port") && g:netrw_port != "" 2012 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 2013 else 2014 NetrwKeepj put ='open '.g:netrw_machine 2015 endif 2016 if exists("g:netrw_uid") && g:netrw_uid != "" 2017 if exists("g:netrw_ftp") && g:netrw_ftp == 1 2018 NetrwKeepj put =g:netrw_uid 2019 if exists("s:netrw_passwd") && s:netrw_passwd != "" 2020 NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 2021 endif 2022 elseif exists("s:netrw_passwd") && s:netrw_passwd != "" 2023 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 2024 endif 2025 endif 2026 NetrwKeepj put =g:netrw_ftpmode 2027 if exists("g:netrw_ftpextracmd") 2028 NetrwKeepj put =g:netrw_ftpextracmd 2029 endif 2030 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"' 2031 " save choice/id/password for future use 2032 let b:netrw_lastfile = choice 2033 2034 " perform ftp: 2035 " -i : turns off interactive prompting from ftp 2036 " -n unix : DON'T use <.netrc>, even though it exists 2037 " -n win32: quit being obnoxious about password 2038 NetrwKeepj norm! 1G"_dd 2039 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) 2040 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 2041 if getline(1) !~ "^$" 2042 call netrw#msg#Notify('ERROR', getline(1)) 2043 let mod=1 2044 endif 2045 2046 " remove enew buffer (quietly) 2047 let filtbuf= bufnr("%") 2048 exe curbuf."b!" 2049 let &l:bh= bhkeep 2050 exe filtbuf."bw!" 2051 2052 "......................................... 2053 " NetWrite: (scp) NetWrite Method #4 {{{3 2054 elseif b:netrw_method == 4 2055 if exists("g:netrw_port") && g:netrw_port != "" 2056 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port) 2057 else 2058 let useport= "" 2059 endif 2060 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(g:netrw_machine.":".b:netrw_fname,1)) 2061 let b:netrw_lastfile = choice 2062 2063 "......................................... 2064 " NetWrite: (http) NetWrite Method #5 {{{3 2065 elseif b:netrw_method == 5 2066 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","") 2067 if executable(curl) 2068 let url= g:netrw_choice 2069 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(url,1) ) 2070 else 2071 call netrw#msg#Notify('ERROR', printf("can't write to http using <%s>", g:netrw_http_put_cmd)) 2072 endif 2073 2074 "......................................... 2075 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3 2076 elseif b:netrw_method == 6 2077 2078 " Construct execution string (four lines) which will be passed through filter 2079 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape) 2080 let bhkeep = &l:bh 2081 2082 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2083 let curbuf = bufnr("%") 2084 setl bh=hide 2085 keepj keepalt enew 2086 2087 setl ff=unix 2088 if exists("g:netrw_port") && g:netrw_port != "" 2089 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 2090 else 2091 NetrwKeepj put ='open '.g:netrw_machine 2092 endif 2093 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != "" 2094 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd 2095 endif 2096 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname 2097 2098 " perform cadaver operation: 2099 NetrwKeepj norm! 1G"_dd 2100 call netrw#os#Execute(s:netrw_silentxfer."%!".g:netrw_dav_cmd) 2101 2102 " remove enew buffer (quietly) 2103 let filtbuf= bufnr("%") 2104 exe curbuf."b!" 2105 let &l:bh = bhkeep 2106 exe filtbuf."bw!" 2107 2108 let b:netrw_lastfile = choice 2109 2110 "......................................... 2111 " NetWrite: (rsync) NetWrite Method #7 {{{3 2112 elseif b:netrw_method == 7 2113 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".netrw#os#Escape(tmpfile,1)." ".netrw#os#Escape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)) 2114 let b:netrw_lastfile = choice 2115 2116 "......................................... 2117 " NetWrite: (sftp) NetWrite Method #9 {{{3 2118 elseif b:netrw_method == 9 2119 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) 2120 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) 2121 let uid_machine = g:netrw_uid .'@'. g:netrw_machine 2122 else 2123 let uid_machine = g:netrw_machine 2124 endif 2125 2126 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2127 let bhkeep = &l:bh 2128 let curbuf = bufnr("%") 2129 setl bh=hide 2130 keepj keepalt enew 2131 2132 setl ff=unix 2133 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname) 2134 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g") 2135 call netrw#os#Execute(s:netrw_silentxfer."%!".sftpcmd.' '.netrw#os#Escape(uid_machine,1)) 2136 let filtbuf= bufnr("%") 2137 exe curbuf."b!" 2138 let &l:bh = bhkeep 2139 exe filtbuf."bw!" 2140 let b:netrw_lastfile = choice 2141 2142 "......................................... 2143 " NetWrite: Complain {{{3 2144 else 2145 call netrw#msg#Notify('WARNING', printf('unable to comply with your request<%s>', choice)) 2146 let leavemod= 1 2147 endif 2148 endwhile 2149 2150 " NetWrite: Cleanup: {{{3 2151 if s:FileReadable(tmpfile) 2152 call netrw#fs#Remove(tmpfile) 2153 endif 2154 call s:NetrwOptionsRestore("w:") 2155 2156 if a:firstline == 1 && a:lastline == line("$") 2157 " restore modifiability; usually equivalent to set nomod 2158 let &l:mod= mod 2159 elseif !exists("leavemod") 2160 " indicate that the buffer has not been modified since last written 2161 setl nomod 2162 endif 2163 2164 endfunction 2165 2166 " netrw#NetSource: source a remotely hosted Vim script {{{2 2167 " uses NetRead to get a copy of the file into a temporarily file, 2168 " then sources that file, 2169 " then removes that file. 2170 function netrw#NetSource(...) 2171 if a:0 > 0 && a:1 == '?' 2172 " give help 2173 echomsg 'NetSource Usage:' 2174 echomsg ':Nsource dav://machine[:port]/path uses cadaver' 2175 echomsg ':Nsource fetch://machine/path uses fetch' 2176 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' 2177 echomsg ':Nsource http[s]://[user@]machine/path uses http wget' 2178 echomsg ':Nsource rcp://[user@]machine/path uses rcp' 2179 echomsg ':Nsource rsync://machine[:port]/path uses rsync' 2180 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp' 2181 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp' 2182 sleep 4 2183 else 2184 let i= 1 2185 while i <= a:0 2186 call netrw#NetRead(3,a:{i}) 2187 if s:FileReadable(s:netrw_tmpfile) 2188 exe "so ".fnameescape(s:netrw_tmpfile) 2189 if delete(s:netrw_tmpfile) 2190 call netrw#msg#Notify('ERROR', 'unable to delete directory <%s>', s:netrw_tmpfile) 2191 endif 2192 unlet s:netrw_tmpfile 2193 else 2194 call netrw#msg#Notify('ERROR', printf('unable to source <%s>!', a:{i})) 2195 endif 2196 let i= i + 1 2197 endwhile 2198 endif 2199 endfunction 2200 2201 " netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2 2202 " (implements the :Ntree command) 2203 function netrw#SetTreetop(iscmd,...) 2204 2205 " iscmd==0: netrw#SetTreetop called using gn mapping 2206 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line 2207 " clear out the current tree 2208 if exists("w:netrw_treetop") 2209 let inittreetop= w:netrw_treetop 2210 unlet w:netrw_treetop 2211 endif 2212 if exists("w:netrw_treedict") 2213 unlet w:netrw_treedict 2214 endif 2215 2216 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop") 2217 let treedir = s:NetrwTreePath(inittreetop) 2218 else 2219 if isdirectory(s:NetrwFile(a:1)) 2220 let treedir = a:1 2221 let s:netrw_treetop = treedir 2222 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://') 2223 let treedir = b:netrw_curdir."/".a:1 2224 let s:netrw_treetop = treedir 2225 else 2226 " normally the cursor is left in the message window. 2227 " However, here this results in the directory being listed in the message window, which is not wanted. 2228 let netrwbuf= bufnr("%") 2229 call netrw#msg#Notify('ERROR', printf("sorry, %s doesn't seem to be a directory!", a:1)) 2230 exe bufwinnr(netrwbuf)."wincmd w" 2231 let treedir = "." 2232 let s:netrw_treetop = getcwd() 2233 endif 2234 endif 2235 2236 " determine if treedir is remote or local 2237 let islocal= expand("%") !~ '^\a\{3,}://' 2238 2239 " browse the resulting directory 2240 if islocal 2241 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0)) 2242 else 2243 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0)) 2244 endif 2245 2246 endfunction 2247 2248 " s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2 2249 " readcmd == %r : replace buffer with newly read file 2250 " == 0r : read file at top of buffer 2251 " == r : read file after current line 2252 " == t : leave file in temporary form (ie. don't read into buffer) 2253 function s:NetrwGetFile(readcmd, tfile, method) 2254 2255 " readcmd=='t': simply do nothing 2256 if a:readcmd == 't' 2257 return 2258 endif 2259 2260 " get name of remote filename (ie. url and all) 2261 let rfile= bufname("%") 2262 2263 if exists("*NetReadFixup") 2264 " for the use of NetReadFixup (not otherwise used internally) 2265 let line2= line("$") 2266 endif 2267 2268 if a:readcmd[0] == '%' 2269 " get file into buffer 2270 2271 " rename the current buffer to the temp file (ie. tfile) 2272 if g:netrw_cygwin 2273 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','') 2274 else 2275 let tfile= a:tfile 2276 endif 2277 call s:NetrwBufRename(tfile) 2278 2279 " edit temporary file (ie. read the temporary file in) 2280 if rfile =~ '\.zip$' 2281 call zip#Browse(tfile) 2282 elseif rfile =~ '\.tar$' 2283 call tar#Browse(tfile) 2284 elseif rfile =~ '\.tar\.gz$' 2285 call tar#Browse(tfile) 2286 elseif rfile =~ '\.tar\.bz2$' 2287 call tar#Browse(tfile) 2288 elseif rfile =~ '\.tar\.xz$' 2289 call tar#Browse(tfile) 2290 elseif rfile =~ '\.txz$' 2291 call tar#Browse(tfile) 2292 else 2293 NetrwKeepj e! 2294 endif 2295 2296 " rename buffer back to remote filename 2297 call s:NetrwBufRename(rfile) 2298 2299 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype 2300 " Detect filetype of local version of remote file. 2301 " Note that isk must not include a "/" for scripts.vim 2302 " to process this detection correctly. 2303 " setl ft= 2304 let iskkeep= &isk 2305 setl isk-=/ 2306 filetype detect 2307 let &l:isk= iskkeep 2308 let line1 = 1 2309 let line2 = line("$") 2310 2311 elseif !&ma 2312 " attempting to read a file after the current line in the file, but the buffer is not modifiable 2313 call netrw#msg#Notify('WARNING', printf('attempt to read<%s> into a non-modifiable buffer!', a:tfile)) 2314 return 2315 2316 elseif s:FileReadable(a:tfile) 2317 " read file after current line 2318 let curline = line(".") 2319 let lastline= line("$") 2320 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile) 2321 let line1= curline + 1 2322 let line2= line("$") - lastline + 1 2323 2324 else 2325 " not readable 2326 call netrw#msg#Notify('WARNING', printf('file <%s> not readable', a:tfile)) 2327 return 2328 endif 2329 2330 " User-provided (ie. optional) fix-it-up command 2331 if exists("*NetReadFixup") 2332 NetrwKeepj call NetReadFixup(a:method, line1, line2) 2333 endif 2334 2335 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu 2336 " update the Buffers menu 2337 NetrwKeepj call s:UpdateBuffersMenu() 2338 endif 2339 2340 2341 " make sure file is being displayed 2342 " redraw! 2343 2344 endfunction 2345 2346 " s:NetrwMethod: determine method of transfer {{{2 2347 " Input: 2348 " choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file] 2349 " Output: 2350 " b:netrw_method= 1: rcp 2351 " 2: ftp + <.netrc> 2352 " 3: ftp + machine, id, password, and [path]filename 2353 " 4: scp 2354 " 5: http[s] (wget) 2355 " 6: dav 2356 " 7: rsync 2357 " 8: fetch 2358 " 9: sftp 2359 " 10: file 2360 " g:netrw_machine= hostname 2361 " b:netrw_fname = filename 2362 " g:netrw_port = optional port number (for ftp) 2363 " g:netrw_choice = copy of input url (choice) 2364 function s:NetrwMethod(choice) 2365 2366 " sanity check: choice should have at least three slashes in it 2367 if strlen(substitute(a:choice,'[^/]','','g')) < 3 2368 call netrw#msg#Notify('ERROR', 'not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])') 2369 let b:netrw_method = -1 2370 return 2371 endif 2372 2373 " record current g:netrw_machine, if any 2374 " curmachine used if protocol == ftp and no .netrc 2375 if exists("g:netrw_machine") 2376 let curmachine= g:netrw_machine 2377 else 2378 let curmachine= "N O T A HOST" 2379 endif 2380 if exists("g:netrw_port") 2381 let netrw_port= g:netrw_port 2382 endif 2383 2384 " insure that netrw_ftp_cmd starts off every method determination 2385 " with the current g:netrw_ftp_cmd 2386 let s:netrw_ftp_cmd= g:netrw_ftp_cmd 2387 2388 " initialization 2389 let b:netrw_method = 0 2390 let g:netrw_machine = "" 2391 let b:netrw_fname = "" 2392 let g:netrw_port = "" 2393 let g:netrw_choice = a:choice 2394 2395 " Patterns: 2396 " mipf : a:machine a:id password filename Use ftp 2397 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd 2398 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd 2399 " rcpurm : rcp://[user@]host/filename Use rcp 2400 " rcphf : [user@]host:filename Use rcp 2401 " scpurm : scp://[user@]host[[#:]port]/filename Use scp 2402 " httpurm : http[s]://[user@]host/filename Use wget 2403 " davurm : dav[s]://host[:port]/path Use cadaver/curl 2404 " rsyncurm : rsync://host[:port]/path Use rsync 2405 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) 2406 " sftpurm : sftp://[user@]host/filename Use scp 2407 " fileurm : file://[user@]host/filename Use elinks or links 2408 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' 2409 let mf = '^\(\S\+\)\s\+\(\S\+\)$' 2410 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' 2411 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$' 2412 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' 2413 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$' 2414 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$' 2415 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$' 2416 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' 2417 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' 2418 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' 2419 let fileurm = '^file\=://\(.*\)$' 2420 2421 " Determine Method 2422 " Method#1: rcp://user@hostname/...path-to-file {{{3 2423 if match(a:choice,rcpurm) == 0 2424 let b:netrw_method = 1 2425 let userid = substitute(a:choice,rcpurm,'\1',"") 2426 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"") 2427 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"") 2428 if userid != "" 2429 let g:netrw_uid= userid 2430 endif 2431 2432 " Method#4: scp://user@hostname/...path-to-file {{{3 2433 elseif match(a:choice,scpurm) == 0 2434 let b:netrw_method = 4 2435 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"") 2436 let g:netrw_port = substitute(a:choice,scpurm,'\2',"") 2437 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") 2438 2439 " Method#5: http[s]://user@hostname/...path-to-file {{{3 2440 elseif match(a:choice,httpurm) == 0 2441 let b:netrw_method = 5 2442 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"") 2443 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"") 2444 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http" 2445 2446 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3 2447 elseif match(a:choice,davurm) == 0 2448 let b:netrw_method= 6 2449 if a:choice =~ 'davs:' 2450 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"") 2451 else 2452 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"") 2453 endif 2454 let b:netrw_fname = substitute(a:choice,davurm,'\3',"") 2455 2456 " Method#7: rsync://user@hostname/...path-to-file {{{3 2457 elseif match(a:choice,rsyncurm) == 0 2458 let b:netrw_method = 7 2459 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"") 2460 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"") 2461 2462 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3 2463 elseif match(a:choice,ftpurm) == 0 2464 let userid = substitute(a:choice,ftpurm,'\2',"") 2465 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"") 2466 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"") 2467 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"") 2468 if userid != "" 2469 let g:netrw_uid= userid 2470 endif 2471 2472 if curmachine != g:netrw_machine 2473 if exists("s:netrw_hup[".g:netrw_machine."]") 2474 call netrw#NetUserPass("ftp:".g:netrw_machine) 2475 elseif exists("s:netrw_passwd") 2476 " if there's a change in hostname, require password re-entry 2477 unlet s:netrw_passwd 2478 endif 2479 if exists("netrw_port") 2480 unlet netrw_port 2481 endif 2482 endif 2483 2484 if exists("g:netrw_uid") && exists("s:netrw_passwd") 2485 let b:netrw_method = 3 2486 else 2487 let host= substitute(g:netrw_machine,'\..*$','','') 2488 if exists("s:netrw_hup[host]") 2489 call netrw#NetUserPass("ftp:".host) 2490 2491 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:' 2492 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>' 2493 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'') 2494 endif 2495 let b:netrw_method= 2 2496 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc 2497 let b:netrw_method= 2 2498 else 2499 if !exists("g:netrw_uid") || g:netrw_uid == "" 2500 call netrw#NetUserPass() 2501 elseif !exists("s:netrw_passwd") || s:netrw_passwd == "" 2502 call netrw#NetUserPass(g:netrw_uid) 2503 " else just use current g:netrw_uid and s:netrw_passwd 2504 endif 2505 let b:netrw_method= 3 2506 endif 2507 endif 2508 2509 " Method#8: fetch {{{3 2510 elseif match(a:choice,fetchurm) == 0 2511 let b:netrw_method = 8 2512 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"") 2513 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"") 2514 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"") 2515 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"") 2516 2517 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3 2518 elseif match(a:choice,mipf) == 0 2519 let b:netrw_method = 3 2520 let g:netrw_machine = substitute(a:choice,mipf,'\1',"") 2521 let g:netrw_uid = substitute(a:choice,mipf,'\2',"") 2522 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"") 2523 let b:netrw_fname = substitute(a:choice,mipf,'\4',"") 2524 call netrw#NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd) 2525 2526 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3 2527 elseif match(a:choice,mf) == 0 2528 if exists("g:netrw_uid") && exists("s:netrw_passwd") 2529 let b:netrw_method = 3 2530 let g:netrw_machine = substitute(a:choice,mf,'\1',"") 2531 let b:netrw_fname = substitute(a:choice,mf,'\2',"") 2532 2533 elseif s:FileReadable(expand("$HOME/.netrc")) 2534 let b:netrw_method = 2 2535 let g:netrw_machine = substitute(a:choice,mf,'\1',"") 2536 let b:netrw_fname = substitute(a:choice,mf,'\2',"") 2537 endif 2538 2539 " Method#9: sftp://user@hostname/...path-to-file {{{3 2540 elseif match(a:choice,sftpurm) == 0 2541 let b:netrw_method = 9 2542 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"") 2543 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"") 2544 2545 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3 2546 elseif match(a:choice,rcphf) == 0 2547 let b:netrw_method = 1 2548 let userid = substitute(a:choice,rcphf,'\2',"") 2549 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"") 2550 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"") 2551 if userid != "" 2552 let g:netrw_uid= userid 2553 endif 2554 2555 " Method#10: file://user@hostname/...path-to-file {{{3 2556 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd") 2557 let b:netrw_method = 10 2558 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"") 2559 2560 " Cannot Determine Method {{{3 2561 else 2562 call netrw#msg#Notify('WARNING', 'cannot determine method (format: protocol://[user@]hostname[:port]/[path])') 2563 let b:netrw_method = -1 2564 endif 2565 "}}}3 2566 2567 if g:netrw_port != "" 2568 " remove any leading [:#] from port number 2569 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','') 2570 elseif exists("netrw_port") 2571 " retain port number as implicit for subsequent ftp operations 2572 let g:netrw_port= netrw_port 2573 endif 2574 2575 endfunction 2576 2577 " s:NetrwValidateHostname: Validate that the hostname is valid {{{2 2578 " Input: 2579 " hostname, may include an optional username and port number, e.g. 2580 " user@hostname:port 2581 " allow a alphanumeric hostname or an IPv(4/6) address 2582 " Output: 2583 " true if g:netrw_machine is valid according to RFC1123 #Section 2 2584 function s:NetrwValidateHostname(hostname) 2585 " Username: 2586 let user_pat = '\%([a-zA-Z0-9._-]\+@\)\?' 2587 " Hostname: 1-64 chars, alphanumeric/dots/hyphens. 2588 " No leading/trailing dots/hyphens. 2589 let host_pat = '[a-zA-Z0-9_]\%([-a-zA-Z0-9._]\{0,62}[a-zA-Z0-9_]\)\?' 2590 " Port: 16 bit unsigned integer 2591 let port_pat = '\%(:\d\{1,5\}\)\?$' 2592 2593 " IPv4: 1-3 digits separated by dots 2594 let ipv4_pat = '\%(\d\{1,3}\.\)\{3\}\d\{1,3\}' 2595 2596 " IPv6: Hex, colons, and optional brackets 2597 let ipv6_pat = '\[\?\%([a-fA-F0-9:]\{2,}\)\+\]\?' 2598 2599 return a:hostname =~? '^'.user_pat.host_pat.port_pat || 2600 \ a:hostname =~? '^'.user_pat.ipv4_pat.port_pat || 2601 \ a:hostname =~? '^'.user_pat.ipv6_pat.port_pat 2602 endfunction 2603 2604 " NetUserPass: set username and password for subsequent ftp transfer {{{2 2605 " Usage: :call netrw#NetUserPass() -- will prompt for userid and password 2606 " :call netrw#NetUserPass("uid") -- will prompt for password 2607 " :call netrw#NetUserPass("uid","password") -- sets global userid and password 2608 " :call netrw#NetUserPass("ftp:host") -- looks up userid and password using hup dictionary 2609 " :call netrw#NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password 2610 function netrw#NetUserPass(...) 2611 2612 2613 if !exists('s:netrw_hup') 2614 let s:netrw_hup= {} 2615 endif 2616 2617 if a:0 == 0 2618 " case: no input arguments 2619 2620 " change host and username if not previously entered; get new password 2621 if !exists("g:netrw_machine") 2622 let g:netrw_machine= input('Enter hostname: ') 2623 endif 2624 if !exists("g:netrw_uid") || g:netrw_uid == "" 2625 " get username (user-id) via prompt 2626 let g:netrw_uid= input('Enter username: ') 2627 endif 2628 " get password via prompting 2629 let s:netrw_passwd= inputsecret("Enter Password: ") 2630 2631 " set up hup database 2632 let host = substitute(g:netrw_machine,'\..*$','','') 2633 if !exists('s:netrw_hup[host]') 2634 let s:netrw_hup[host]= {} 2635 endif 2636 let s:netrw_hup[host].uid = g:netrw_uid 2637 let s:netrw_hup[host].passwd = s:netrw_passwd 2638 2639 elseif a:0 == 1 2640 " case: one input argument 2641 2642 if a:1 =~ '^ftp:' 2643 " get host from ftp:... url 2644 " access userid and password from hup (host-user-passwd) dictionary 2645 let host = substitute(a:1,'^ftp:','','') 2646 let host = substitute(host,'\..*','','') 2647 if exists("s:netrw_hup[host]") 2648 let g:netrw_uid = s:netrw_hup[host].uid 2649 let s:netrw_passwd = s:netrw_hup[host].passwd 2650 else 2651 let g:netrw_uid = input("Enter UserId: ") 2652 let s:netrw_passwd = inputsecret("Enter Password: ") 2653 endif 2654 2655 else 2656 " case: one input argument, not an url. Using it as a new user-id. 2657 if exists("g:netrw_machine") 2658 if g:netrw_machine =~ '[0-9.]\+' 2659 let host= g:netrw_machine 2660 else 2661 let host= substitute(g:netrw_machine,'\..*$','','') 2662 endif 2663 else 2664 let g:netrw_machine= input('Enter hostname: ') 2665 endif 2666 let g:netrw_uid = a:1 2667 if exists("g:netrw_passwd") 2668 " ask for password if one not previously entered 2669 let s:netrw_passwd= g:netrw_passwd 2670 else 2671 let s:netrw_passwd = inputsecret("Enter Password: ") 2672 endif 2673 endif 2674 2675 if exists("host") 2676 if !exists('s:netrw_hup[host]') 2677 let s:netrw_hup[host]= {} 2678 endif 2679 let s:netrw_hup[host].uid = g:netrw_uid 2680 let s:netrw_hup[host].passwd = s:netrw_passwd 2681 endif 2682 2683 elseif a:0 == 2 2684 let g:netrw_uid = a:1 2685 let s:netrw_passwd = a:2 2686 2687 elseif a:0 == 3 2688 " enter hostname, user-id, and password into the hup dictionary 2689 let host = substitute(a:1,'^\a\+:','','') 2690 let host = substitute(host,'\..*$','','') 2691 if !exists('s:netrw_hup[host]') 2692 let s:netrw_hup[host]= {} 2693 endif 2694 let s:netrw_hup[host].uid = a:2 2695 let s:netrw_hup[host].passwd = a:3 2696 let g:netrw_uid = s:netrw_hup[host].uid 2697 let s:netrw_passwd = s:netrw_hup[host].passwd 2698 endif 2699 2700 endfunction 2701 2702 " Shared Browsing Support: {{{1 2703 2704 " s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2 2705 function s:ExplorePatHls(pattern) 2706 let repat= substitute(a:pattern,'^**/\{1,2}','','') 2707 let repat= escape(repat,'][.\') 2708 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>' 2709 return repat 2710 endfunction 2711 2712 " s:NetrwBookHistHandler: {{{2 2713 " 0: (user: <mb>) bookmark current directory 2714 " 1: (user: <gb>) change to the bookmarked path 2715 " 2: (user: <qb>) list bookmarks 2716 " 3: (browsing) records current directory history 2717 " 4: (user: <u>) go up (previous) directory, using history 2718 " 5: (user: <U>) go down (next) directory, using history 2719 " 6: (user: <mB>) delete bookmark 2720 function s:NetrwBookHistHandler(chg,curdir) 2721 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0 2722 return 2723 endif 2724 2725 let ykeep = @@ 2726 let curbufnr = bufnr("%") 2727 2728 if a:chg == 0 2729 " bookmark the current directory 2730 if exists("s:netrwmarkfilelist_{curbufnr}") 2731 call s:NetrwBookmark(0) 2732 echo "bookmarked marked files" 2733 else 2734 call s:MakeBookmark(a:curdir) 2735 echo "bookmarked the current directory" 2736 endif 2737 2738 try 2739 call s:NetrwBookHistSave() 2740 catch 2741 endtry 2742 2743 elseif a:chg == 1 2744 " change to bookmarked path 2745 if exists("g:netrw_bookmarklist") && !empty(g:netrw_bookmarklist) 2746 let len_bookmarklist = len(g:netrw_bookmarklist) 2747 let bookmark_num = v:count 2748 2749 " v:count value is set to zero if no count (prefix) is given to the `gb` map 2750 if bookmark_num == 0 2751 " list bookmarks and prompt for a bookmark number 2752 let goto_list = [" # | Goto Bookmark:"] 2753 let i = 0 2754 while i < len_bookmarklist 2755 call add(goto_list, printf("%3d| %s", i + 1, g:netrw_bookmarklist[i])) 2756 let i += 1 2757 endwhile 2758 let bookmark_num = inputlist(goto_list) 2759 endif 2760 2761 if bookmark_num > 0 2762 if bookmark_num <= len_bookmarklist 2763 exe "NetrwKeepj e " . fnameescape(g:netrw_bookmarklist[bookmark_num - 1]) 2764 else 2765 echomsg "Sorry, bookmark#" . bookmark_num . " doesn't exist!" 2766 endif 2767 endif 2768 " Exit silently if user cancels with `q` or empty after inputlist() 2769 else 2770 echo "Bookmark list is empty." 2771 endif 2772 2773 elseif a:chg == 2 2774 " redraw! 2775 let didwork= 0 2776 " list user's bookmarks 2777 if exists("g:netrw_bookmarklist") 2778 let cnt= 1 2779 for bmd in g:netrw_bookmarklist 2780 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1]) 2781 let didwork = 1 2782 let cnt = cnt + 1 2783 endfor 2784 endif 2785 2786 " list directory history 2787 " Note: history is saved only when PerformListing is done; 2788 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history. 2789 let cnt = g:netrw_dirhistcnt 2790 let first = 1 2791 let histcnt = 0 2792 if g:netrw_dirhistmax > 0 2793 while ( first || cnt != g:netrw_dirhistcnt ) 2794 if exists("g:netrw_dirhist_{cnt}") 2795 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt}) 2796 let didwork= 1 2797 endif 2798 let histcnt = histcnt + 1 2799 let first = 0 2800 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax 2801 if cnt < 0 2802 let cnt= cnt + g:netrw_dirhistmax 2803 endif 2804 endwhile 2805 else 2806 let g:netrw_dirhistcnt= 0 2807 endif 2808 if didwork 2809 call inputsave()|call input("Press <cr> to continue")|call inputrestore() 2810 endif 2811 2812 elseif a:chg == 3 2813 " saves most recently visited directories (when they differ) 2814 if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir 2815 if g:netrw_dirhistmax > 0 2816 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax 2817 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir 2818 endif 2819 endif 2820 2821 elseif a:chg == 4 2822 " u: change to the previous directory stored on the history list 2823 if g:netrw_dirhistmax > 0 2824 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax 2825 if g:netrw_dirhistcnt < 0 2826 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax 2827 endif 2828 else 2829 let g:netrw_dirhistcnt= 0 2830 endif 2831 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") 2832 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") 2833 setl ma noro 2834 sil! NetrwKeepj %d _ 2835 setl nomod 2836 endif 2837 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}) 2838 else 2839 if g:netrw_dirhistmax > 0 2840 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax 2841 else 2842 let g:netrw_dirhistcnt= 0 2843 endif 2844 echo "Sorry, no predecessor directory exists yet" 2845 endif 2846 2847 elseif a:chg == 5 2848 " U: change to the subsequent directory stored on the history list 2849 if g:netrw_dirhistmax > 0 2850 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax 2851 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") 2852 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") 2853 setl ma noro 2854 sil! NetrwKeepj %d _ 2855 setl nomod 2856 endif 2857 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}) 2858 else 2859 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax 2860 if g:netrw_dirhistcnt < 0 2861 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax 2862 endif 2863 echo "Sorry, no successor directory exists yet" 2864 endif 2865 else 2866 let g:netrw_dirhistcnt= 0 2867 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")" 2868 endif 2869 2870 elseif a:chg == 6 2871 if exists("s:netrwmarkfilelist_{curbufnr}") && !empty(s:netrwmarkfilelist_{curbufnr}) 2872 call s:NetrwBookmark(1) 2873 echo "removed marked files from bookmarks" 2874 elseif exists("g:netrw_bookmarklist") && !empty(g:netrw_bookmarklist) 2875 let len_bookmarklist = len(g:netrw_bookmarklist) 2876 let bookmark_num = v:count 2877 2878 " v:count value is set to zero if no count (prefix) is given to the `gb` map 2879 if bookmark_num == 0 2880 " list bookmarks and prompt for a bookmark number 2881 let goto_list = [" # | Delete Bookmark:"] 2882 let i = 0 2883 while i < len_bookmarklist 2884 call add(goto_list, printf("%3d| %s", i + 1, g:netrw_bookmarklist[i])) 2885 let i += 1 2886 endwhile 2887 let bookmark_num = inputlist(goto_list) 2888 endif 2889 2890 if bookmark_num > 0 2891 if bookmark_num <= len_bookmarklist 2892 let bookmark_path = g:netrw_bookmarklist[bookmark_num - 1] 2893 call s:MergeBookmarks() 2894 NetrwKeepj call remove(g:netrw_bookmarklist, bookmark_num - 1) 2895 echo "removed " . bookmark_path . " from g:netrw_bookmarklist." 2896 else 2897 echomsg "Sorry, bookmark#" . bookmark_num . " doesn't exist!" 2898 endif 2899 endif 2900 " Exit silently if user cancels with `q` or empty after inputlist() 2901 else 2902 echo "Bookmark list is empty." 2903 endif 2904 2905 try 2906 call s:NetrwBookHistSave() 2907 catch 2908 endtry 2909 endif 2910 call s:NetrwBookmarkMenu() 2911 call s:NetrwTgtMenu() 2912 let @@= ykeep 2913 endfunction 2914 2915 " s:NetrwBookHistRead: this function reads bookmarks and history {{{2 2916 " Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0. 2917 " Sister function: s:NetrwBookHistSave() 2918 function s:NetrwBookHistRead() 2919 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0 2920 return 2921 endif 2922 let ykeep= @@ 2923 2924 " read bookmarks 2925 if !exists("s:netrw_initbookhist") 2926 let home = s:NetrwHome() 2927 let savefile= home."/.netrwbook" 2928 if filereadable(s:NetrwFile(savefile)) 2929 exe "keepalt NetrwKeepj so ".savefile 2930 endif 2931 2932 " read history 2933 if g:netrw_dirhistmax > 0 2934 let savefile= home."/.netrwhist" 2935 if filereadable(s:NetrwFile(savefile)) 2936 exe "keepalt NetrwKeepj so ".savefile 2937 endif 2938 let s:netrw_initbookhist= 1 2939 au VimLeave * call s:NetrwBookHistSave() 2940 endif 2941 endif 2942 2943 let @@= ykeep 2944 endfunction 2945 2946 " s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2 2947 " Sister function: s:NetrwBookHistRead() 2948 " I used to do this via viminfo but that appears to 2949 " be unreliable for long-term storage 2950 " If g:netrw_dirhistmax is <= 0, no history or bookmarks 2951 " will be saved. 2952 " (s:NetrwBookHistHandler(3,...) used to record history) 2953 function s:NetrwBookHistSave() 2954 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0 2955 return 2956 endif 2957 2958 let savefile= s:NetrwHome()."/.netrwhist" 2959 1split 2960 2961 " setting up a new buffer which will become .netrwhist 2962 call s:NetrwEnew() 2963 if g:netrw_use_noswf 2964 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf 2965 else 2966 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 2967 endif 2968 setl nocin noai noci magic nospell nohid wig= noaw 2969 setl ma noro write 2970 if exists("+acd") | setl noacd | endif 2971 sil! NetrwKeepj keepalt %d _ 2972 2973 " rename enew'd file: .netrwhist -- no attempt to merge 2974 " record dirhistmax and current dirhistcnt 2975 " save history 2976 sil! keepalt file .netrwhist 2977 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax) 2978 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt) 2979 if g:netrw_dirhistmax > 0 2980 let lastline = line("$") 2981 let cnt = g:netrw_dirhistcnt 2982 let first = 1 2983 while ( first || cnt != g:netrw_dirhistcnt ) 2984 let lastline= lastline + 1 2985 if exists("g:netrw_dirhist_{cnt}") 2986 call setline(lastline,'let g:netrw_dirhist_'.cnt.'='.string(g:netrw_dirhist_{cnt})) 2987 endif 2988 let first = 0 2989 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax 2990 if cnt < 0 2991 let cnt= cnt + g:netrw_dirhistmax 2992 endif 2993 endwhile 2994 exe "sil! w! ".savefile 2995 endif 2996 2997 " save bookmarks 2998 sil NetrwKeepj %d _ 2999 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] 3000 " merge and write .netrwbook 3001 let savefile= s:NetrwHome()."/.netrwbook" 3002 3003 if filereadable(s:NetrwFile(savefile)) 3004 let booklist= deepcopy(g:netrw_bookmarklist) 3005 exe "sil NetrwKeepj keepalt so ".savefile 3006 for bdm in booklist 3007 if index(g:netrw_bookmarklist,bdm) == -1 3008 call add(g:netrw_bookmarklist,bdm) 3009 endif 3010 endfor 3011 call sort(g:netrw_bookmarklist) 3012 endif 3013 3014 " construct and save .netrwbook 3015 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist)) 3016 exe "sil! w! ".savefile 3017 endif 3018 3019 " cleanup -- remove buffer used to construct history 3020 let bgone= bufnr("%") 3021 q! 3022 exe "keepalt ".bgone."bwipe!" 3023 3024 endfunction 3025 3026 " s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2 3027 " list of the contents of a local or remote directory. It is assumed that the 3028 " g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted 3029 " with the requested remote hostname first. 3030 " Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse() 3031 function s:NetrwBrowse(islocal,dirname) 3032 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif 3033 3034 " save alternate-file's filename if w:netrw_rexlocal doesn't exist 3035 " This is useful when one edits a local file, then :e ., then :Rex 3036 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != "" 3037 let w:netrw_rexfile= bufname("#") 3038 endif 3039 3040 " s:NetrwBrowse : initialize history {{{3 3041 if !exists("s:netrw_initbookhist") 3042 NetrwKeepj call s:NetrwBookHistRead() 3043 endif 3044 3045 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3 3046 if a:dirname !~ '^\a\{3,}://' 3047 let dirname= simplify(a:dirname) 3048 else 3049 let dirname= a:dirname 3050 endif 3051 3052 " repoint t:netrw_lexbufnr if appropriate 3053 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr 3054 let repointlexbufnr= 1 3055 endif 3056 3057 " s:NetrwBrowse : sanity checks: {{{3 3058 if exists("s:netrw_skipbrowse") 3059 unlet s:netrw_skipbrowse 3060 return 3061 endif 3062 if !exists("*shellescape") 3063 call netrw#msg#Notify('ERROR', "netrw can't run -- your vim is missing shellescape()") 3064 return 3065 endif 3066 if !exists("*fnameescape") 3067 call netrw#msg#Notify('ERROR', "netrw can't run -- your vim is missing fnameescape()") 3068 return 3069 endif 3070 3071 " s:NetrwBrowse : save options: {{{3 3072 call s:NetrwOptionsSave("w:") 3073 3074 " s:NetrwBrowse : re-instate any marked files {{{3 3075 if has("syntax") && exists("g:syntax_on") && g:syntax_on 3076 if exists("s:netrwmarkfilelist_{bufnr('%')}") 3077 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" 3078 endif 3079 endif 3080 3081 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep 3082 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3 3083 if s:NetrwLcd(dirname) 3084 return 3085 endif 3086 3087 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"' 3088 " s:NetrwBrowse : remote regular file handler {{{3 3089 if bufname(dirname) != "" 3090 exe "NetrwKeepj b ".fnameescape(bufname(dirname)) 3091 else 3092 " attempt transfer of remote regular file 3093 3094 " remove any filetype indicator from end of dirname, except for the 3095 " "this is a directory" indicator (/). 3096 " There shouldn't be one of those here, anyway. 3097 let path= substitute(dirname,'[*=@|]\r\=$','','e') 3098 call s:RemotePathAnalysis(dirname) 3099 3100 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3 3101 call s:NetrwEnew(dirname) 3102 call s:NetrwOptionsSafe(a:islocal) 3103 setl ma noro 3104 let b:netrw_curdir = dirname 3105 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path 3106 call s:NetrwBufRename(url) 3107 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname) 3108 sil call netrw#NetRead(2,url) 3109 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error 3110 if s:path =~ '\.bz2$' 3111 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','','')) 3112 elseif s:path =~ '\.gz$' 3113 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','','')) 3114 elseif s:path =~ '\.xz$' 3115 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.xz$','','')) 3116 else 3117 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname) 3118 endif 3119 endif 3120 3121 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3 3122 call s:SetBufWinVars() 3123 call s:NetrwOptionsRestore("w:") 3124 setl ma nomod noro 3125 return 3126 endif 3127 3128 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3 3129 call s:UseBufWinVars() 3130 3131 " set up some variables {{{3 3132 let b:netrw_browser_active = 1 3133 let dirname = dirname 3134 let s:last_sort_by = g:netrw_sort_by 3135 3136 " set up menu {{{3 3137 NetrwKeepj call s:NetrwMenu(1) 3138 3139 " get/set-up buffer {{{3 3140 let svpos = winsaveview() 3141 3142 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the 3143 " previous buffer 3144 let prevbufnr = bufnr('%') 3145 let reusing= s:NetrwGetBuffer(a:islocal,dirname) 3146 if exists("s:rexposn_".prevbufnr) && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3147 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr} 3148 endif 3149 3150 " maintain markfile highlighting 3151 if has("syntax") && exists("g:syntax_on") && g:syntax_on 3152 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != "" 3153 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" 3154 else 3155 2match none 3156 endif 3157 endif 3158 if reusing && line("$") > 1 3159 call s:NetrwOptionsRestore("w:") 3160 setl noma nomod nowrap 3161 return 3162 endif 3163 3164 " set b:netrw_curdir to the new directory name {{{3 3165 let b:netrw_curdir= dirname 3166 if b:netrw_curdir =~ '[/\\]$' 3167 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e') 3168 endif 3169 if b:netrw_curdir =~ '\a:$' && has("win32") 3170 let b:netrw_curdir= b:netrw_curdir."/" 3171 endif 3172 if b:netrw_curdir == '' 3173 if has("amiga") 3174 " On the Amiga, the empty string connotes the current directory 3175 let b:netrw_curdir= getcwd() 3176 else 3177 " under unix, when the root directory is encountered, the result 3178 " from the preceding substitute is an empty string. 3179 let b:netrw_curdir= '/' 3180 endif 3181 endif 3182 if !a:islocal && b:netrw_curdir !~ '/$' 3183 let b:netrw_curdir= b:netrw_curdir.'/' 3184 endif 3185 3186 " ------------ 3187 " (local only) {{{3 3188 " ------------ 3189 if a:islocal 3190 " Set up ShellCmdPost handling. Append current buffer to browselist 3191 call s:LocalFastBrowser() 3192 3193 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3 3194 if !g:netrw_keepdir 3195 if !exists("&l:acd") || !&l:acd 3196 if s:NetrwLcd(b:netrw_curdir) 3197 return 3198 endif 3199 endif 3200 endif 3201 3202 " -------------------------------- 3203 " remote handling: {{{3 3204 " -------------------------------- 3205 else 3206 3207 " analyze dirname and g:netrw_list_cmd {{{3 3208 if dirname =~# "^NetrwTreeListing\>" 3209 let dirname= b:netrw_curdir 3210 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") 3211 let dirname= substitute(b:netrw_curdir,'\\','/','g') 3212 if dirname !~ '/$' 3213 let dirname= dirname.'/' 3214 endif 3215 let b:netrw_curdir = dirname 3216 else 3217 let dirname = substitute(dirname,'\\','/','g') 3218 endif 3219 3220 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' 3221 if dirname !~ dirpat 3222 call netrw#msg#Notify('ERROR', printf("netrw doesn't understand your dirname<%s>", dirname)) 3223 NetrwKeepj call s:NetrwOptionsRestore("w:") 3224 setl noma nomod nowrap 3225 return 3226 endif 3227 let b:netrw_curdir= dirname 3228 endif " (additional remote handling) 3229 3230 " ------------------------------- 3231 " Perform Directory Listing: {{{3 3232 " ------------------------------- 3233 NetrwKeepj call s:NetrwMaps(a:islocal) 3234 NetrwKeepj call s:NetrwCommands(a:islocal) 3235 NetrwKeepj call s:PerformListing(a:islocal) 3236 3237 " restore option(s) 3238 call s:NetrwOptionsRestore("w:") 3239 3240 " If there is a rexposn: restore position with rexposn 3241 " Otherwise : set rexposn 3242 if exists("s:rexposn_".bufnr("%")) 3243 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')}) 3244 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt 3245 NetrwKeepj exe w:netrw_bannercnt 3246 endif 3247 else 3248 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir) 3249 endif 3250 3251 " repoint t:netrw_lexbufnr if appropriate 3252 if exists("repointlexbufnr") 3253 let t:netrw_lexbufnr= bufnr("%") 3254 endif 3255 3256 " restore position 3257 if reusing 3258 call winrestview(svpos) 3259 endif 3260 3261 " The s:LocalBrowseRefresh() function is called by an autocmd 3262 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed). 3263 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time. 3264 return 3265 endfunction 3266 3267 " s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2 3268 " may not apply correctly; ie. netrw's idea of the current directory may 3269 " differ from vim's. This function insures that netrw's idea of the current 3270 " directory is used. 3271 " Returns a path to the file specified by a:fname 3272 function s:NetrwFile(fname) 3273 3274 " clean up any leading treedepthstring 3275 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3276 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','') 3277 else 3278 let fname= a:fname 3279 endif 3280 3281 if g:netrw_keepdir 3282 " vim's idea of the current directory possibly may differ from netrw's 3283 if !exists("b:netrw_curdir") 3284 let b:netrw_curdir= getcwd() 3285 endif 3286 3287 if !g:netrw_cygwin && has("win32") 3288 if isabsolutepath(fname) 3289 " windows, but full path given 3290 let ret= fname 3291 else 3292 " windows, relative path given 3293 let ret= netrw#fs#ComposePath(b:netrw_curdir,fname) 3294 endif 3295 3296 elseif fname =~ '^/' 3297 " not windows, full path given 3298 let ret= fname 3299 else 3300 " not windows, relative path given 3301 let ret= netrw#fs#ComposePath(b:netrw_curdir,fname) 3302 endif 3303 else 3304 " vim and netrw agree on the current directory 3305 let ret= fname 3306 endif 3307 3308 return ret 3309 endfunction 3310 3311 " s:NetrwFileInfo: supports qf (query for file information) {{{2 3312 function s:NetrwFileInfo(islocal,fname) 3313 let ykeep= @@ 3314 if a:islocal 3315 let lsopt= "-lsad" 3316 if g:netrw_sizestyle =~# 'H' 3317 let lsopt= "-lsadh" 3318 elseif g:netrw_sizestyle =~# 'h' 3319 let lsopt= "-lsadh --si" 3320 endif 3321 if (has("unix") || has("macunix")) && executable("/bin/ls") 3322 3323 if getline(".") == "../" 3324 echo system("/bin/ls ".lsopt." ".netrw#os#Escape("..")) 3325 3326 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring 3327 echo system("/bin/ls ".lsopt." ".netrw#os#Escape(b:netrw_curdir)) 3328 3329 elseif exists("b:netrw_curdir") 3330 echo system("/bin/ls ".lsopt." ".netrw#os#Escape(netrw#fs#ComposePath(b:netrw_curdir,a:fname))) 3331 3332 else 3333 echo system("/bin/ls ".lsopt." ".netrw#os#Escape(s:NetrwFile(a:fname))) 3334 endif 3335 else 3336 " use vim functions to return information about file below cursor 3337 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]' 3338 let fname= substitute(a:fname,".$","","") 3339 else 3340 let fname= a:fname 3341 endif 3342 let t = getftime(s:NetrwFile(fname)) 3343 let sz = getfsize(s:NetrwFile(fname)) 3344 if g:netrw_sizestyle =~# "[hH]" 3345 let sz= s:NetrwHumanReadable(sz) 3346 endif 3347 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname))) 3348 endif 3349 else 3350 echo "sorry, \"qf\" not supported yet for remote files" 3351 endif 3352 let @@= ykeep 3353 endfunction 3354 3355 " s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2 3356 " returns 0=cleared buffer 3357 " 1=re-used buffer (buffer not cleared) 3358 " Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix) 3359 function s:NetrwGetBuffer(islocal,dirname) 3360 let dirname= a:dirname 3361 3362 " re-use buffer if possible {{{3 3363 if !exists("s:netrwbuf") 3364 let s:netrwbuf= {} 3365 endif 3366 3367 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3368 let bufnum = -1 3369 3370 if !empty(s:netrwbuf) && has_key(s:netrwbuf,netrw#fs#AbsPath(dirname)) 3371 if has_key(s:netrwbuf,"NetrwTreeListing") 3372 let bufnum= s:netrwbuf["NetrwTreeListing"] 3373 else 3374 let bufnum= s:netrwbuf[netrw#fs#AbsPath(dirname)] 3375 endif 3376 if !bufexists(bufnum) 3377 call remove(s:netrwbuf,"NetrwTreeListing") 3378 let bufnum= -1 3379 endif 3380 elseif bufnr("NetrwTreeListing") != -1 3381 let bufnum= bufnr("NetrwTreeListing") 3382 else 3383 let bufnum= -1 3384 endif 3385 3386 elseif has_key(s:netrwbuf,netrw#fs#AbsPath(dirname)) 3387 let bufnum= s:netrwbuf[netrw#fs#AbsPath(dirname)] 3388 if !bufexists(bufnum) 3389 call remove(s:netrwbuf,netrw#fs#AbsPath(dirname)) 3390 let bufnum= -1 3391 endif 3392 3393 else 3394 let bufnum= -1 3395 endif 3396 3397 " highjack the current buffer 3398 " IF the buffer already has the desired name 3399 " AND it is empty 3400 let curbuf = bufname("%") 3401 if curbuf == '.' 3402 let curbuf = getcwd() 3403 endif 3404 if dirname == curbuf && line("$") == 1 && getline("%") == "" 3405 return 0 3406 else " DEBUG 3407 endif 3408 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems 3409 3410 " get enew buffer and name it -or- re-use buffer {{{3 3411 if bufnum < 0 " get enew buffer and name it 3412 call s:NetrwEnew(dirname) 3413 " name the buffer 3414 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3415 " Got enew buffer; transform into a NetrwTreeListing 3416 let w:netrw_treebufnr = bufnr("%") 3417 call s:NetrwBufRename("NetrwTreeListing") 3418 if g:netrw_use_noswf 3419 setl nobl bt=nofile noswf 3420 else 3421 setl nobl bt=nofile 3422 endif 3423 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr> 3424 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr> 3425 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr> 3426 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr> 3427 else 3428 call s:NetrwBufRename(dirname) 3429 " enter the new buffer into the s:netrwbuf dictionary 3430 let s:netrwbuf[netrw#fs#AbsPath(dirname)]= bufnr("%") 3431 endif 3432 3433 else " Re-use the buffer 3434 " ignore all events 3435 let eikeep= &ei 3436 setl ei=all 3437 3438 if &ft == "netrw" 3439 exe "sil! NetrwKeepj noswapfile b ".bufnum 3440 else 3441 call s:NetrwEditBuf(bufnum) 3442 endif 3443 if bufname("%") == '.' 3444 call s:NetrwBufRename(getcwd()) 3445 endif 3446 3447 " restore ei 3448 let &ei= eikeep 3449 3450 if line("$") <= 1 && getline(1) == "" 3451 " empty buffer 3452 NetrwKeepj call s:NetrwListSettings(a:islocal) 3453 return 0 3454 3455 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1) 3456 NetrwKeepj call s:NetrwListSettings(a:islocal) 3457 sil NetrwKeepj %d _ 3458 return 0 3459 3460 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3461 setl ma 3462 sil NetrwKeepj %d _ 3463 NetrwKeepj call s:NetrwListSettings(a:islocal) 3464 return 0 3465 3466 else 3467 return 1 3468 endif 3469 endif 3470 3471 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3 3472 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) 3473 " slow 0 D D Deleting a buffer implies it will not be re-used (slow) 3474 " med 1 D H 3475 " fast 2 H H 3476 let fname= expand("%") 3477 NetrwKeepj call s:NetrwListSettings(a:islocal) 3478 call s:NetrwBufRename(fname) 3479 3480 " delete all lines from buffer {{{3 3481 sil! keepalt NetrwKeepj %d _ 3482 3483 return 0 3484 endfunction 3485 3486 " s:NetrwGetWord: it gets the directory/file named under the cursor {{{2 3487 function s:NetrwGetWord() 3488 let keepsol= &l:sol 3489 setl nosol 3490 3491 call s:UseBufWinVars() 3492 3493 " insure that w:netrw_liststyle is set up 3494 if !exists("w:netrw_liststyle") 3495 if exists("g:netrw_liststyle") 3496 let w:netrw_liststyle= g:netrw_liststyle 3497 else 3498 let w:netrw_liststyle= s:THINLIST 3499 endif 3500 endif 3501 3502 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt 3503 " Active Banner support 3504 NetrwKeepj norm! 0 3505 let dirname= "./" 3506 let curline= getline('.') 3507 3508 if curline =~# '"\s*Sorted by\s' 3509 NetrwKeepj norm! "_s 3510 let s:netrw_skipbrowse= 1 3511 echo 'Pressing "s" also works' 3512 3513 elseif curline =~# '"\s*Sort sequence:' 3514 let s:netrw_skipbrowse= 1 3515 echo 'Press "S" to edit sorting sequence' 3516 3517 elseif curline =~# '"\s*Quick Help:' 3518 NetrwKeepj norm! ? 3519 let s:netrw_skipbrowse= 1 3520 3521 elseif curline =~# '"\s*\%(Hiding\|Showing\):' 3522 NetrwKeepj norm! a 3523 let s:netrw_skipbrowse= 1 3524 echo 'Pressing "a" also works' 3525 3526 elseif line("$") > w:netrw_bannercnt 3527 exe 'sil NetrwKeepj '.w:netrw_bannercnt 3528 endif 3529 3530 elseif w:netrw_liststyle == s:THINLIST 3531 NetrwKeepj norm! 0 3532 let dirname= substitute(getline('.'),'\t -->.*$','','') 3533 3534 elseif w:netrw_liststyle == s:LONGLIST 3535 NetrwKeepj norm! 0 3536 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e') 3537 3538 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3539 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e') 3540 let dirname= substitute(dirname,'\t -->.*$','','') 3541 3542 else 3543 let dirname= getline('.') 3544 3545 if !exists("b:netrw_cpf") 3546 let b:netrw_cpf= 0 3547 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' 3548 call histdel("/",-1) 3549 endif 3550 3551 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf 3552 if filestart == 0 3553 NetrwKeepj norm! 0ma 3554 else 3555 call cursor(line("."),filestart+1) 3556 NetrwKeepj norm! ma 3557 endif 3558 3559 let dict={} 3560 " save the unnamed register and register 0-9 and a 3561 let dict.a=[getreg('a'), getregtype('a')] 3562 for i in range(0, 9) 3563 let dict[i] = [getreg(i), getregtype(i)] 3564 endfor 3565 let dict.unnamed = [getreg(''), getregtype('')] 3566 3567 let eofname= filestart + b:netrw_cpf + 1 3568 if eofname <= col("$") 3569 call cursor(line("."),filestart+b:netrw_cpf+1) 3570 NetrwKeepj norm! "ay`a 3571 else 3572 NetrwKeepj norm! "ay$ 3573 endif 3574 3575 let dirname = @a 3576 call s:RestoreRegister(dict) 3577 3578 let dirname= substitute(dirname,'\s\+$','','e') 3579 endif 3580 3581 " symlinks are indicated by a trailing "@". Remove it before further processing. 3582 let dirname= substitute(dirname,"@$","","") 3583 3584 " executables are indicated by a trailing "*". Remove it before further processing. 3585 let dirname= substitute(dirname,"\*$","","") 3586 3587 let &l:sol= keepsol 3588 3589 return dirname 3590 endfunction 3591 3592 " s:NetrwListSettings: make standard settings for making a netrw listing {{{2 3593 " g:netrw_bufsettings will be used after the listing is produced. 3594 " Called by s:NetrwGetBuffer() 3595 function s:NetrwListSettings(islocal) 3596 let fname= bufname("%") 3597 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings) 3598 setl bt=nofile nobl ma nonu nowrap noro nornu 3599 call s:NetrwBufRename(fname) 3600 if g:netrw_use_noswf 3601 setl noswf 3602 endif 3603 exe "setl ts=".(g:netrw_maxfilenamelen+1) 3604 setl isk+=.,~,- 3605 if g:netrw_fastbrowse > a:islocal 3606 setl bh=hide 3607 else 3608 setl bh=delete 3609 endif 3610 endfunction 3611 3612 " s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2 3613 " islocal=0: remote browsing 3614 " =1: local browsing 3615 function s:NetrwListStyle(islocal) 3616 let ykeep = @@ 3617 let fname = s:NetrwGetWord() 3618 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif 3619 let svpos = winsaveview() 3620 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST 3621 3622 " repoint t:netrw_lexbufnr if appropriate 3623 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr 3624 let repointlexbufnr= 1 3625 endif 3626 3627 if w:netrw_liststyle == s:THINLIST 3628 " use one column listing 3629 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') 3630 3631 elseif w:netrw_liststyle == s:LONGLIST 3632 " use long list 3633 let g:netrw_list_cmd = g:netrw_list_cmd." -l" 3634 3635 elseif w:netrw_liststyle == s:WIDELIST 3636 " give wide list 3637 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') 3638 3639 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 3640 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') 3641 3642 else 3643 call netrw#msg#Notify('WARNING', printf('bad value for g:netrw_liststyle (=%s)', w:netrw_liststyle)) 3644 let g:netrw_liststyle = s:THINLIST 3645 let w:netrw_liststyle = g:netrw_liststyle 3646 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge') 3647 endif 3648 setl ma noro 3649 3650 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh 3651 sil! NetrwKeepj %d _ 3652 " following prevents tree listing buffer from being marked "modified" 3653 setl nomod 3654 3655 " refresh the listing 3656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 3657 NetrwKeepj call s:NetrwCursor(0) 3658 3659 " repoint t:netrw_lexbufnr if appropriate 3660 if exists("repointlexbufnr") 3661 let t:netrw_lexbufnr= bufnr("%") 3662 endif 3663 3664 " restore position; keep cursor on the filename 3665 NetrwKeepj call winrestview(svpos) 3666 let @@= ykeep 3667 3668 endfunction 3669 3670 " s:NetrwBannerCtrl: toggles the display of the banner {{{2 3671 function s:NetrwBannerCtrl(islocal) 3672 let ykeep= @@ 3673 " toggle the banner (enable/suppress) 3674 let g:netrw_banner= !g:netrw_banner 3675 3676 " refresh the listing 3677 let svpos= winsaveview() 3678 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 3679 3680 " keep cursor on the filename 3681 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt 3682 let fname= s:NetrwGetWord() 3683 sil NetrwKeepj $ 3684 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc') 3685 if result <= 0 && exists("w:netrw_bannercnt") 3686 exe "NetrwKeepj ".w:netrw_bannercnt 3687 endif 3688 endif 3689 let @@= ykeep 3690 endfunction 3691 3692 " s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2 3693 " 3694 " No bang: enters files/directories into Netrw's bookmark system 3695 " No argument and in netrw buffer: 3696 " if there are marked files: bookmark marked files 3697 " otherwise : bookmark file/directory under cursor 3698 " No argument and not in netrw buffer: bookmarks current open file 3699 " Has arguments: globs them individually and bookmarks them 3700 " 3701 " With bang: deletes files/directories from Netrw's bookmark system 3702 function s:NetrwBookmark(del,...) 3703 if a:0 == 0 3704 if &ft == "netrw" 3705 let curbufnr = bufnr("%") 3706 3707 if exists("s:netrwmarkfilelist_{curbufnr}") 3708 " for every filename in the marked list 3709 let svpos = winsaveview() 3710 let islocal= expand("%") !~ '^\a\{3,}://' 3711 for fname in s:netrwmarkfilelist_{curbufnr} 3712 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif 3713 endfor 3714 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd() 3715 call s:NetrwUnmarkList(curbufnr,curdir) 3716 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0)) 3717 NetrwKeepj call winrestview(svpos) 3718 else 3719 let fname= s:NetrwGetWord() 3720 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif 3721 endif 3722 3723 else 3724 " bookmark currently open file 3725 let fname= expand("%") 3726 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif 3727 endif 3728 3729 else 3730 " bookmark specified files 3731 " attempts to infer if working remote or local 3732 " by deciding if the current file begins with an url 3733 " Globbing cannot be done remotely. 3734 let islocal= expand("%") !~ '^\a\{3,}://' 3735 let i = 1 3736 while i <= a:0 3737 if islocal 3738 let mbfiles = glob(fnameescape(a:{i}), 0, 1, 1) 3739 else 3740 let mbfiles = [a:{i}] 3741 endif 3742 for mbfile in mbfiles 3743 if a:del 3744 call s:DeleteBookmark(mbfile) 3745 else 3746 call s:MakeBookmark(mbfile) 3747 endif 3748 endfor 3749 let i= i + 1 3750 endwhile 3751 endif 3752 3753 " update the menu 3754 call s:NetrwBookmarkMenu() 3755 endfunction 3756 3757 " s:NetrwBookmarkMenu: Uses menu priorities {{{2 3758 " .2.[cnt] for bookmarks, and 3759 " .3.[cnt] for history 3760 " (see s:NetrwMenu()) 3761 function s:NetrwBookmarkMenu() 3762 if !exists("s:netrw_menucnt") 3763 return 3764 endif 3765 3766 " the following test assures that gvim is running, has menus available, and has menus enabled. 3767 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu 3768 if exists("g:NetrwTopLvlMenu") 3769 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks' 3770 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete' 3771 endif 3772 if !exists("s:netrw_initbookhist") 3773 call s:NetrwBookHistRead() 3774 endif 3775 3776 " show bookmarked places 3777 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0 3778 let cnt= 1 3779 for bmd in g:netrw_bookmarklist 3780 let ebmd= escape(bmd,g:netrw_menu_escape) 3781 let fbmd= escape(fnameescape(bmd),'|') 3782 3783 " show bookmarks for goto menu 3784 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.ebmd.' :e '.fbmd."\<cr>" 3785 3786 " show bookmarks for deletion menu 3787 exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.ebmd.' '.cnt."mB" 3788 let cnt= cnt + 1 3789 endfor 3790 3791 endif 3792 3793 " show directory browsing history 3794 if g:netrw_dirhistmax > 0 3795 let cnt = g:netrw_dirhistcnt 3796 let first = 1 3797 let histcnt = 0 3798 while ( first || cnt != g:netrw_dirhistcnt ) 3799 let histcnt = histcnt + 1 3800 let priority = g:netrw_dirhistcnt + histcnt 3801 if exists("g:netrw_dirhist_{cnt}") 3802 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape) 3803 let ehistdir= escape(fnameescape(g:netrw_dirhist_{cnt}),'|') 3804 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.ehistdir."\<cr>" 3805 endif 3806 let first = 0 3807 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax 3808 if cnt < 0 3809 let cnt= cnt + g:netrw_dirhistmax 3810 endif 3811 endwhile 3812 endif 3813 3814 endif 3815 endfunction 3816 3817 " s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2 3818 " directory and a new directory name. Also, if the 3819 " "new directory name" is actually a file, 3820 " NetrwBrowseChgDir() edits the file. 3821 " cursor=0: newdir is relative to b:netrw_curdir 3822 " =1: newdir is relative to the path to the word under the cursor in 3823 " tree view 3824 function s:NetrwBrowseChgDir(islocal, newdir, cursor, ...) 3825 let ykeep= @@ 3826 if !exists("b:netrw_curdir") 3827 let @@= ykeep 3828 return 3829 endif 3830 3831 " NetrwBrowseChgDir; save options and initialize {{{3 3832 call s:SavePosn(s:netrw_posn) 3833 NetrwKeepj call s:NetrwOptionsSave("s:") 3834 NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 3835 3836 let newdir = a:newdir 3837 let dirname = b:netrw_curdir 3838 3839 if a:cursor && w:netrw_liststyle == s:TREELIST 3840 " dirname is the path to the word under the cursor 3841 let dirname = s:NetrwTreePath(w:netrw_treetop) 3842 " If the word under the cursor is a directory (except for ../), NetrwTreePath 3843 " returns the full path, including the word under the cursor, remove it 3844 if newdir != "../" 3845 let dirname = fnamemodify(dirname, ":h") 3846 endif 3847 endif 3848 3849 if has("win32") 3850 let dirname = substitute(dirname, '\\', '/', 'ge') 3851 endif 3852 3853 let dolockout = 0 3854 let dorestore = 1 3855 3856 " ignore <cr>s when done in the banner 3857 if g:netrw_banner 3858 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt 3859 if getline(".") =~# 'Quick Help' 3860 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp) 3861 setl ma noro nowrap 3862 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp]) 3863 setl noma nomod nowrap 3864 NetrwKeepj call s:NetrwOptionsRestore("s:") 3865 endif 3866 endif 3867 endif 3868 3869 " set up o/s-dependent directory recognition pattern 3870 let dirpat = has("amiga") || has('win32') ? '[\/:]$' : '/$' 3871 3872 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(netrw#fs#ComposePath(dirname, newdir)))) 3873 " ------------------------------ 3874 " NetrwBrowseChgDir: edit a file {{{3 3875 " ------------------------------ 3876 3877 " save position for benefit of Rexplore 3878 let s:rexposn_{bufnr("%")}= winsaveview() 3879 3880 let dirname = isabsolutepath(newdir) 3881 \ ? netrw#fs#AbsPath(newdir) 3882 \ : netrw#fs#ComposePath(dirname, newdir) 3883 3884 " this lets netrw#BrowseX avoid the edit 3885 if a:0 < 1 3886 NetrwKeepj call s:NetrwOptionsRestore("s:") 3887 let curdir= b:netrw_curdir 3888 if !exists("s:didsplit") 3889 if type(g:netrw_browse_split) == 3 3890 " open file in server 3891 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr] 3892 call s:NetrwServerEdit(a:islocal,dirname) 3893 return 3894 3895 elseif g:netrw_browse_split == 1 3896 " horizontally splitting the window first 3897 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize 3898 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s" 3899 if !&ea 3900 keepalt wincmd _ 3901 else 3902 exe "keepalt wincmd =" 3903 endif 3904 call s:SetRexDir(a:islocal,curdir) 3905 3906 elseif g:netrw_browse_split == 2 3907 " vertically splitting the window first 3908 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize 3909 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s" 3910 if !&ea 3911 keepalt wincmd | 3912 else 3913 exe "keepalt wincmd =" 3914 endif 3915 call s:SetRexDir(a:islocal,curdir) 3916 3917 elseif g:netrw_browse_split == 3 3918 " open file in new tab 3919 keepalt tabnew 3920 if !exists("b:netrw_curdir") 3921 let b:netrw_curdir= getcwd() 3922 endif 3923 call s:SetRexDir(a:islocal,curdir) 3924 3925 elseif g:netrw_browse_split == 4 3926 " act like "P" (ie. open previous window) 3927 if s:NetrwPrevWinOpen(2) == 3 3928 let @@= ykeep 3929 return 3930 endif 3931 call s:SetRexDir(a:islocal,curdir) 3932 3933 else 3934 " handling a file, didn't split, so remove menu 3935 call s:NetrwMenu(0) 3936 " optional change to window 3937 if g:netrw_chgwin >= 1 3938 if winnr("$")+1 == g:netrw_chgwin 3939 " if g:netrw_chgwin is set to one more than the last window, then 3940 " vertically split the last window to make that window available. 3941 let curwin= winnr() 3942 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w" 3943 vs 3944 exe "NetrwKeepj keepalt ".curwin."wincmd w" 3945 endif 3946 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w" 3947 endif 3948 call s:SetRexDir(a:islocal,curdir) 3949 endif 3950 3951 endif 3952 3953 " the point where netrw actually edits the (local) file 3954 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will 3955 " use keepalt to support :e # to return to a directory listing 3956 if !&mod 3957 " if e the new file would fail due to &mod, then don't change any of the flags 3958 let dolockout= 1 3959 endif 3960 3961 if a:islocal 3962 " some like c-^ to return to the last edited file 3963 " others like c-^ to return to the netrw buffer 3964 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file, 3965 " so emit error E37 instead. 3966 call s:NetrwEditFile("e","",dirname) 3967 call s:NetrwCursor(1) 3968 if &hidden || &bufhidden == "hide" 3969 " file came from vim's hidden storage. Don't "restore" options with it. 3970 let dorestore= 0 3971 endif 3972 endif 3973 3974 " handle g:Netrw_funcref -- call external-to-netrw functions 3975 " This code will handle g:Netrw_funcref as an individual function reference 3976 " or as a list of function references. It will ignore anything that's not 3977 " a function reference. See :help Funcref for information about function references. 3978 if exists("g:Netrw_funcref") 3979 if type(g:Netrw_funcref) == 2 3980 NetrwKeepj call g:Netrw_funcref() 3981 elseif type(g:Netrw_funcref) == 3 3982 for Fncref in g:Netrw_funcref 3983 if type(Fncref) == 2 3984 NetrwKeepj call Fncref() 3985 endif 3986 endfor 3987 endif 3988 endif 3989 endif 3990 3991 elseif newdir =~ '^/' 3992 " ---------------------------------------------------- 3993 " NetrwBrowseChgDir: just go to the new directory spec {{{3 3994 " ---------------------------------------------------- 3995 let dirname = newdir 3996 NetrwKeepj call s:SetRexDir(a:islocal,dirname) 3997 NetrwKeepj call s:NetrwOptionsRestore("s:") 3998 norm! m` 3999 4000 elseif newdir == './' 4001 " --------------------------------------------- 4002 " NetrwBrowseChgDir: refresh the directory list {{{3 4003 " --------------------------------------------- 4004 NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4005 norm! m` 4006 4007 elseif newdir == '../' 4008 " -------------------------------------- 4009 " NetrwBrowseChgDir: go up one directory {{{3 4010 " -------------------------------------- 4011 4012 " The following regexps expect '/' as path separator 4013 let dirname = substitute(netrw#fs#AbsPath(dirname), '\\', '/', 'ge') . '/' 4014 4015 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") 4016 " force a refresh 4017 setl noro ma 4018 NetrwKeepj %d _ 4019 endif 4020 4021 if has("amiga") 4022 " amiga 4023 if a:islocal 4024 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','') 4025 let dirname= substitute(dirname,'/$','','') 4026 else 4027 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','') 4028 endif 4029 4030 elseif !g:netrw_cygwin && has("win32") 4031 " windows 4032 if a:islocal 4033 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','') 4034 if dirname == "" 4035 let dirname= '/' 4036 endif 4037 else 4038 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','') 4039 endif 4040 if dirname =~ '^\a:$' 4041 let dirname= dirname.'/' 4042 endif 4043 4044 else 4045 " unix or cygwin 4046 if a:islocal 4047 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','') 4048 if dirname == "" 4049 let dirname= '/' 4050 endif 4051 else 4052 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','') 4053 endif 4054 endif 4055 NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4056 norm! m` 4057 4058 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") 4059 " -------------------------------------- 4060 " NetrwBrowseChgDir: Handle Tree Listing {{{3 4061 " -------------------------------------- 4062 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh) 4063 setl noro ma 4064 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")) 4065 NetrwKeepj %d _ 4066 endif 4067 let treedir = s:NetrwTreeDir(a:islocal) 4068 let s:treecurpos = winsaveview() 4069 let haskey = 0 4070 4071 " search treedict for tree dir as-is 4072 if has_key(w:netrw_treedict,treedir) 4073 let haskey= 1 4074 else 4075 endif 4076 4077 " search treedict for treedir with a [/@] appended 4078 if !haskey && treedir !~ '[/@]$' 4079 if has_key(w:netrw_treedict,treedir."/") 4080 let treedir= treedir."/" 4081 let haskey = 1 4082 else 4083 endif 4084 endif 4085 4086 " search treedict for treedir with any trailing / elided 4087 if !haskey && treedir =~ '/$' 4088 let treedir= substitute(treedir,'/$','','') 4089 if has_key(w:netrw_treedict,treedir) 4090 let haskey = 1 4091 else 4092 endif 4093 endif 4094 4095 if haskey 4096 " close tree listing for selected subdirectory 4097 call remove(w:netrw_treedict,treedir) 4098 let dirname= w:netrw_treetop 4099 else 4100 " go down one directory 4101 let dirname= substitute(treedir,'/*$','/','') 4102 endif 4103 NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4104 let s:treeforceredraw = 1 4105 4106 else 4107 " ---------------------------------------- 4108 " NetrwBrowseChgDir: Go down one directory {{{3 4109 " ---------------------------------------- 4110 let dirname = netrw#fs#ComposePath(dirname,newdir) 4111 NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4112 norm! m` 4113 endif 4114 4115 " -------------------------------------- 4116 " NetrwBrowseChgDir: Restore and Cleanup {{{3 4117 " -------------------------------------- 4118 if dorestore 4119 " dorestore is zero'd when a local file was hidden or bufhidden; 4120 " in such a case, we want to keep whatever settings it may have. 4121 NetrwKeepj call s:NetrwOptionsRestore("s:") 4122 endif 4123 if dolockout && dorestore 4124 if filewritable(dirname) 4125 setl ma noro nomod 4126 else 4127 setl ma ro nomod 4128 endif 4129 endif 4130 call s:RestorePosn(s:netrw_posn) 4131 let @@= ykeep 4132 4133 return dirname 4134 endfunction 4135 4136 " s:NetrwBrowseUpDir: implements the "-" mappings {{{2 4137 " for thin, long, and wide: cursor placed just after banner 4138 " for tree, keeps cursor on current filename 4139 function s:NetrwBrowseUpDir(islocal) 4140 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1 4141 " this test needed because occasionally this function seems to be incorrectly called 4142 " when multiple leftmouse clicks are taken when atop the one line help in the banner. 4143 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty 4144 " directories. 4145 return 4146 endif 4147 4148 norm! 0 4149 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") 4150 let curline= getline(".") 4151 let swwline= winline() - 1 4152 if exists("w:netrw_treetop") 4153 let b:netrw_curdir= w:netrw_treetop 4154 elseif exists("b:netrw_curdir") 4155 let w:netrw_treetop= b:netrw_curdir 4156 else 4157 let w:netrw_treetop= getcwd() 4158 let b:netrw_curdir = w:netrw_treetop 4159 endif 4160 let curfile = getline(".") 4161 let curpath = s:NetrwTreePath(w:netrw_treetop) 4162 if a:islocal 4163 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0)) 4164 else 4165 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0)) 4166 endif 4167 if w:netrw_treetop == '/' 4168 keepj call search('^\M'.curfile,"w") 4169 elseif curfile == '../' 4170 keepj call search('^\M'.curfile,"wb") 4171 else 4172 while 1 4173 keepj call search('^\M'.s:treedepthstring.curfile,"wb") 4174 let treepath= s:NetrwTreePath(w:netrw_treetop) 4175 if treepath == curpath 4176 break 4177 endif 4178 endwhile 4179 endif 4180 4181 else 4182 call s:SavePosn(s:netrw_posn) 4183 if exists("b:netrw_curdir") 4184 let curdir= b:netrw_curdir 4185 else 4186 let curdir= expand(getcwd()) 4187 endif 4188 if a:islocal 4189 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0)) 4190 else 4191 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0)) 4192 endif 4193 call s:RestorePosn(s:netrw_posn) 4194 let curdir= substitute(curdir,'^.*[\/]','','') 4195 let curdir= '\<'. escape(curdir, '~'). '/' 4196 call search(curdir,'wc') 4197 endif 4198 endfunction 4199 4200 " netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2 4201 " given filename; typically this means given their extension. 4202 function netrw#BrowseX(fname) 4203 " special core dump handler 4204 if a:fname =~ '/core\(\.\d\+\)\=$' && exists("g:Netrw_corehandler") 4205 if type(g:Netrw_corehandler) == v:t_func 4206 " g:Netrw_corehandler is a function reference (see :help Funcref) 4207 call g:Netrw_corehandler(s:NetrwFile(a:fname)) 4208 elseif type(g:Netrw_corehandler) == v:t_list 4209 " g:Netrw_corehandler is a List of function references (see :help Funcref) 4210 for Fncref in g:Netrw_corehandler 4211 if type(Fncref) == v:t_func 4212 call Fncref(a:fname) 4213 endif 4214 endfor 4215 endif 4216 return 4217 endif 4218 4219 let fname = a:fname 4220 " special ~ handler for local 4221 if fname =~ '^\~' && expand("$HOME") != "" 4222 let fname = substitute(fname, '^\~', expand("$HOME"), '') 4223 endif 4224 4225 if fname =~ '^[a-z]\+://' 4226 " open a remote file 4227 call netrw#os#Open(fname) 4228 else 4229 call netrw#os#Open(s:NetrwFile(fname)) 4230 endif 4231 endfunction 4232 4233 " s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2 4234 " Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer 4235 " to become an unlisted buffer, so in that case don't bwipe it. 4236 function s:NetrwBufRename(newname) 4237 let oldbufname= bufname(bufnr("%")) 4238 4239 if oldbufname != a:newname 4240 let b:junk= 1 4241 exe 'sil! keepj keepalt file '.fnameescape(a:newname) 4242 let oldbufnr= bufnr(oldbufname) 4243 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%") 4244 exe "bwipe! ".oldbufnr 4245 endif 4246 endif 4247 4248 endfunction 4249 4250 " netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2 4251 function netrw#CheckIfRemote(...) 4252 if a:0 > 0 4253 let curfile= a:1 4254 else 4255 let curfile= expand("%") 4256 endif 4257 if curfile =~ '^\a\{3,}://' 4258 return 1 4259 else 4260 return 0 4261 endif 4262 endfunction 4263 4264 " s:NetrwChgPerm: (implements "gp") change file permission {{{2 4265 function s:NetrwChgPerm(islocal,curdir) 4266 let ykeep = @@ 4267 call inputsave() 4268 let newperm= input("Enter new permission: ") 4269 call inputrestore() 4270 let fullpath = fnamemodify(netrw#fs#PathJoin(a:curdir, expand("<cfile>")), ':p') 4271 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',netrw#os#Escape(fullpath),'') 4272 let chgperm= substitute(chgperm,'\<PERM\>',netrw#os#Escape(newperm),'') 4273 call system(chgperm) 4274 if v:shell_error != 0 4275 NetrwKeepj call netrw#msg#Notify('WARNING', printf('changing permission on file<%s> seems to have failed', fullpath)) 4276 endif 4277 if a:islocal 4278 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4279 endif 4280 let @@= ykeep 4281 endfunction 4282 4283 " s:NetrwClearExplore: clear explore variables (if any) {{{2 4284 function s:NetrwClearExplore() 4285 2match none 4286 if exists("s:explore_match") |unlet s:explore_match |endif 4287 if exists("s:explore_indx") |unlet s:explore_indx |endif 4288 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif 4289 if exists("s:dirstarstar") |unlet s:dirstarstar |endif 4290 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif 4291 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif 4292 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif 4293 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif 4294 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif 4295 " redraw! 4296 endfunction 4297 4298 " s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2 4299 function s:NetrwEditBuf(bufnum) 4300 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw" 4301 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum) 4302 else 4303 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum) 4304 endif 4305 endfunction 4306 4307 " s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2 4308 " NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME> 4309 function s:NetrwEditFile(cmd,opt,fname) 4310 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw" 4311 exe "NetrwKeepj noswapfile keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname) 4312 else 4313 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0) 4314 call setbufvar(bufname('%'), '&bufhidden', 'hide') 4315 endif 4316 exe "NetrwKeepj noswapfile ".a:opt." ".a:cmd." ".fnameescape(a:fname) 4317 endif 4318 endfunction 4319 4320 " s:NetrwExploreListUniq: {{{2 4321 function s:NetrwExploreListUniq(explist) 4322 " this assumes that the list is already sorted 4323 let newexplist= [] 4324 for member in a:explist 4325 if !exists("uniqmember") || member != uniqmember 4326 let uniqmember = member 4327 let newexplist = newexplist + [ member ] 4328 endif 4329 endfor 4330 return newexplist 4331 endfunction 4332 4333 " s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2 4334 function s:NetrwForceChgDir(islocal,newdir) 4335 let ykeep= @@ 4336 if a:newdir !~ '/$' 4337 " ok, looks like force is needed to get directory-style treatment 4338 if a:newdir =~ '@$' 4339 let newdir= substitute(a:newdir,'@$','/','') 4340 elseif a:newdir =~ '[*=|\\]$' 4341 let newdir= substitute(a:newdir,'.$','/','') 4342 else 4343 let newdir= a:newdir.'/' 4344 endif 4345 else 4346 " should already be getting treatment as a directory 4347 let newdir= a:newdir 4348 endif 4349 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0) 4350 call s:NetrwBrowse(a:islocal,newdir) 4351 let @@= ykeep 4352 endfunction 4353 4354 " s:NetrwForceFile: (gf support) Force treatment as a file {{{2 4355 function s:NetrwForceFile(islocal,newfile) 4356 if a:newfile =~ '[/@*=|\\]$' 4357 let newfile= substitute(a:newfile,'.$','','') 4358 else 4359 let newfile= a:newfile 4360 endif 4361 if a:islocal 4362 call s:NetrwBrowseChgDir(a:islocal,newfile,0) 4363 else 4364 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0)) 4365 endif 4366 endfunction 4367 4368 " s:NetrwHide: this function is invoked by the "a" map for browsing {{{2 4369 " and switches the hiding mode. The actual hiding is done by 4370 " s:NetrwListHide(). 4371 " g:netrw_hide= 0: show all 4372 " 1: show not-hidden files 4373 " 2: show hidden files only 4374 function s:NetrwHide(islocal) 4375 let ykeep= @@ 4376 let svpos= winsaveview() 4377 4378 if exists("s:netrwmarkfilelist_{bufnr('%')}") 4379 4380 " hide the files in the markfile list 4381 for fname in s:netrwmarkfilelist_{bufnr("%")} 4382 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1 4383 " remove fname from hiding list 4384 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','') 4385 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g') 4386 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','') 4387 else 4388 " append fname to hiding list 4389 if exists("g:netrw_list_hide") && g:netrw_list_hide != "" 4390 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>' 4391 else 4392 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>' 4393 endif 4394 endif 4395 endfor 4396 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) 4397 let g:netrw_hide= 1 4398 4399 else 4400 4401 " switch between show-all/show-not-hidden/show-hidden 4402 let g:netrw_hide=(g:netrw_hide+1)%3 4403 exe "NetrwKeepj norm! 0" 4404 if g:netrw_hide && g:netrw_list_hide == "" 4405 call netrw#msg#Notify('WARNING', 'your hiding list is empty!') 4406 let @@= ykeep 4407 return 4408 endif 4409 endif 4410 4411 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4412 NetrwKeepj call winrestview(svpos) 4413 let @@= ykeep 4414 endfunction 4415 4416 " s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2 4417 function s:NetrwHideEdit(islocal) 4418 let ykeep= @@ 4419 " save current cursor position 4420 let svpos= winsaveview() 4421 4422 " get new hiding list from user 4423 call inputsave() 4424 let newhide= input("Edit Hiding List: ",g:netrw_list_hide) 4425 call inputrestore() 4426 let g:netrw_list_hide= newhide 4427 4428 " refresh the listing 4429 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0)) 4430 4431 " restore cursor position 4432 call winrestview(svpos) 4433 let @@= ykeep 4434 endfunction 4435 4436 " s:NetrwHidden: invoked by "gh" {{{2 4437 function s:NetrwHidden(islocal) 4438 let ykeep= @@ 4439 " save current position 4440 let svpos = winsaveview() 4441 4442 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+' 4443 " remove .file pattern from hiding list 4444 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','') 4445 elseif strdisplaywidth(g:netrw_list_hide) >= 1 4446 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+' 4447 else 4448 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+' 4449 endif 4450 if g:netrw_list_hide =~ '^,' 4451 let g:netrw_list_hide= strpart(g:netrw_list_hide,1) 4452 endif 4453 4454 " refresh screen and return to saved position 4455 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4456 NetrwKeepj call winrestview(svpos) 4457 let @@= ykeep 4458 endfunction 4459 4460 " s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2 4461 function s:NetrwHome() 4462 if exists('g:netrw_home') 4463 let home = expand(g:netrw_home) 4464 elseif has('nvim') 4465 let home = netrw#fs#PathJoin(stdpath('state'), 'netrw') 4466 elseif exists('$MYVIMDIR') 4467 let home = expand('$MYVIMDIR')->substitute('/$', '', '') 4468 else 4469 " Pick the first redable directory in 'runtimepath' 4470 for path in split(&rtp, ',') 4471 if isdirectory(s:NetrwFile(path)) && filewritable(s:NetrwFile(path)) 4472 let home = path 4473 break 4474 endif 4475 endfor 4476 4477 if empty(path) 4478 " just pick the first directory 4479 let home = substitute(&rtp, ',.*$', '', '') 4480 endif 4481 endif 4482 4483 " insure that the home directory exists 4484 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home)) 4485 if exists("g:netrw_mkdir") 4486 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home))) 4487 else 4488 call mkdir(home, 'p') 4489 endif 4490 endif 4491 4492 " Normalize directory if on Windows 4493 if has("win32") 4494 let home = substitute(home, '/', '\\', 'g') 4495 endif 4496 4497 let g:netrw_home = home 4498 return home 4499 endfunction 4500 4501 " s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2 4502 function s:NetrwLeftmouse(islocal) 4503 if exists("s:netrwdrag") 4504 return 4505 endif 4506 if &ft != "netrw" 4507 return 4508 endif 4509 4510 let ykeep= @@ 4511 " check if the status bar was clicked on instead of a file/directory name 4512 while getchar(0) != 0 4513 "clear the input stream 4514 endwhile 4515 call feedkeys("\<LeftMouse>") 4516 let c = getchar() 4517 let mouse_lnum = v:mouse_lnum 4518 let wlastline = line('w$') 4519 let lastline = line('$') 4520 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr() 4521 " appears to be a status bar leftmouse click 4522 let @@= ykeep 4523 return 4524 endif 4525 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode 4526 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar 4527 " without this test when its disabled. 4528 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop. 4529 if v:mouse_col > virtcol('.') 4530 let @@= ykeep 4531 return 4532 endif 4533 4534 if a:islocal 4535 if exists("b:netrw_curdir") 4536 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 4537 endif 4538 else 4539 if exists("b:netrw_curdir") 4540 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 4541 endif 4542 endif 4543 let @@= ykeep 4544 endfunction 4545 4546 " s:NetrwCLeftmouse: used to select a file/directory for a target {{{2 4547 function s:NetrwCLeftmouse(islocal) 4548 if &ft != "netrw" 4549 return 4550 endif 4551 call s:NetrwMarkFileTgt(a:islocal) 4552 endfunction 4553 4554 " s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2 4555 " a:islocal=0 : <c-r> not used, remote 4556 " a:islocal=1 : <c-r> not used, local 4557 " a:islocal=2 : <c-r> used, remote 4558 " a:islocal=3 : <c-r> used, local 4559 function s:NetrwServerEdit(islocal,fname) 4560 let islocal = a:islocal%2 " =0: remote =1: local 4561 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used 4562 4563 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$') 4564 " handle directories in the local window -- not in the remote vim server 4565 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw. 4566 let g:netrw_browse_split= 0 4567 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr()) 4568 let g:netrw_browse_split= s:netrw_browse_split_{winnr()} 4569 unlet s:netrw_browse_split_{winnr()} 4570 endif 4571 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0)) 4572 return 4573 endif 4574 4575 if has("clientserver") && executable("gvim") 4576 4577 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3 4578 let srvrname = g:netrw_browse_split[0] 4579 let tabnum = g:netrw_browse_split[1] 4580 let winnum = g:netrw_browse_split[2] 4581 4582 if serverlist() !~ '\<'.srvrname.'\>' 4583 if !ctrlr 4584 " user must have closed the server window and the user did not use <c-r>, but 4585 " used something like <cr>. 4586 if exists("g:netrw_browse_split") 4587 unlet g:netrw_browse_split 4588 endif 4589 let g:netrw_browse_split= 0 4590 if exists("s:netrw_browse_split_".winnr()) 4591 let g:netrw_browse_split= s:netrw_browse_split_{winnr()} 4592 endif 4593 call s:NetrwBrowseChgDir(islocal,a:fname,0) 4594 return 4595 4596 elseif has("win32") && executable("start") 4597 " start up remote netrw server under windows 4598 call system("start gvim --servername ".srvrname) 4599 4600 else 4601 " start up remote netrw server under linux 4602 call system("gvim --servername ".srvrname) 4603 endif 4604 endif 4605 4606 call remote_send(srvrname,":tabn ".tabnum."\<cr>") 4607 call remote_send(srvrname,":".winnum."wincmd w\<cr>") 4608 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>") 4609 else 4610 4611 if serverlist() !~ '\<'.g:netrw_servername.'\>' 4612 4613 if !ctrlr 4614 if exists("g:netrw_browse_split") 4615 unlet g:netrw_browse_split 4616 endif 4617 let g:netrw_browse_split= 0 4618 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0)) 4619 return 4620 4621 else 4622 if has("win32") && executable("start") 4623 " start up remote netrw server under windows 4624 call system("start gvim --servername ".g:netrw_servername) 4625 else 4626 " start up remote netrw server under linux 4627 call system("gvim --servername ".g:netrw_servername) 4628 endif 4629 endif 4630 endif 4631 4632 while 1 4633 try 4634 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>") 4635 break 4636 catch /^Vim\%((\a\+)\)\=:E241/ 4637 sleep 200m 4638 endtry 4639 endwhile 4640 4641 if exists("g:netrw_browse_split") 4642 if type(g:netrw_browse_split) != 3 4643 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split 4644 endif 4645 unlet g:netrw_browse_split 4646 endif 4647 let g:netrw_browse_split= [g:netrw_servername,1,1] 4648 endif 4649 4650 else 4651 call netrw#msg#Notify('ERROR', 'you need a gui-capable vim and client-server to use <ctrl-r>') 4652 endif 4653 4654 endfunction 4655 4656 " s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2 4657 function s:NetrwSLeftmouse(islocal) 4658 if &ft != "netrw" 4659 return 4660 endif 4661 4662 let s:ngw= s:NetrwGetWord() 4663 call s:NetrwMarkFile(a:islocal,s:ngw) 4664 4665 endfunction 4666 4667 " s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2 4668 " Used to mark multiple files. 4669 function s:NetrwSLeftdrag(islocal) 4670 if !exists("s:netrwdrag") 4671 let s:netrwdrag = winnr() 4672 if a:islocal 4673 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr> 4674 else 4675 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr> 4676 endif 4677 endif 4678 let ngw = s:NetrwGetWord() 4679 if !exists("s:ngw") || s:ngw != ngw 4680 call s:NetrwMarkFile(a:islocal,ngw) 4681 endif 4682 let s:ngw= ngw 4683 endfunction 4684 4685 " s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2 4686 function s:NetrwSLeftrelease(islocal) 4687 if exists("s:netrwdrag") 4688 nunmap <s-leftrelease> 4689 let ngw = s:NetrwGetWord() 4690 if !exists("s:ngw") || s:ngw != ngw 4691 call s:NetrwMarkFile(a:islocal,ngw) 4692 endif 4693 if exists("s:ngw") 4694 unlet s:ngw 4695 endif 4696 unlet s:netrwdrag 4697 endif 4698 endfunction 4699 4700 " s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2 4701 " comma-separated patterns given in g:netrw_list_hide 4702 function s:NetrwListHide() 4703 let ykeep= @@ 4704 4705 " find a character not in the "hide" string to use as a separator for :g and :v commands 4706 " How-it-works: take the hiding command, convert it into a range. 4707 " Duplicate characters don't matter. 4708 " Remove all such characters from the '/~@#...890' string. 4709 " Use the first character left as a separator character. 4710 let listhide= g:netrw_list_hide 4711 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) 4712 4713 while listhide != "" 4714 if listhide =~ ',' 4715 let hide = substitute(listhide,',.*$','','e') 4716 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e') 4717 else 4718 let hide = listhide 4719 let listhide = "" 4720 endif 4721 if g:netrw_sort_by =~ '^[ts]' 4722 if hide =~ '^\^' 4723 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','') 4724 elseif hide =~ '^\\(\^' 4725 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','') 4726 endif 4727 endif 4728 4729 " Prune the list by hiding any files which match 4730 if g:netrw_hide == 1 4731 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d' 4732 elseif g:netrw_hide == 2 4733 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @' 4734 endif 4735 endwhile 4736 4737 if g:netrw_hide == 2 4738 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d' 4739 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e' 4740 endif 4741 4742 " remove any blank lines that have somehow remained. 4743 " This seems to happen under Windows. 4744 exe 'sil! NetrwKeepj 1,$g@^\s*$@d' 4745 4746 let @@= ykeep 4747 endfunction 4748 4749 " s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2 4750 " implements the "d" mapping. 4751 function s:NetrwMakeDir(usrhost) 4752 4753 let ykeep= @@ 4754 " get name of new directory from user. A bare <CR> will skip. 4755 " if its currently a directory, also request will be skipped, but with 4756 " a message. 4757 call inputsave() 4758 let newdirname= input("Please give directory name: ") 4759 call inputrestore() 4760 4761 if newdirname == "" 4762 let @@= ykeep 4763 return 4764 endif 4765 4766 if a:usrhost == "" 4767 4768 " Local mkdir: 4769 " sanity checks 4770 let fullnewdir= b:netrw_curdir.'/'.newdirname 4771 if isdirectory(s:NetrwFile(fullnewdir)) 4772 call netrw#msg#Notify('WARNING', printf('<%s> is already a directory!', newdirname)) 4773 let @@= ykeep 4774 return 4775 endif 4776 if s:FileReadable(fullnewdir) 4777 call netrw#msg#Notify('WARNING', printf('<%s> is already a file!', newdirname)) 4778 let @@= ykeep 4779 return 4780 endif 4781 4782 " requested new local directory is neither a pre-existing file or 4783 " directory, so make it! 4784 if has("unix") 4785 call mkdir(fullnewdir,"p",xor(0777, system("umask"))) 4786 else 4787 call mkdir(fullnewdir,"p") 4788 endif 4789 4790 " on success refresh listing 4791 let svpos= winsaveview() 4792 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 4793 call winrestview(svpos) 4794 4795 elseif !exists("b:netrw_method") || b:netrw_method == 4 4796 " Remote mkdir: using ssh 4797 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd) 4798 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname 4799 call netrw#os#Execute("sil! !".mkdircmd." ".netrw#os#Escape(newdirname,1)) 4800 if v:shell_error == 0 4801 " refresh listing 4802 let svpos= winsaveview() 4803 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4804 NetrwKeepj call winrestview(svpos) 4805 else 4806 call netrw#msg#Notify('ERROR', printf('unable to make directory<%s>', newdirname)) 4807 endif 4808 4809 elseif b:netrw_method == 2 4810 " Remote mkdir: using ftp+.netrc 4811 let svpos= winsaveview() 4812 if exists("b:netrw_fname") 4813 let remotepath= b:netrw_fname 4814 else 4815 let remotepath= "" 4816 endif 4817 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"') 4818 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4819 NetrwKeepj call winrestview(svpos) 4820 4821 elseif b:netrw_method == 3 4822 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc) 4823 let svpos= winsaveview() 4824 if exists("b:netrw_fname") 4825 let remotepath= b:netrw_fname 4826 else 4827 let remotepath= "" 4828 endif 4829 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"') 4830 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4831 NetrwKeepj call winrestview(svpos) 4832 endif 4833 4834 let @@= ykeep 4835 endfunction 4836 4837 " s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2 4838 function s:TreeSqueezeDir(islocal) 4839 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") 4840 " its a tree-listing style 4841 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e') 4842 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1) 4843 let depth = strchars(substitute(curdepth,' ','','g')) 4844 let srch = -1 4845 if depth >= 2 4846 NetrwKeepj norm! 0 4847 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','') 4848 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline) 4849 elseif depth == 1 4850 NetrwKeepj norm! 0 4851 let treedepthchr= substitute(s:treedepthstring,' ','','') 4852 let srch = search('^[^'.treedepthchr.']','bW',stopline) 4853 endif 4854 if srch > 0 4855 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1)) 4856 exe srch 4857 endif 4858 endif 4859 endfunction 4860 4861 " s:NetrwMaps: {{{2 4862 function s:NetrwMaps(islocal) 4863 " remove B flag from 'cpo' so that \<CR>, \<Bar>, etc. inside 4864 " interpolated path names play back as literal text rather than 4865 " the actual key — without this, a crafted directory name can 4866 " inject keystrokes into the cmdline the mapping is typing 4867 let _cpo = &cpo 4868 set cpo-=B 4869 4870 " mouse <Plug> maps: {{{3 4871 if g:netrw_mousemaps && g:netrw_retmap 4872 if !hasmapto("<Plug>NetrwReturn") 4873 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$' 4874 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn 4875 elseif maparg("<c-leftmouse>","n") == "" 4876 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn 4877 endif 4878 endif 4879 nno <silent> <Plug>NetrwReturn :Rexplore<cr> 4880 endif 4881 4882 " generate default <Plug> maps {{{3 4883 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif 4884 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif 4885 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif 4886 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif 4887 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif 4888 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif 4889 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif 4890 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif 4891 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif 4892 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif 4893 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif 4894 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif 4895 4896 if a:islocal 4897 " local normal-mode maps {{{3 4898 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr> 4899 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr> 4900 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr> 4901 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr> 4902 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr> 4903 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr> 4904 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr> 4905 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr> 4906 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr> 4907 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr> 4908 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr> 4909 " --------------------------------------------------------------------- 4910 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr> 4911 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr> 4912 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr> 4913 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr> 4914 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr> 4915 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr> 4916 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr> 4917 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr> 4918 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr> 4919 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> 4920 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> 4921 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr> 4922 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr> 4923 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr> 4924 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr> 4925 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr> 4926 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr> 4927 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr> 4928 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr> 4929 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr> 4930 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr> 4931 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr> 4932 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr> 4933 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr> 4934 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr> 4935 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr> 4936 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr> 4937 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr> 4938 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr> 4939 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr> 4940 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr> 4941 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr> 4942 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> 4943 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr> 4944 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr> 4945 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr> 4946 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr> 4947 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr> 4948 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr> 4949 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr> 4950 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr> 4951 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr> 4952 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr> 4953 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr> 4954 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,0))"<cr> 4955 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr> 4956 4957 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./',0))<cr> 4958 if !hasmapto('<Plug>NetrwHideEdit') 4959 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit 4960 endif 4961 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr> 4962 if !hasmapto('<Plug>NetrwRefresh') 4963 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh 4964 endif 4965 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './',0))<cr> 4966 if s:didstarstar || !mapcheck("<s-down>","n") 4967 nnoremap <buffer> <silent> <s-down> :Nexplore<cr> 4968 endif 4969 if s:didstarstar || !mapcheck("<s-up>","n") 4970 nnoremap <buffer> <silent> <s-up> :Pexplore<cr> 4971 endif 4972 if !hasmapto('<Plug>NetrwTreeSqueeze') 4973 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze 4974 endif 4975 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr> 4976 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape) 4977 if g:netrw_mousemaps == 1 4978 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse 4979 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse 4980 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse 4981 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse 4982 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag 4983 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse 4984 imap <buffer> <leftmouse> <Plug>ILeftmouse 4985 imap <buffer> <middlemouse> <Plug>IMiddlemouse 4986 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr> 4987 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr> 4988 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr> 4989 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr> 4990 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr> 4991 nmap <buffer> <silent> <Plug>Netrw2Leftmouse - 4992 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 4993 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 4994 endif 4995 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 4996 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 4997 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>' 4998 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>' 4999 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 5000 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>' 5001 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>' 5002 nnoremap <buffer> <F1> :he netrw-quickhelp<cr> 5003 5004 " support user-specified maps 5005 call netrw#UserMaps(1) 5006 5007 else 5008 " remote normal-mode maps {{{3 5009 call s:RemotePathAnalysis(b:netrw_curdir) 5010 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr> 5011 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr> 5012 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr> 5013 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr> 5014 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr> 5015 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr> 5016 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr> 5017 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr> 5018 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1))<cr> 5019 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr> 5020 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr> 5021 " --------------------------------------------------------------------- 5022 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr> 5023 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr> 5024 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr> 5025 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr> 5026 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr> 5027 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr> 5028 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr> 5029 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr> 5030 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr> 5031 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr> 5032 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr> 5033 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr> 5034 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr> 5035 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr> 5036 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr> 5037 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr> 5038 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr> 5039 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr> 5040 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr> 5041 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr> 5042 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr> 5043 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr> 5044 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr> 5045 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr> 5046 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr> 5047 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr> 5048 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr> 5049 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr> 5050 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr> 5051 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr> 5052 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr> 5053 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr> 5054 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr> 5055 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr> 5056 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr> 5057 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr> 5058 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr> 5059 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr> 5060 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr> 5061 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr> 5062 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr> 5063 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr> 5064 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr> 5065 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr> 5066 if !hasmapto('<Plug>NetrwHideEdit') 5067 nmap <buffer> <c-h> <Plug>NetrwHideEdit 5068 endif 5069 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr> 5070 if !hasmapto('<Plug>NetrwRefresh') 5071 nmap <buffer> <c-l> <Plug>NetrwRefresh 5072 endif 5073 if !hasmapto('<Plug>NetrwTreeSqueeze') 5074 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze 5075 endif 5076 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr> 5077 5078 let mapsafepath = escape(s:path, s:netrw_map_escape) 5079 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape) 5080 5081 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr> 5082 if g:netrw_mousemaps == 1 5083 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse 5084 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr> 5085 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse 5086 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr> 5087 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse 5088 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr> 5089 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag 5090 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr> 5091 nmap <middlemouse> <Plug>NetrwMiddlemouse 5092 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr> 5093 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse 5094 nmap <buffer> <silent> <Plug>Netrw2Leftmouse - 5095 imap <buffer> <leftmouse> <Plug>ILeftmouse 5096 imap <buffer> <middlemouse> <Plug>IMiddlemouse 5097 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse 5098 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5099 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5100 endif 5101 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5102 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>' 5103 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5104 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5105 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5106 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5107 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>' 5108 nnoremap <buffer> <F1> :he netrw-quickhelp<cr> 5109 5110 " support user-specified maps 5111 call netrw#UserMaps(0) 5112 endif " }}}3 5113 let &cpo = _cpo 5114 endfunction 5115 5116 " s:NetrwCommands: set up commands {{{2 5117 " If -buffer, the command is only available from within netrw buffers 5118 " Otherwise, the command is available from any window, so long as netrw 5119 " has been used at least once in the session. 5120 function s:NetrwCommands(islocal) 5121 5122 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>) 5123 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>) 5124 com! Rexplore if exists("w:netrw_rexlocal")|call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".")|else|call netrw#msg#Notify('WARNING', "win#".winnr()." not a former netrw window")|endif 5125 if a:islocal 5126 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>) 5127 else 5128 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>) 5129 endif 5130 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>) 5131 5132 endfunction 5133 5134 " s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2 5135 " glob()ing only works with local files 5136 function s:NetrwMarkFiles(islocal,...) 5137 let curdir = s:NetrwGetCurdir(a:islocal) 5138 let i = 1 5139 while i <= a:0 5140 if a:islocal 5141 let mffiles= glob(a:{i}, 0, 1, 1) 5142 else 5143 let mffiles= [a:{i}] 5144 endif 5145 for mffile in mffiles 5146 call s:NetrwMarkFile(a:islocal,mffile) 5147 endfor 5148 let i= i + 1 5149 endwhile 5150 endfunction 5151 5152 " s:NetrwMarkTarget: implements :MT (mark target) {{{2 5153 function s:NetrwMarkTarget(...) 5154 if a:0 == 0 || (a:0 == 1 && a:1 == "") 5155 let curdir = s:NetrwGetCurdir(1) 5156 let tgt = b:netrw_curdir 5157 else 5158 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1) 5159 let tgt = a:1 5160 endif 5161 let s:netrwmftgt = tgt 5162 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://' 5163 let curislocal = b:netrw_curdir !~ '^\a\{3,}://' 5164 let svpos = winsaveview() 5165 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0)) 5166 call winrestview(svpos) 5167 endfunction 5168 5169 " s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2 5170 " mark and unmark files. If a markfile list exists, 5171 " then the rename and delete functions will use it instead 5172 " of whatever may happen to be under the cursor at that 5173 " moment. When the mouse and gui are available, 5174 " shift-leftmouse may also be used to mark files. 5175 " 5176 " Creates two lists 5177 " s:netrwmarkfilelist -- holds complete paths to all marked files 5178 " s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr()) 5179 " 5180 " Creates a marked file match string 5181 " s:netrwmarkfilemtch_# -- used with 2match to display marked files 5182 " 5183 " Creates a buffer version of islocal 5184 " b:netrw_islocal 5185 function s:NetrwMarkFile(islocal,fname) 5186 5187 " sanity check 5188 if empty(a:fname) 5189 return 5190 endif 5191 let curdir = s:NetrwGetCurdir(a:islocal) 5192 5193 let ykeep = @@ 5194 let curbufnr = bufnr("%") 5195 let leader = '\%(^\|\s\)\zs' 5196 let word_boundary_trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)' 5197 let fallback_trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)' 5198 let trailer = (a:fname =~ '\a$') ? word_boundary_trailer : fallback_trailer 5199 5200 if exists("s:netrwmarkfilelist_".curbufnr) 5201 " markfile list pre-exists 5202 let b:netrw_islocal = a:islocal 5203 5204 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1 5205 " append filename to buffer's markfilelist 5206 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','','')) 5207 let s:netrwmarkfilemtch_{curbufnr} = s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer 5208 5209 else 5210 " remove filename from buffer's markfilelist 5211 call filter(s:netrwmarkfilelist_{curbufnr}, {_, v -> v !=# a:fname}) 5212 if s:netrwmarkfilelist_{curbufnr} == [] 5213 " local markfilelist is empty; remove it entirely 5214 call s:NetrwUnmarkList(curbufnr,curdir) 5215 else 5216 " rebuild match list to display markings correctly 5217 let s:netrwmarkfilemtch_{curbufnr} = "" 5218 let first = 1 5219 for fname in s:netrwmarkfilelist_{curbufnr} 5220 let curtrailer = (fname =~ '\a$') ? word_boundary_trailer : fallback_trailer 5221 5222 let match_str = leader.escape(fname, g:netrw_markfileesc).curtrailer 5223 if first 5224 let s:netrwmarkfilemtch_{curbufnr} = match_str 5225 else 5226 let s:netrwmarkfilemtch_{curbufnr} = s:netrwmarkfilemtch_{curbufnr}.'\|'.match_str 5227 endif 5228 let first = 0 5229 endfor 5230 endif 5231 endif 5232 5233 else 5234 " initialize new markfilelist 5235 let s:netrwmarkfilelist_{curbufnr} = [] 5236 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','','')) 5237 5238 " build initial markfile matching pattern 5239 let s:netrwmarkfilemtch_{curbufnr} = leader.escape(a:fname,g:netrw_markfileesc).trailer 5240 endif 5241 5242 " handle global markfilelist 5243 if exists("s:netrwmarkfilelist") 5244 let dname = netrw#fs#ComposePath(b:netrw_curdir,a:fname) 5245 if index(s:netrwmarkfilelist,dname) == -1 5246 " append new filename to global markfilelist 5247 call add(s:netrwmarkfilelist,netrw#fs#ComposePath(b:netrw_curdir,a:fname)) 5248 else 5249 " remove new filename from global markfilelist 5250 call filter(s:netrwmarkfilelist, {_, v -> v !=# dname}) 5251 if s:netrwmarkfilelist == [] 5252 unlet s:netrwmarkfilelist 5253 endif 5254 endif 5255 else 5256 " initialize new global-directory markfilelist 5257 let s:netrwmarkfilelist = [] 5258 call add(s:netrwmarkfilelist,netrw#fs#ComposePath(b:netrw_curdir,a:fname)) 5259 endif 5260 5261 " set up 2match'ing to netrwmarkfilemtch_# list 5262 if has("syntax") && exists("g:syntax_on") && g:syntax_on 5263 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != "" 5264 if exists("g:did_drchip_netrwlist_syntax") 5265 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/" 5266 endif 5267 else 5268 2match none 5269 endif 5270 endif 5271 let @@= ykeep 5272 endfunction 5273 5274 " s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2 5275 " mA: move the argument list to marked file list (tomflist=1) 5276 " Uses the global marked file list 5277 function s:NetrwMarkFileArgList(islocal,tomflist) 5278 let svpos = winsaveview() 5279 let curdir = s:NetrwGetCurdir(a:islocal) 5280 let curbufnr = bufnr("%") 5281 5282 if a:tomflist 5283 " mA: move argument list to marked file list 5284 while argc() 5285 let fname= argv(0) 5286 exe "argdel ".fnameescape(fname) 5287 call s:NetrwMarkFile(a:islocal,fname) 5288 endwhile 5289 5290 else 5291 " ma: move marked file list to argument list 5292 if exists("s:netrwmarkfilelist") 5293 5294 " for every filename in the marked list 5295 for fname in s:netrwmarkfilelist 5296 exe "argadd ".fnameescape(fname) 5297 endfor " for every file in the marked list 5298 5299 " unmark list and refresh 5300 call s:NetrwUnmarkList(curbufnr,curdir) 5301 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5302 NetrwKeepj call winrestview(svpos) 5303 endif 5304 endif 5305 endfunction 5306 5307 " s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2 5308 " compress/decompress files using the programs 5309 " in g:netrw_compress and g:netrw_uncompress, 5310 " using g:netrw_compress_suffix to know which to 5311 " do. By default: 5312 " g:netrw_compress = "gzip" 5313 " g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"} 5314 function s:NetrwMarkFileCompress(islocal) 5315 let svpos = winsaveview() 5316 let curdir = s:NetrwGetCurdir(a:islocal) 5317 let curbufnr = bufnr("%") 5318 5319 " sanity check 5320 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5321 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5322 return 5323 endif 5324 5325 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress") 5326 5327 " for every filename in the marked list 5328 for fname in s:netrwmarkfilelist_{curbufnr} 5329 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','') 5330 if exists("g:netrw_decompress['".sfx."']") 5331 " fname has a suffix indicating that its compressed; apply associated decompression routine 5332 let exe= g:netrw_decompress[sfx] 5333 let exe= netrw#fs#WinPath(exe) 5334 if a:islocal 5335 if g:netrw_keepdir 5336 let fname= netrw#os#Escape(netrw#fs#ComposePath(curdir,fname)) 5337 else 5338 let fname= netrw#os#Escape(fname) 5339 endif 5340 call system(exe." ".fname) 5341 if v:shell_error 5342 call netrw#msg#Notify('WARNING', printf('unable to apply<%s> to file<%s>', exe, fname)) 5343 endif 5344 else 5345 let fname= netrw#os#Escape(b:netrw_curdir.fname,1) 5346 NetrwKeepj call s:RemoteSystem(exe." ".fname) 5347 endif 5348 5349 endif 5350 unlet sfx 5351 5352 if exists("exe") 5353 unlet exe 5354 elseif a:islocal 5355 " fname not a compressed file, so compress it 5356 call system(netrw#fs#WinPath(g:netrw_compress)." ".netrw#os#Escape(netrw#fs#ComposePath(b:netrw_curdir,fname))) 5357 if v:shell_error 5358 call netrw#msg#Notify('WARNING', printf('consider setting g:netrw_compress<%s> to something that works', g:netrw_compress)) 5359 endif 5360 else 5361 " fname not a compressed file, so compress it 5362 NetrwKeepj call s:RemoteSystem(netrw#fs#WinPath(g:netrw_compress)." ".netrw#os#Escape(fname)) 5363 endif 5364 endfor " for every file in the marked list 5365 5366 call s:NetrwUnmarkList(curbufnr,curdir) 5367 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5368 NetrwKeepj call winrestview(svpos) 5369 endif 5370 endfunction 5371 5372 " s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2 5373 " If no marked files, then set up directory as the 5374 " target. Currently does not support copying entire 5375 " directories. Uses the local-buffer marked file list. 5376 " Returns 1=success (used by NetrwMarkFileMove()) 5377 " 0=failure 5378 function s:NetrwMarkFileCopy(islocal,...) 5379 5380 let curdir = s:NetrwGetCurdir(a:islocal) 5381 let curbufnr = bufnr("%") 5382 if !exists("b:netrw_curdir") 5383 let b:netrw_curdir= curdir 5384 endif 5385 5386 " sanity check 5387 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5388 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5389 return 0 5390 endif 5391 5392 if !exists("s:netrwmftgt") 5393 call netrw#msg#Notify('ERROR', 'your marked file target is empty! (:help netrw-mt)') 5394 return 0 5395 endif 5396 5397 if a:islocal && s:netrwmftgt_islocal 5398 " Copy marked files, local directory to local directory 5399 if !executable(g:netrw_localcopycmd) 5400 call netrw#msg#Notify('ERROR', printf('g:netrw_localcopycmd<%s> not executable on your system, aborting', g:netrw_localcopycmd)) 5401 return 5402 endif 5403 5404 " copy marked files while within the same directory (ie. allow renaming) 5405 if simplify(s:netrwmftgt."/") ==# simplify(b:netrw_curdir."/") 5406 " copy multiple marked files inside the same directory 5407 for oldname in s:netrwmarkfilelist_{curbufnr} 5408 call inputsave() 5409 let newname= input(printf("Copy %s to: ", oldname), oldname, 'file') 5410 call inputrestore() 5411 5412 if empty(newname) 5413 return 0 5414 endif 5415 5416 let tgt = netrw#fs#ComposePath(s:netrwmftgt, newname) 5417 let oldname = netrw#fs#ComposePath(b:netrw_curdir, oldname) 5418 if tgt ==# oldname 5419 continue 5420 endif 5421 5422 let ret = filecopy(oldname, tgt) 5423 if ret == v:false 5424 call netrw#msg#Notify('ERROR', $'copy failed, unable to filecopy() <{oldname}> to <{tgt}>') 5425 break 5426 endif 5427 endfor 5428 call s:NetrwUnmarkList(curbufnr,curdir) 5429 NetrwKeepj call s:NetrwRefreshDir(a:islocal, b:netrw_curdir) 5430 return ret 5431 else 5432 let args = [] 5433 for arg in s:netrwmarkfilelist_{curbufnr} 5434 call add(args, netrw#fs#ComposePath(b:netrw_curdir, arg)) 5435 endfor 5436 let tgt = s:netrwmftgt 5437 endif 5438 5439 let copycmd = g:netrw_localcopycmd 5440 let copycmdopt = g:netrw_localcopycmdopt 5441 5442 " on Windows, no builtin command supports copying multiple files at once 5443 " (powershell's Copy-Item cmdlet does but requires , as file separator) 5444 if len(s:netrwmarkfilelist_{curbufnr}) > 1 && has("win32") && !g:netrw_cygwin 5445 " copy multiple marked files 5446 for file in args 5447 let dest = netrw#fs#ComposePath(tgt, fnamemodify(file, ':t')) 5448 let ret = filecopy(file, dest) 5449 if ret == v:false 5450 call netrw#msg#Notify('ERROR', $'copy failed, unable to filecopy() <{file}> to <{dest}>') 5451 break 5452 endif 5453 endfor 5454 call s:NetrwUnmarkList(curbufnr,curdir) 5455 NetrwKeepj call s:NetrwRefreshDir(a:islocal, b:netrw_curdir) 5456 return ret 5457 endif 5458 5459 if len(args) == 1 && isdirectory(s:NetrwFile(args[0])) 5460 let copycmd = g:netrw_localcopydircmd 5461 let copycmdopt = g:netrw_localcopydircmdopt 5462 if has('win32') && g:netrw_localcopydircmd == "xcopy" 5463 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's 5464 " contents to a target. One must append the source directory name to the target to get xcopy to 5465 " do the right thing. 5466 let tgt = netrw#fs#ComposePath(tgt, fnamemodify(simplify(netrw#fs#PathJoin(args[0],".")),":t")) 5467 endif 5468 endif 5469 5470 " prepare arguments for shell call 5471 let args = join(map(args,'netrw#os#Escape(v:val)')) 5472 let tgt = netrw#os#Escape(tgt) 5473 5474 " enforce noshellslash for system calls 5475 if exists('+shellslash') && &shellslash 5476 for var in ['copycmd', 'args', 'tgt'] 5477 let {var} = substitute({var}, '/', '\', 'g') 5478 endfor 5479 endif 5480 5481 " shell call 5482 let shell_cmd = printf("%s %s %s %s", copycmd, copycmdopt, args, tgt) 5483 call system(shell_cmd) 5484 if v:shell_error != 0 5485 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir 5486 call netrw#msg#Notify('ERROR', printf("copy failed; perhaps due to vim's current directory<%s> not matching netrw's (%s) (see :help netrw-cd)", getcwd(), b:netrw_curdir)) 5487 else 5488 call netrw#msg#Notify('ERROR', printf("tried using g:netrw_localcopycmd<%s>; it doesn't work!", g:netrw_localcopycmd)) 5489 endif 5490 return 0 5491 endif 5492 5493 elseif a:islocal && !s:netrwmftgt_islocal 5494 " Copy marked files, local directory to remote directory 5495 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{curbufnr},s:netrwmftgt) 5496 5497 elseif !a:islocal && s:netrwmftgt_islocal 5498 " Copy marked files, remote directory to local directory 5499 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{curbufnr},s:netrwmftgt) 5500 5501 elseif !a:islocal && !s:netrwmftgt_islocal 5502 " Copy marked files, remote directory to remote directory 5503 let curdir = getcwd() 5504 let tmpdir = s:GetTempfile("") 5505 if tmpdir !~ '/' 5506 let tmpdir= curdir."/".tmpdir 5507 endif 5508 call mkdir(tmpdir) 5509 if isdirectory(s:NetrwFile(tmpdir)) 5510 if s:NetrwLcd(tmpdir) 5511 return 5512 endif 5513 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{curbufnr},tmpdir) 5514 let localfiles= map(deepcopy(s:netrwmarkfilelist_{curbufnr}),'substitute(v:val,"^.*/","","")') 5515 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt) 5516 if getcwd() == tmpdir 5517 for fname in s:netrwmarkfilelist_{curbufnr} 5518 call netrw#fs#Remove(fname) 5519 endfor 5520 if s:NetrwLcd(curdir) 5521 return 5522 endif 5523 if delete(tmpdir,"d") 5524 call netrw#msg#Notify('ERROR', printf('unable to delete directory <%s>!', tmpdir)) 5525 endif 5526 else 5527 if s:NetrwLcd(curdir) 5528 return 5529 endif 5530 endif 5531 endif 5532 endif 5533 5534 " ------- 5535 " cleanup 5536 " ------- 5537 " remove markings from local buffer 5538 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer 5539 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium) 5540 if g:netrw_fastbrowse <= 1 5541 NetrwKeepj call s:LocalBrowseRefresh() 5542 else 5543 " refresh local and targets for fast browsing 5544 " remove markings from local buffer 5545 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir) 5546 5547 " refresh buffers 5548 if s:netrwmftgt_islocal 5549 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) 5550 endif 5551 if a:islocal && s:netrwmftgt != curdir 5552 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir) 5553 endif 5554 endif 5555 5556 return 1 5557 endfunction 5558 5559 " s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2 5560 " invoke vim's diff mode on the marked files. 5561 " Either two or three files can be so handled. 5562 " Uses the global marked file list. 5563 function s:NetrwMarkFileDiff(islocal) 5564 let curbufnr= bufnr("%") 5565 5566 " sanity check 5567 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5568 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5569 return 5570 endif 5571 let curdir= s:NetrwGetCurdir(a:islocal) 5572 5573 if exists("s:netrwmarkfilelist_{".curbufnr."}") 5574 let cnt = 0 5575 for fname in s:netrwmarkfilelist 5576 let cnt= cnt + 1 5577 if cnt == 1 5578 exe "NetrwKeepj e ".fnameescape(fname) 5579 diffthis 5580 elseif cnt == 2 || cnt == 3 5581 below vsplit 5582 exe "NetrwKeepj e ".fnameescape(fname) 5583 diffthis 5584 else 5585 break 5586 endif 5587 endfor 5588 call s:NetrwUnmarkList(curbufnr,curdir) 5589 endif 5590 5591 endfunction 5592 5593 " s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2 5594 " Uses global markfilelist 5595 function s:NetrwMarkFileEdit(islocal) 5596 5597 let curdir = s:NetrwGetCurdir(a:islocal) 5598 let curbufnr = bufnr("%") 5599 5600 " sanity check 5601 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5602 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5603 return 5604 endif 5605 5606 if exists("s:netrwmarkfilelist_{curbufnr}") 5607 call s:SetRexDir(a:islocal,curdir) 5608 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)")) 5609 " unmark markedfile list 5610 " call s:NetrwUnmarkList(curbufnr,curdir) 5611 call s:NetrwUnmarkAll() 5612 exe "sil args ".flist 5613 endif 5614 echo "(use :bn, :bp to navigate files; :Rex to return)" 5615 5616 endfunction 5617 5618 " s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2 5619 function s:NetrwMarkFileQFEL(islocal,qfel) 5620 call s:NetrwUnmarkAll() 5621 let curbufnr= bufnr("%") 5622 5623 if !empty(a:qfel) 5624 for entry in a:qfel 5625 let bufnmbr= entry["bufnr"] 5626 if !exists("s:netrwmarkfilelist_{curbufnr}") 5627 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr)) 5628 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1 5629 " s:NetrwMarkFile will remove duplicate entries from the marked file list. 5630 " So, this test lets two or more hits on the same pattern to be ignored. 5631 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr)) 5632 else 5633 endif 5634 endfor 5635 echo "(use me to edit marked files)" 5636 else 5637 call netrw#msg#Notify('WARNING', "can't convert quickfix error list; its empty!") 5638 endif 5639 5640 endfunction 5641 5642 " s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2 5643 " mx enbloc=0: Uses the local marked-file list, applies command to each file individually 5644 " mX enbloc=1: Uses the global marked-file list, applies command to entire list 5645 function s:NetrwMarkFileExe(islocal,enbloc) 5646 let svpos = winsaveview() 5647 let curdir = s:NetrwGetCurdir(a:islocal) 5648 let curbufnr = bufnr("%") 5649 5650 if a:enbloc == 0 5651 " individually apply command to files, one at a time 5652 " sanity check 5653 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5654 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5655 return 5656 endif 5657 5658 if exists("s:netrwmarkfilelist_{curbufnr}") 5659 " get the command 5660 call inputsave() 5661 let cmd= input("Enter command: ","","file") 5662 call inputrestore() 5663 if cmd == "" 5664 return 5665 endif 5666 5667 " apply command to marked files, individually. Substitute: filename -> % 5668 " If no %, then append a space and the filename to the command 5669 for fname in s:netrwmarkfilelist_{curbufnr} 5670 if a:islocal 5671 if g:netrw_keepdir 5672 let fname= netrw#os#Escape(netrw#fs#WinPath(netrw#fs#ComposePath(curdir,fname))) 5673 else 5674 let fname= netrw#os#Escape(netrw#fs#WinPath(fname)) 5675 endif 5676 else 5677 let fname= netrw#os#Escape(netrw#fs#WinPath(b:netrw_curdir.fname)) 5678 endif 5679 if cmd =~ '%' 5680 let xcmd= substitute(cmd,'%',fname,'g') 5681 else 5682 let xcmd= cmd.' '.fname 5683 endif 5684 if a:islocal 5685 let ret= system(xcmd) 5686 else 5687 let ret= s:RemoteSystem(xcmd) 5688 endif 5689 if v:shell_error < 0 5690 call netrw#msg#Notify('ERROR', printf('command<%s> failed, aborting', xcmd)) 5691 break 5692 else 5693 if ret !=# '' 5694 echo "\n" 5695 " skip trailing new line 5696 echo ret[0:-2] 5697 else 5698 echo ret 5699 endif 5700 endif 5701 endfor 5702 5703 " unmark marked file list 5704 call s:NetrwUnmarkList(curbufnr,curdir) 5705 5706 " refresh the listing 5707 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5708 NetrwKeepj call winrestview(svpos) 5709 else 5710 call netrw#msg#Notify('ERROR', 'no files marked!') 5711 endif 5712 5713 else " apply command to global list of files, en bloc 5714 5715 call inputsave() 5716 let cmd= input("Enter command: ","","file") 5717 call inputrestore() 5718 if cmd == "" 5719 return 5720 endif 5721 if cmd =~ '%' 5722 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'netrw#os#Escape(v:val)'),' '),'g') 5723 else 5724 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'netrw#os#Escape(v:val)'),' ') 5725 endif 5726 if a:islocal 5727 call system(cmd) 5728 if v:shell_error < 0 5729 call netrw#msg#Notify('ERROR', printf('command<%s> failed, aborting',xcmd)) 5730 endif 5731 else 5732 let ret= s:RemoteSystem(cmd) 5733 endif 5734 call s:NetrwUnmarkAll() 5735 5736 " refresh the listing 5737 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5738 NetrwKeepj call winrestview(svpos) 5739 5740 endif 5741 endfunction 5742 5743 " s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix 5744 " as the marked file(s) (toggles suffix presence) 5745 " Uses the local marked file list. 5746 function s:NetrwMarkHideSfx(islocal) 5747 let svpos = winsaveview() 5748 let curbufnr = bufnr("%") 5749 5750 " s:netrwmarkfilelist_{curbufnr}: the List of marked files 5751 if exists("s:netrwmarkfilelist_{curbufnr}") 5752 5753 for fname in s:netrwmarkfilelist_{curbufnr} 5754 " construct suffix pattern 5755 if fname =~ '\.' 5756 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','') 5757 else 5758 let sfxpat= '^\%(\%(\.\)\@!.\)*$' 5759 endif 5760 " determine if its in the hiding list or not 5761 let inhidelist= 0 5762 if g:netrw_list_hide != "" 5763 let itemnum = 0 5764 let hidelist= split(g:netrw_list_hide,',') 5765 for hidepat in hidelist 5766 if sfxpat == hidepat 5767 let inhidelist= 1 5768 break 5769 endif 5770 let itemnum= itemnum + 1 5771 endfor 5772 endif 5773 if inhidelist 5774 " remove sfxpat from list 5775 call remove(hidelist,itemnum) 5776 let g:netrw_list_hide= join(hidelist,",") 5777 elseif g:netrw_list_hide != "" 5778 " append sfxpat to non-empty list 5779 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat 5780 else 5781 " set hiding list to sfxpat 5782 let g:netrw_list_hide= sfxpat 5783 endif 5784 endfor 5785 5786 " refresh the listing 5787 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5788 NetrwKeepj call winrestview(svpos) 5789 else 5790 call netrw#msg#Notify('ERROR', 'no files marked!') 5791 endif 5792 endfunction 5793 5794 " s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2 5795 " Uses the local marked-file list. 5796 function s:NetrwMarkFileVimCmd(islocal) 5797 let svpos = winsaveview() 5798 let curdir = s:NetrwGetCurdir(a:islocal) 5799 let curbufnr = bufnr("%") 5800 5801 " sanity check 5802 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5803 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5804 return 5805 endif 5806 5807 if exists("s:netrwmarkfilelist_{curbufnr}") 5808 " get the command 5809 call inputsave() 5810 let cmd= input("Enter vim command: ","","file") 5811 call inputrestore() 5812 if cmd == "" 5813 return 5814 endif 5815 5816 " apply command to marked files. Substitute: filename -> % 5817 " If no %, then append a space and the filename to the command 5818 for fname in s:netrwmarkfilelist_{curbufnr} 5819 if a:islocal 5820 1split 5821 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname) 5822 exe cmd 5823 exe "sil! keepalt wq!" 5824 else 5825 echo "sorry, \"mv\" not supported yet for remote files" 5826 endif 5827 endfor 5828 5829 " unmark marked file list 5830 call s:NetrwUnmarkList(curbufnr,curdir) 5831 5832 " refresh the listing 5833 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5834 NetrwKeepj call winrestview(svpos) 5835 else 5836 call netrw#msg#Notify('ERROR', 'no files marked!') 5837 endif 5838 endfunction 5839 5840 " s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2 5841 " Uses the global markfilelist 5842 function s:NetrwMarkFileGrep(islocal) 5843 let svpos = winsaveview() 5844 let curbufnr = bufnr("%") 5845 let curdir = s:NetrwGetCurdir(a:islocal) 5846 5847 if exists("s:netrwmarkfilelist") 5848 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)")) 5849 call s:NetrwUnmarkAll() 5850 else 5851 let netrwmarkfilelist= "*" 5852 endif 5853 5854 " ask user for pattern 5855 call inputsave() 5856 let pat= input("Enter pattern: ","") 5857 call inputrestore() 5858 let patbang = "" 5859 if pat =~ '^!' 5860 let patbang = "!" 5861 let pat = strpart(pat,2) 5862 endif 5863 if pat =~ '^\i' 5864 let pat = escape(pat,'/') 5865 let pat = '/'.pat.'/' 5866 else 5867 let nonisi = pat[0] 5868 endif 5869 5870 " use vimgrep for both local and remote 5871 try 5872 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist 5873 catch /^Vim\%((\a\+)\)\=:E480/ 5874 call netrw#msg#Notify('WARNING', printf('no match with pattern<%s>', pat)) 5875 return 5876 endtry 5877 echo "(use :cn, :cp to navigate, :Rex to return)" 5878 5879 2match none 5880 NetrwKeepj call winrestview(svpos) 5881 5882 if exists("nonisi") 5883 " original, user-supplied pattern did not begin with a character from isident 5884 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$' 5885 call s:NetrwMarkFileQFEL(a:islocal,getqflist()) 5886 endif 5887 endif 5888 5889 endfunction 5890 5891 " s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2 5892 " uses the global marked file list 5893 " s:netrwmfloc= 0: target directory is remote 5894 " = 1: target directory is local 5895 function s:NetrwMarkFileMove(islocal) 5896 let curdir = s:NetrwGetCurdir(a:islocal) 5897 let curbufnr = bufnr("%") 5898 5899 " sanity check 5900 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 5901 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 5902 return 5903 endif 5904 5905 if !exists("s:netrwmftgt") 5906 call netrw#msg#Notify('ERROR', 'your marked file target is empty! (:help netrw-mt)') 5907 return 0 5908 endif 5909 5910 if a:islocal && s:netrwmftgt_islocal 5911 " move: local -> local 5912 if !executable(g:netrw_localmovecmd) 5913 call netrw#msg#Notify('ERROR', printf('g:netrw_localmovecmd<%s> not executable on your system, aborting', g:netrw_localmovecmd)) 5914 return 5915 endif 5916 5917 let tgt = netrw#os#Escape(s:netrwmftgt) 5918 if has("win32") && !g:netrw_cygwin && g:netrw_localmovecmd =~ '\s' && g:netrw_localmovecmdopt == "" 5919 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','') 5920 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','') 5921 else 5922 let movecmd = g:netrw_localmovecmd 5923 let movecmdargs = g:netrw_localmovecmdopt 5924 endif 5925 5926 " build args list 5927 let args = [] 5928 for fname in s:netrwmarkfilelist_{curbufnr} 5929 if g:netrw_keepdir 5930 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1 5931 let fname= netrw#fs#ComposePath(b:netrw_curdir, fname) 5932 endif 5933 call add(args, netrw#os#Escape(fname)) 5934 endfor 5935 5936 " enforce noshellslash for system calls 5937 if exists('+shellslash') && &shellslash 5938 let tgt = substitute(tgt, '/', '\', 'g') 5939 call map(args, "substitute(v:val, '/', '\\', 'g')") 5940 endif 5941 5942 for fname in args 5943 let shell_cmd = printf("%s %s %s %s", movecmd, movecmdargs, fname, tgt) 5944 let ret= system(shell_cmd) 5945 if v:shell_error != 0 5946 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir 5947 call netrw#msg#Notify('ERROR', printf("move failed; perhaps due to vim's current directory<%s> not matching netrw's (%s) (see :help netrw-cd)", getcwd(), b:netrw_curdir)) 5948 else 5949 call netrw#msg#Notify('ERROR', printf("tried using g:netrw_localmovecmd<%s>; it doesn't work!", g:netrw_localmovecmd)) 5950 endif 5951 break 5952 endif 5953 endfor 5954 5955 elseif a:islocal && !s:netrwmftgt_islocal 5956 " move: local -> remote 5957 let mflist= s:netrwmarkfilelist_{curbufnr} 5958 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5959 for fname in mflist 5960 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') 5961 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1) 5962 endfor 5963 unlet mflist 5964 5965 elseif !a:islocal && s:netrwmftgt_islocal 5966 " move: remote -> local 5967 let mflist= s:netrwmarkfilelist_{curbufnr} 5968 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5969 for fname in mflist 5970 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') 5971 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1) 5972 endfor 5973 unlet mflist 5974 5975 elseif !a:islocal && !s:netrwmftgt_islocal 5976 " move: remote -> remote 5977 let mflist= s:netrwmarkfilelist_{curbufnr} 5978 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5979 for fname in mflist 5980 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','') 5981 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1) 5982 endfor 5983 unlet mflist 5984 endif 5985 5986 " ------- 5987 " cleanup 5988 " ------- 5989 5990 " remove markings from local buffer 5991 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer 5992 5993 " refresh buffers 5994 if !s:netrwmftgt_islocal 5995 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) 5996 endif 5997 if a:islocal 5998 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir) 5999 endif 6000 if g:netrw_fastbrowse <= 1 6001 NetrwKeepj call s:LocalBrowseRefresh() 6002 endif 6003 6004 endfunction 6005 6006 " s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2 6007 " files when given a regexp (for which a prompt is 6008 " issued) (matches to name of files). 6009 function s:NetrwMarkFileRegexp(islocal) 6010 6011 " get the regular expression 6012 call inputsave() 6013 let regexp= input("Enter regexp: ","","file") 6014 call inputrestore() 6015 6016 if a:islocal 6017 let curdir= s:NetrwGetCurdir(a:islocal) 6018 " get the matching list of files using local glob() 6019 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape) 6020 let filelist= glob(netrw#fs#ComposePath(dirname,regexp),0,1,1) 6021 6022 " mark the list of files 6023 for fname in filelist 6024 if fname =~ '^'.fnameescape(curdir) 6025 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','','')) 6026 else 6027 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','','')) 6028 endif 6029 endfor 6030 6031 else 6032 6033 " convert displayed listing into a filelist 6034 let eikeep = &ei 6035 let areg = @a 6036 sil NetrwKeepj %y a 6037 setl ei=all ma 6038 1split 6039 NetrwKeepj call s:NetrwEnew() 6040 NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 6041 sil NetrwKeepj norm! "ap 6042 NetrwKeepj 2 6043 let bannercnt= search('^" =====','W') 6044 exe "sil NetrwKeepj 1,".bannercnt."d" 6045 setl bt=nofile 6046 if g:netrw_liststyle == s:LONGLIST 6047 sil NetrwKeepj %s/\s\{2,}\S.*$//e 6048 call histdel("/",-1) 6049 elseif g:netrw_liststyle == s:WIDELIST 6050 sil NetrwKeepj %s/\s\{2,}/\r/ge 6051 call histdel("/",-1) 6052 elseif g:netrw_liststyle == s:TREELIST 6053 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e' 6054 sil! NetrwKeepj g/^ .*$/d 6055 call histdel("/",-1) 6056 call histdel("/",-1) 6057 endif 6058 " convert regexp into the more usual glob-style format 6059 let regexp= substitute(regexp,'\*','.*','g') 6060 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d" 6061 call histdel("/",-1) 6062 let filelist= getline(1,line("$")) 6063 q! 6064 for filename in filelist 6065 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','','')) 6066 endfor 6067 unlet filelist 6068 let @a = areg 6069 let &ei = eikeep 6070 endif 6071 echo " (use me to edit marked files)" 6072 6073 endfunction 6074 6075 " s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2 6076 " Uses the local marked file list. 6077 function s:NetrwMarkFileSource(islocal) 6078 let curbufnr= bufnr("%") 6079 6080 " sanity check 6081 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 6082 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 6083 return 6084 endif 6085 let curdir= s:NetrwGetCurdir(a:islocal) 6086 6087 if exists("s:netrwmarkfilelist_{curbufnr}") 6088 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")} 6089 call s:NetrwUnmarkList(curbufnr,curdir) 6090 for fname in netrwmarkfilelist 6091 if a:islocal 6092 if g:netrw_keepdir 6093 let fname= netrw#fs#ComposePath(curdir,fname) 6094 endif 6095 else 6096 let fname= curdir.fname 6097 endif 6098 " the autocmds will handle sourcing both local and remote files 6099 exe "so ".fnameescape(fname) 6100 endfor 6101 2match none 6102 endif 6103 endfunction 6104 6105 " s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2 6106 " Uses the global markfilelist 6107 function s:NetrwMarkFileTag(islocal) 6108 let svpos = winsaveview() 6109 let curdir = s:NetrwGetCurdir(a:islocal) 6110 let curbufnr = bufnr("%") 6111 6112 " sanity check 6113 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr}) 6114 call netrw#msg#Notify('ERROR', 'there are no marked files in this window (:help netrw-mf)') 6115 return 6116 endif 6117 6118 if exists("s:netrwmarkfilelist") 6119 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "netrw#os#Escape(v:val,".!a:islocal.")")) 6120 call s:NetrwUnmarkAll() 6121 6122 if a:islocal 6123 6124 call system(g:netrw_ctags." ".netrwmarkfilelist) 6125 if v:shell_error 6126 call netrw#msg#Notify('ERROR', printf('g:netrw_ctags<%s> is not executable!', g:netrw_ctags)) 6127 endif 6128 6129 else 6130 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist) 6131 call netrw#Obtain(a:islocal,"tags") 6132 let curdir= b:netrw_curdir 6133 1split 6134 NetrwKeepj e tags 6135 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','') 6136 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e' 6137 call histdel("/",-1) 6138 wq! 6139 endif 6140 2match none 6141 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6142 call winrestview(svpos) 6143 endif 6144 endfunction 6145 6146 " s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2 6147 " Sets up two variables, 6148 " s:netrwmftgt : holds the target directory 6149 " s:netrwmftgt_islocal : 0=target directory is remote 6150 " 1=target directory is local 6151 function s:NetrwMarkFileTgt(islocal) 6152 let svpos = winsaveview() 6153 let curdir = s:NetrwGetCurdir(a:islocal) 6154 let hadtgt = exists("s:netrwmftgt") 6155 if !exists("w:netrw_bannercnt") 6156 let w:netrw_bannercnt= b:netrw_bannercnt 6157 endif 6158 6159 " set up target 6160 if line(".") < w:netrw_bannercnt 6161 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target 6162 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir 6163 unlet s:netrwmftgt s:netrwmftgt_islocal 6164 if g:netrw_fastbrowse <= 1 6165 call s:LocalBrowseRefresh() 6166 endif 6167 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6168 call winrestview(svpos) 6169 return 6170 else 6171 let s:netrwmftgt= b:netrw_curdir 6172 endif 6173 6174 else 6175 " get word under cursor. 6176 " * If directory, use it for the target. 6177 " * If file, use b:netrw_curdir for the target 6178 let curword= s:NetrwGetWord() 6179 let tgtdir = netrw#fs#ComposePath(curdir,curword) 6180 if a:islocal && isdirectory(s:NetrwFile(tgtdir)) 6181 let s:netrwmftgt = tgtdir 6182 elseif !a:islocal && tgtdir =~ '/$' 6183 let s:netrwmftgt = tgtdir 6184 else 6185 let s:netrwmftgt = curdir 6186 endif 6187 endif 6188 if a:islocal 6189 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi) 6190 let s:netrwmftgt= simplify(s:netrwmftgt) 6191 endif 6192 if g:netrw_cygwin 6193 let s:netrwmftgt= substitute(system("cygpath ".netrw#os#Escape(s:netrwmftgt)),'\n$','','') 6194 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','') 6195 endif 6196 let s:netrwmftgt_islocal= a:islocal 6197 6198 " need to do refresh so that the banner will be updated 6199 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing 6200 if g:netrw_fastbrowse <= 1 6201 call s:LocalBrowseRefresh() 6202 endif 6203 " call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6204 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 6205 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0)) 6206 else 6207 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6208 endif 6209 call winrestview(svpos) 6210 if !hadtgt 6211 sil! NetrwKeepj norm! j 6212 endif 6213 endfunction 6214 6215 " s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2 6216 function s:NetrwGetCurdir(islocal) 6217 6218 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 6219 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop) 6220 elseif !exists("b:netrw_curdir") 6221 let b:netrw_curdir= getcwd() 6222 endif 6223 6224 if b:netrw_curdir !~ '\<\a\{3,}://' 6225 let curdir= b:netrw_curdir 6226 if g:netrw_keepdir == 0 6227 call s:NetrwLcd(curdir) 6228 endif 6229 endif 6230 6231 return b:netrw_curdir 6232 endfunction 6233 6234 " s:NetrwOpenFile: query user for a filename and open it {{{2 6235 function s:NetrwOpenFile(islocal) 6236 call inputsave() 6237 let fname = input("Enter filename: ") 6238 call inputrestore() 6239 6240 if empty(fname) 6241 return 6242 endif 6243 6244 " save position for benefit of Rexplore 6245 let s:rexposn_{bufnr("%")}= winsaveview() 6246 6247 execute "NetrwKeepj e " . fnameescape(!isabsolutepath(fname) 6248 \ ? netrw#fs#ComposePath(b:netrw_curdir, fname) 6249 \ : fname) 6250 endfunction 6251 6252 " netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2 6253 " For the mapping to this function be made via 6254 " netrwPlugin, you'll need to have had 6255 " g:netrw_usetab set to non-zero. 6256 function netrw#Shrink() 6257 let curwin = winnr() 6258 let wiwkeep = &wiw 6259 set wiw=1 6260 6261 if &ft == "netrw" 6262 if winwidth(0) > g:netrw_wiw 6263 let t:netrw_winwidth= winwidth(0) 6264 exe "vert resize ".g:netrw_wiw 6265 wincmd l 6266 if winnr() == curwin 6267 wincmd h 6268 endif 6269 else 6270 exe "vert resize ".t:netrw_winwidth 6271 endif 6272 6273 elseif exists("t:netrw_lexbufnr") 6274 exe bufwinnr(t:netrw_lexbufnr)."wincmd w" 6275 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw 6276 let t:netrw_winwidth= winwidth(0) 6277 exe "vert resize ".g:netrw_wiw 6278 wincmd l 6279 if winnr() == curwin 6280 wincmd h 6281 endif 6282 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0 6283 exe "vert resize ".t:netrw_winwidth 6284 else 6285 call netrw#Lexplore(0,0) 6286 endif 6287 6288 else 6289 call netrw#Lexplore(0,0) 6290 endif 6291 let wiw= wiwkeep 6292 6293 endfunction 6294 6295 " s:NetSortSequence: allows user to edit the sorting sequence {{{2 6296 function s:NetSortSequence(islocal) 6297 let ykeep= @@ 6298 let svpos= winsaveview() 6299 call inputsave() 6300 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence) 6301 call inputrestore() 6302 6303 " refresh the listing 6304 let g:netrw_sort_sequence= newsortseq 6305 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6306 NetrwKeepj call winrestview(svpos) 6307 let @@= ykeep 6308 endfunction 6309 6310 " s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2 6311 " User access provided by the <mF> mapping. (see :help netrw-mF) 6312 " Used by many MarkFile functions. 6313 function s:NetrwUnmarkList(curbufnr,curdir) 6314 6315 " remove all files in local marked-file list from global list 6316 if exists("s:netrwmarkfilelist") 6317 for mfile in s:netrwmarkfilelist_{a:curbufnr} 6318 let dfile = netrw#fs#ComposePath(a:curdir,mfile) " prepend directory to mfile 6319 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile 6320 call remove(s:netrwmarkfilelist,idx) " remove from global list 6321 endfor 6322 if s:netrwmarkfilelist == [] 6323 unlet s:netrwmarkfilelist 6324 endif 6325 6326 " getting rid of the local marked-file lists is easy 6327 unlet s:netrwmarkfilelist_{a:curbufnr} 6328 endif 6329 if exists("s:netrwmarkfilemtch_{a:curbufnr}") 6330 unlet s:netrwmarkfilemtch_{a:curbufnr} 6331 endif 6332 2match none 6333 endfunction 6334 6335 " s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2 6336 function s:NetrwUnmarkAll() 6337 if exists("s:netrwmarkfilelist") 6338 unlet s:netrwmarkfilelist 6339 endif 6340 sil call s:NetrwUnmarkAll2() 6341 2match none 6342 endfunction 6343 6344 " s:NetrwUnmarkAll2: unmark all files from all buffers {{{2 6345 function s:NetrwUnmarkAll2() 6346 redir => netrwmarkfilelist_let 6347 let 6348 redir END 6349 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list 6350 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_ 6351 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to 6352 for flist in netrwmarkfilelist_list 6353 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','') 6354 unlet s:netrwmarkfilelist_{curbufnr} 6355 unlet s:netrwmarkfilemtch_{curbufnr} 6356 endfor 6357 endfunction 6358 6359 " s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2 6360 " 6361 " Marked files are in two types of lists: 6362 " s:netrwmarkfilelist -- holds complete paths to all marked files 6363 " s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr()) 6364 " 6365 " Marked files suitable for use with 2match are in: 6366 " s:netrwmarkfilemtch_# -- used with 2match to display marked files 6367 function s:NetrwUnMarkFile(islocal) 6368 let svpos = winsaveview() 6369 let curbufnr = bufnr("%") 6370 6371 " unmark marked file list 6372 " (although I expect s:NetrwUpload() to do it, I'm just making sure) 6373 if exists("s:netrwmarkfilelist") 6374 unlet s:netrwmarkfilelist 6375 endif 6376 6377 let ibuf= 1 6378 while ibuf <= bufnr("$") 6379 if exists("s:netrwmarkfilelist_".ibuf) 6380 unlet s:netrwmarkfilelist_{ibuf} 6381 unlet s:netrwmarkfilemtch_{ibuf} 6382 endif 6383 let ibuf = ibuf + 1 6384 endwhile 6385 2match none 6386 6387 " call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6388 call winrestview(svpos) 6389 endfunction 6390 6391 " s:NetrwMenu: generates the menu for gvim and netrw {{{2 6392 function s:NetrwMenu(domenu) 6393 6394 if !exists("g:NetrwMenuPriority") 6395 let g:NetrwMenuPriority= 80 6396 endif 6397 6398 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu 6399 6400 if !exists("s:netrw_menu_enabled") && a:domenu 6401 let s:netrw_menu_enabled= 1 6402 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>' 6403 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :' 6404 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -' 6405 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x' 6406 if g:netrw_dirhistmax > 0 6407 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb' 6408 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u' 6409 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U' 6410 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb' 6411 else 6412 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>" 6413 endif 6414 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o' 6415 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v' 6416 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t' 6417 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p' 6418 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'" 6419 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S' 6420 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh" 6421 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>" 6422 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>" 6423 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D' 6424 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %' 6425 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>" 6426 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p' 6427 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P' 6428 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o' 6429 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t' 6430 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v' 6431 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore ' 6432 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */' 6433 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/' 6434 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//' 6435 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//' 6436 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>' 6437 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>' 6438 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d' 6439 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf' 6440 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr' 6441 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a' 6442 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc' 6443 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D' 6444 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md' 6445 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me' 6446 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx' 6447 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm' 6448 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O' 6449 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp' 6450 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R' 6451 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt' 6452 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT' 6453 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz' 6454 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O' 6455 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>' 6456 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>' 6457 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>' 6458 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>' 6459 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>' 6460 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>' 6461 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>' 6462 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r" 6463 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>' 6464 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>' 6465 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>' 6466 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>' 6467 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R' 6468 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c' 6469 let s:netrw_menucnt= 28 6470 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x 6471 call s:NetrwTgtMenu() " let bookmarks and history be easy targets 6472 6473 elseif !a:domenu 6474 let s:netrwcnt = 0 6475 let curwin = winnr() 6476 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif 6477 exe curwin."wincmd w" 6478 6479 if s:netrwcnt <= 1 6480 exe 'sil! unmenu '.g:NetrwTopLvlMenu 6481 sil! unlet s:netrw_menu_enabled 6482 endif 6483 endif 6484 return 6485 endif 6486 6487 endfunction 6488 6489 " s:NetrwObtain: obtain file under cursor or from markfile list {{{2 6490 " Used by the O maps (as <SID>NetrwObtain()) 6491 function s:NetrwObtain(islocal) 6492 6493 let ykeep= @@ 6494 if exists("s:netrwmarkfilelist_{bufnr('%')}") 6495 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://' 6496 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')}) 6497 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir) 6498 else 6499 call netrw#Obtain(a:islocal,s:NetrwGetWord()) 6500 endif 6501 let @@= ykeep 6502 6503 endfunction 6504 6505 " s:NetrwPrevWinOpen: open file/directory in previous window. {{{2 6506 " If there's only one window, then the window will first be split. 6507 " Returns: 6508 " choice = 0 : didn't have to choose 6509 " choice = 1 : saved modified file in window first 6510 " choice = 2 : didn't save modified file, opened window 6511 " choice = 3 : cancel open 6512 function s:NetrwPrevWinOpen(islocal) 6513 let ykeep= @@ 6514 " grab a copy of the b:netrw_curdir to pass it along to newly split windows 6515 let curdir = b:netrw_curdir 6516 6517 " get last window number and the word currently under the cursor 6518 let origwin = winnr() 6519 let lastwinnr = winnr("$") 6520 let curword = s:NetrwGetWord() 6521 let choice = 0 6522 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen) 6523 let s:treedir = s:NetrwTreeDir(a:islocal) 6524 let curdir = s:treedir 6525 6526 let didsplit = 0 6527 if lastwinnr == 1 6528 " if only one window, open a new one first 6529 " g:netrw_preview=0: preview window shown in a horizontally split window 6530 " g:netrw_preview=1: preview window shown in a vertically split window 6531 if g:netrw_preview 6532 " vertically split preview window 6533 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize 6534 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s" 6535 else 6536 " horizontally split preview window 6537 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize 6538 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" 6539 endif 6540 let didsplit = 1 6541 6542 else 6543 NetrwKeepj call s:SaveBufVars() 6544 let eikeep= &ei 6545 setl ei=all 6546 wincmd p 6547 6548 if exists("s:lexplore_win") && s:lexplore_win == winnr() 6549 " whoops -- user trying to open file in the Lexplore window. 6550 " Use Lexplore's opening-file window instead. 6551 " exe g:netrw_chgwin."wincmd w" 6552 wincmd p 6553 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 6554 endif 6555 6556 " prevwinnr: the window number of the "prev" window 6557 " prevbufnr: the buffer number of the buffer in the "prev" window 6558 " bnrcnt : the qty of windows open on the "prev" buffer 6559 let prevwinnr = winnr() 6560 let prevbufnr = bufnr("%") 6561 let prevbufname = bufname("%") 6562 let prevmod = &mod 6563 let bnrcnt = 0 6564 NetrwKeepj call s:RestoreBufVars() 6565 6566 " if the previous window's buffer has been changed (ie. its modified flag is set), 6567 " and it doesn't appear in any other extant window, then ask the 6568 " user if s/he wants to abandon modifications therein. 6569 if prevmod 6570 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif 6571 exe prevwinnr."wincmd w" 6572 6573 if bnrcnt == 1 && &hidden == 0 6574 " only one copy of the modified buffer in a window, and 6575 " hidden not set, so overwriting will lose the modified file. Ask first... 6576 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel") 6577 let &ei= eikeep 6578 6579 if choice == 1 6580 " Yes -- write file & then browse 6581 let v:errmsg= "" 6582 sil w 6583 if v:errmsg != "" 6584 call netrw#msg#Notify('ERROR', printf('unable to write <%s>!', (exists("prevbufname") ? prevbufname : 'n/a'))) 6585 exe origwin."wincmd w" 6586 let &ei = eikeep 6587 let @@ = ykeep 6588 return choice 6589 endif 6590 6591 elseif choice == 2 6592 " No -- don't worry about changed file, just browse anyway 6593 echomsg "**note** changes to ".prevbufname." abandoned" 6594 6595 else 6596 " Cancel -- don't do this 6597 exe origwin."wincmd w" 6598 let &ei= eikeep 6599 let @@ = ykeep 6600 return choice 6601 endif 6602 endif 6603 endif 6604 let &ei= eikeep 6605 endif 6606 6607 " restore b:netrw_curdir (window split/enew may have lost it) 6608 let b:netrw_curdir= curdir 6609 if a:islocal < 2 6610 if a:islocal 6611 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0)) 6612 else 6613 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0)) 6614 endif 6615 endif 6616 let @@= ykeep 6617 return choice 6618 endfunction 6619 6620 " s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2 6621 " Always assumed to be local -> remote 6622 " call s:NetrwUpload(filename, target) 6623 " call s:NetrwUpload(filename, target, fromdirectory) 6624 function s:NetrwUpload(fname,tgt,...) 6625 6626 if a:tgt =~ '^\a\{3,}://' 6627 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','') 6628 else 6629 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','') 6630 endif 6631 6632 if a:0 > 0 6633 let fromdir= a:1 6634 else 6635 let fromdir= getcwd() 6636 endif 6637 6638 if type(a:fname) == 1 6639 " handle uploading a single file using NetWrite 6640 1split 6641 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname)) 6642 if a:tgt =~ '/$' 6643 let wfname= substitute(a:fname,'^.*/','','') 6644 exe "w! ".fnameescape(a:tgt.wfname) 6645 else 6646 exe "w ".fnameescape(a:tgt) 6647 endif 6648 q! 6649 6650 elseif type(a:fname) == 3 6651 " handle uploading a list of files via scp 6652 let curdir= getcwd() 6653 if a:tgt =~ '^scp:' 6654 if s:NetrwLcd(fromdir) 6655 return 6656 endif 6657 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')}) 6658 let args = join(map(filelist,"netrw#os#Escape(v:val, 1)")) 6659 if exists("g:netrw_port") && g:netrw_port != "" 6660 let useport= " ".g:netrw_scpport." ".g:netrw_port 6661 else 6662 let useport= "" 6663 endif 6664 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','') 6665 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','') 6666 call netrw#os#Execute(s:netrw_silentxfer."!".g:netrw_scp_cmd.netrw#os#Escape(useport,1)." ".args." ".netrw#os#Escape(machine.":".tgt,1)) 6667 if s:NetrwLcd(curdir) 6668 return 6669 endif 6670 6671 elseif a:tgt =~ '^ftp:' 6672 call s:NetrwMethod(a:tgt) 6673 if !s:NetrwValidateHostname(g:netrw_machine) 6674 call netrw#msg#Notify('ERROR', printf('Rejecting invalid hostname: <%s>', g:netrw_machine)) 6675 return 6676 endif 6677 6678 if b:netrw_method == 2 6679 " handle uploading a list of files via ftp+.netrc 6680 let netrw_fname = b:netrw_fname 6681 sil NetrwKeepj new 6682 6683 NetrwKeepj put =g:netrw_ftpmode 6684 6685 if exists("g:netrw_ftpextracmd") 6686 NetrwKeepj put =g:netrw_ftpextracmd 6687 endif 6688 6689 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"') 6690 6691 if tgtdir == "" 6692 let tgtdir= '/' 6693 endif 6694 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"') 6695 6696 for fname in a:fname 6697 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"') 6698 endfor 6699 6700 if exists("g:netrw_port") && g:netrw_port != "" 6701 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)." ".netrw#os#Escape(g:netrw_port,1)) 6702 else 6703 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)) 6704 endif 6705 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 6706 sil NetrwKeepj g/Local directory now/d 6707 call histdel("/",-1) 6708 if getline(1) !~ "^$" && getline(1) !~ '^Trying ' 6709 call netrw#msg#Notify('ERROR', getline(1)) 6710 else 6711 bw!|q 6712 endif 6713 6714 elseif b:netrw_method == 3 6715 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc) 6716 let netrw_fname= b:netrw_fname 6717 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars() 6718 let tmpbufnr= bufnr("%") 6719 setl ff=unix 6720 6721 if exists("g:netrw_port") && g:netrw_port != "" 6722 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 6723 else 6724 NetrwKeepj put ='open '.g:netrw_machine 6725 endif 6726 6727 if exists("g:netrw_uid") && g:netrw_uid != "" 6728 if exists("g:netrw_ftp") && g:netrw_ftp == 1 6729 NetrwKeepj put =g:netrw_uid 6730 if exists("s:netrw_passwd") 6731 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"') 6732 endif 6733 elseif exists("s:netrw_passwd") 6734 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 6735 endif 6736 endif 6737 6738 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"') 6739 6740 if exists("b:netrw_fname") && b:netrw_fname != "" 6741 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"') 6742 endif 6743 6744 if exists("g:netrw_ftpextracmd") 6745 NetrwKeepj put =g:netrw_ftpextracmd 6746 endif 6747 6748 for fname in a:fname 6749 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"') 6750 endfor 6751 6752 " perform ftp: 6753 " -i : turns off interactive prompting from ftp 6754 " -n unix : DON'T use <.netrc>, even though it exists 6755 " -n win32: quit being obnoxious about password 6756 NetrwKeepj norm! 1G"_dd 6757 call netrw#os#Execute(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) 6758 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 6759 sil NetrwKeepj g/Local directory now/d 6760 call histdel("/",-1) 6761 if getline(1) !~ "^$" && getline(1) !~ '^Trying ' 6762 let debugkeep= &debug 6763 setl debug=msg 6764 call netrw#msg#Notify('ERROR', getline(1)) 6765 let &debug = debugkeep 6766 let mod = 1 6767 else 6768 bw!|q 6769 endif 6770 elseif !exists("b:netrw_method") || b:netrw_method < 0 6771 return 6772 endif 6773 else 6774 call netrw#msg#Notify('ERROR', printf("can't obtain files with protocol from<%s>", a:tgt)) 6775 endif 6776 endif 6777 6778 endfunction 6779 6780 " s:NetrwPreview: supports netrw's "p" map {{{2 6781 function s:NetrwPreview(path) range 6782 let ykeep= @@ 6783 NetrwKeepj call s:NetrwOptionsSave("s:") 6784 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://' 6785 NetrwKeepj call s:NetrwOptionsSafe(1) 6786 else 6787 NetrwKeepj call s:NetrwOptionsSafe(0) 6788 endif 6789 if has("quickfix") 6790 if !isdirectory(s:NetrwFile(a:path)) 6791 if g:netrw_preview 6792 " vertical split 6793 let pvhkeep = &pvh 6794 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize 6795 let &pvh = winwidth(0) - winsz 6796 else 6797 " horizontal split 6798 let pvhkeep = &pvh 6799 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize 6800 let &pvh = winheight(0) - winsz 6801 endif 6802 " g:netrw_preview g:netrw_alto 6803 " 1 : vert 1: top -- preview window is vertically split off and on the left 6804 " 1 : vert 0: bot -- preview window is vertically split off and on the right 6805 " 0 : 1: top -- preview window is horizontally split off and on the top 6806 " 0 : 0: bot -- preview window is horizontally split off and on the bottom 6807 " 6808 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via 6809 " the BufEnter event set up in netrwPlugin.vim 6810 let eikeep = &ei 6811 set ei=BufEnter 6812 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path) 6813 let &ei= eikeep 6814 if exists("pvhkeep") 6815 let &pvh= pvhkeep 6816 endif 6817 else 6818 call netrw#msg#Notify('WARNING', printf('sorry, cannot preview a directory such as <%s>', a:path)) 6819 endif 6820 else 6821 call netrw#msg#Notify('WARNING', 'sorry, to preview your vim needs the quickfix feature compiled in') 6822 endif 6823 NetrwKeepj call s:NetrwOptionsRestore("s:") 6824 let @@= ykeep 6825 endfunction 6826 6827 " s:NetrwRefresh: {{{2 6828 function s:NetrwRefresh(islocal,dirname) 6829 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first. 6830 setl ma noro 6831 let ykeep = @@ 6832 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 6833 if !exists("w:netrw_treetop") 6834 if exists("b:netrw_curdir") 6835 let w:netrw_treetop= b:netrw_curdir 6836 else 6837 let w:netrw_treetop= getcwd() 6838 endif 6839 endif 6840 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop) 6841 endif 6842 6843 " save the cursor position before refresh. 6844 let screenposn = winsaveview() 6845 6846 sil! NetrwKeepj %d _ 6847 if a:islocal 6848 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname) 6849 else 6850 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname) 6851 endif 6852 6853 " restore position 6854 NetrwKeepj call winrestview(screenposn) 6855 6856 " restore file marks 6857 if has("syntax") && exists("g:syntax_on") && g:syntax_on 6858 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != "" 6859 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/" 6860 else 6861 2match none 6862 endif 6863 endif 6864 6865 " restore 6866 let @@= ykeep 6867 endfunction 6868 6869 " s:NetrwRefreshDir: refreshes a directory by name {{{2 6870 " Called by NetrwMarkFileCopy() 6871 " Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh() 6872 function s:NetrwRefreshDir(islocal,dirname) 6873 if g:netrw_fastbrowse == 0 6874 " slowest mode (keep buffers refreshed, local or remote) 6875 let tgtwin= bufwinnr(a:dirname) 6876 6877 if tgtwin > 0 6878 " tgtwin is being displayed, so refresh it 6879 let curwin= winnr() 6880 exe tgtwin."wincmd w" 6881 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6882 exe curwin."wincmd w" 6883 6884 elseif bufnr(a:dirname) > 0 6885 let bn= bufnr(a:dirname) 6886 exe "sil keepj bd ".bn 6887 endif 6888 6889 elseif g:netrw_fastbrowse <= 1 6890 NetrwKeepj call s:LocalBrowseRefresh() 6891 endif 6892 endfunction 6893 6894 " s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified 6895 " window number to do its editing in. 6896 " Supports [count]C where the count, if present, is used to specify 6897 " a window to use for editing via the <cr> mapping. 6898 function s:NetrwSetChgwin(...) 6899 if a:0 > 0 6900 if a:1 == "" " :NetrwC win# 6901 let g:netrw_chgwin= winnr() 6902 else " :NetrwC 6903 let g:netrw_chgwin= a:1 6904 endif 6905 elseif v:count > 0 " [count]C 6906 let g:netrw_chgwin= v:count 6907 else " C 6908 let g:netrw_chgwin= winnr() 6909 endif 6910 echo "editing window now set to window#".g:netrw_chgwin 6911 endfunction 6912 6913 " s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2 6914 " What this function does is to compute a priority for the patterns 6915 " in the g:netrw_sort_sequence. It applies a substitute to any 6916 " "files" that satisfy each pattern, putting the priority / in 6917 " front. An "*" pattern handles the default priority. 6918 function s:NetrwSetSort() 6919 let ykeep= @@ 6920 if w:netrw_liststyle == s:LONGLIST 6921 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge') 6922 else 6923 let seqlist = g:netrw_sort_sequence 6924 endif 6925 " sanity check -- insure that * appears somewhere 6926 if seqlist == "" 6927 let seqlist= '*' 6928 elseif seqlist !~ '\*' 6929 let seqlist= seqlist.',*' 6930 endif 6931 let priority = 1 6932 while seqlist != "" 6933 if seqlist =~ ',' 6934 let seq = substitute(seqlist,',.*$','','e') 6935 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e') 6936 else 6937 let seq = seqlist 6938 let seqlist = "" 6939 endif 6940 if priority < 10 6941 let spriority= "00".priority.g:netrw_sepchr 6942 elseif priority < 100 6943 let spriority= "0".priority.g:netrw_sepchr 6944 else 6945 let spriority= priority.g:netrw_sepchr 6946 endif 6947 6948 " sanity check 6949 if w:netrw_bannercnt > line("$") 6950 " apparently no files were left after a Hiding pattern was used 6951 return 6952 endif 6953 if seq == '*' 6954 let starpriority= spriority 6955 else 6956 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/' 6957 call histdel("/",-1) 6958 " sometimes multiple sorting patterns will match the same file or directory. 6959 " The following substitute is intended to remove the excess matches. 6960 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e' 6961 NetrwKeepj call histdel("/",-1) 6962 endif 6963 let priority = priority + 1 6964 endwhile 6965 if exists("starpriority") 6966 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e' 6967 NetrwKeepj call histdel("/",-1) 6968 endif 6969 6970 " Following line associated with priority -- items that satisfy a priority 6971 " pattern get prefixed by ###/ which permits easy sorting by priority. 6972 " Sometimes files can satisfy multiple priority patterns -- only the latest 6973 " priority pattern needs to be retained. So, at this point, these excess 6974 " priority prefixes need to be removed, but not directories that happen to 6975 " be just digits themselves. 6976 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e' 6977 NetrwKeepj call histdel("/",-1) 6978 let @@= ykeep 6979 6980 endfunction 6981 6982 " s:NetrwSetTgt: sets the target to the specified choice index {{{2 6983 " Implements [count]Tb (bookhist<b>) 6984 " [count]Th (bookhist<h>) 6985 " See :help netrw-qb for how to make the choice. 6986 function s:NetrwSetTgt(islocal,bookhist,choice) 6987 6988 if a:bookhist == 'b' 6989 " supports choosing a bookmark as a target using a qb-generated list 6990 let choice= a:choice - 1 6991 if exists("g:netrw_bookmarklist[".choice."]") 6992 call netrw#MakeTgt(g:netrw_bookmarklist[choice]) 6993 else 6994 echomsg "Sorry, bookmark#".a:choice." doesn't exist!" 6995 endif 6996 6997 elseif a:bookhist == 'h' 6998 " supports choosing a history stack entry as a target using a qb-generated list 6999 let choice= (a:choice % g:netrw_dirhistmax) + 1 7000 if exists("g:netrw_dirhist_".choice) 7001 let histentry = g:netrw_dirhist_{choice} 7002 call netrw#MakeTgt(histentry) 7003 else 7004 echomsg "Sorry, history#".a:choice." not available!" 7005 endif 7006 endif 7007 7008 " refresh the display 7009 if !exists("b:netrw_curdir") 7010 let b:netrw_curdir= getcwd() 7011 endif 7012 call s:NetrwRefresh(a:islocal,b:netrw_curdir) 7013 7014 endfunction 7015 7016 " s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2 7017 function s:NetrwSortStyle(islocal) 7018 NetrwKeepj call s:NetrwSaveWordPosn() 7019 let svpos= winsaveview() 7020 7021 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name' 7022 NetrwKeepj norm! 0 7023 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 7024 NetrwKeepj call winrestview(svpos) 7025 endfunction 7026 7027 " s:NetrwSplit: mode {{{2 7028 " =0 : net and o 7029 " =1 : net and t 7030 " =2 : net and v 7031 " =3 : local and o 7032 " =4 : local and t 7033 " =5 : local and v 7034 function s:NetrwSplit(mode) 7035 7036 let ykeep= @@ 7037 call s:SaveWinVars() 7038 7039 if a:mode == 0 7040 " remote and o 7041 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize 7042 if winsz == 0|let winsz= ""|endif 7043 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" 7044 let s:didsplit= 1 7045 NetrwKeepj call s:RestoreWinVars() 7046 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 7047 unlet s:didsplit 7048 7049 elseif a:mode == 1 7050 " remote and t 7051 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1) 7052 tabnew 7053 let s:didsplit= 1 7054 NetrwKeepj call s:RestoreWinVars() 7055 NetrwKeepj call s:NetrwBrowse(0,newdir) 7056 unlet s:didsplit 7057 7058 elseif a:mode == 2 7059 " remote and v 7060 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize 7061 if winsz == 0|let winsz= ""|endif 7062 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v" 7063 let s:didsplit= 1 7064 NetrwKeepj call s:RestoreWinVars() 7065 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 7066 unlet s:didsplit 7067 7068 elseif a:mode == 3 7069 " local and o 7070 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize 7071 if winsz == 0|let winsz= ""|endif 7072 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s" 7073 let s:didsplit= 1 7074 NetrwKeepj call s:RestoreWinVars() 7075 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 7076 unlet s:didsplit 7077 if &ea 7078 exe "keepalt wincmd =" 7079 endif 7080 7081 elseif a:mode == 4 7082 " local and t 7083 let cursorword = s:NetrwGetWord() 7084 let eikeep = &ei 7085 let netrw_winnr = winnr() 7086 let netrw_line = line(".") 7087 let netrw_col = virtcol(".") 7088 NetrwKeepj norm! H0 7089 let netrw_hline = line(".") 7090 setl ei=all 7091 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>" 7092 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>" 7093 let &ei = eikeep 7094 let netrw_curdir = s:NetrwTreeDir(0) 7095 tabnew 7096 let b:netrw_curdir = netrw_curdir 7097 let s:didsplit = 1 7098 NetrwKeepj call s:RestoreWinVars() 7099 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0)) 7100 if &ft == "netrw" 7101 setl ei=all 7102 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>" 7103 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>" 7104 let &ei= eikeep 7105 endif 7106 unlet s:didsplit 7107 7108 elseif a:mode == 5 7109 " local and v 7110 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize 7111 if winsz == 0|let winsz= ""|endif 7112 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v" 7113 let s:didsplit= 1 7114 NetrwKeepj call s:RestoreWinVars() 7115 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 7116 unlet s:didsplit 7117 if &ea 7118 exe "keepalt wincmd =" 7119 endif 7120 7121 else 7122 call netrw#msg#Notify('ERROR', '(NetrwSplit) unsupported mode='.a:mode) 7123 endif 7124 7125 let @@= ykeep 7126 endfunction 7127 7128 " s:NetrwTgtMenu: {{{2 7129 function s:NetrwTgtMenu() 7130 if !exists("s:netrw_menucnt") 7131 return 7132 endif 7133 7134 " the following test assures that gvim is running, has menus available, and has menus enabled. 7135 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu 7136 if exists("g:NetrwTopLvlMenu") 7137 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets' 7138 endif 7139 if !exists("s:netrw_initbookhist") 7140 call s:NetrwBookHistRead() 7141 endif 7142 7143 " try to cull duplicate entries 7144 let tgtdict={} 7145 7146 " target bookmarked places 7147 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0 7148 let cnt= 1 7149 for bmd in g:netrw_bookmarklist 7150 if has_key(tgtdict,bmd) 7151 let cnt= cnt + 1 7152 continue 7153 endif 7154 let tgtdict[bmd]= cnt 7155 let ebmd= escape(bmd,g:netrw_menu_escape) 7156 " show bookmarks for goto menu 7157 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt(".escape(string(bmd),'|').")\<cr>" 7158 let cnt= cnt + 1 7159 endfor 7160 endif 7161 7162 " target directory browsing history 7163 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0 7164 let histcnt = 1 7165 while histcnt <= g:netrw_dirhistmax 7166 let priority = g:netrw_dirhistcnt + histcnt 7167 if exists("g:netrw_dirhist_{histcnt}") 7168 let histentry = g:netrw_dirhist_{histcnt} 7169 if has_key(tgtdict,histentry) 7170 let histcnt = histcnt + 1 7171 continue 7172 endif 7173 let tgtdict[histentry] = histcnt 7174 let ehistentry = escape(histentry,g:netrw_menu_escape) 7175 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt(".escape(string(histentry),'|').")\<cr>" 7176 endif 7177 let histcnt = histcnt + 1 7178 endwhile 7179 endif 7180 endif 7181 endfunction 7182 7183 " s:NetrwTreeDir: determine tree directory given current cursor position {{{2 7184 " (full path directory with trailing slash returned) 7185 function s:NetrwTreeDir(islocal) 7186 7187 if exists("s:treedir") && exists("s:prevwinopen") 7188 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early 7189 let treedir= s:treedir 7190 unlet s:treedir 7191 unlet s:prevwinopen 7192 return treedir 7193 endif 7194 if exists("s:prevwinopen") 7195 unlet s:prevwinopen 7196 endif 7197 7198 if !exists("b:netrw_curdir") || b:netrw_curdir == "" 7199 let b:netrw_curdir= getcwd() 7200 endif 7201 let treedir = b:netrw_curdir 7202 let s:treecurpos= winsaveview() 7203 7204 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 7205 7206 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/") 7207 let curline= substitute(getline('.'),"\t -->.*$",'','') 7208 if curline =~ '/$' 7209 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e') 7210 elseif curline =~ '@$' 7211 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop)) 7212 else 7213 let treedir= "" 7214 endif 7215 7216 " detect user attempting to close treeroot 7217 if curline !~ '^'.s:treedepthstring && getline('.') != '..' 7218 " now force a refresh 7219 sil! NetrwKeepj %d _ 7220 return b:netrw_curdir 7221 endif 7222 7223 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop 7224 " if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir)) 7225 " let newdir = w:netrw_treetop.'/'.potentialdir 7226 if a:islocal && curline =~ '@$' 7227 if isdirectory(s:NetrwFile(potentialdir)) 7228 let treedir = potentialdir 7229 let w:netrw_treetop = treedir 7230 endif 7231 else 7232 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1','')) 7233 let treedir = s:NetrwTreePath(w:netrw_treetop) 7234 endif 7235 endif 7236 7237 " sanity maintenance: keep those //s away... 7238 let treedir= substitute(treedir,'//$','/','') 7239 return treedir 7240 endfunction 7241 7242 " s:NetrwTreeDisplay: recursive tree display {{{2 7243 function s:NetrwTreeDisplay(dir,depth) 7244 " ensure that there are no folds 7245 setl nofen 7246 7247 " install ../ and shortdir 7248 if a:depth == "" 7249 call setline(line("$")+1,'../') 7250 endif 7251 if a:dir =~ '^\a\{3,}://' 7252 if a:dir == w:netrw_treetop 7253 let shortdir= a:dir 7254 else 7255 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e') 7256 endif 7257 call setline(line("$")+1,a:depth.shortdir) 7258 else 7259 let shortdir= substitute(a:dir,'^.*/','','e') 7260 call setline(line("$")+1,a:depth.shortdir.'/') 7261 endif 7262 " append a / to dir if its missing one 7263 let dir= a:dir 7264 7265 " display subtrees (if any) 7266 let depth= s:treedepthstring.a:depth 7267 7268 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide) 7269 if g:netrw_hide == 1 7270 " hide given patterns 7271 let listhide= split(g:netrw_list_hide,',') 7272 for pat in listhide 7273 call filter(w:netrw_treedict[dir], {_, v -> v !~# pat}) 7274 endfor 7275 7276 elseif g:netrw_hide == 2 7277 " show given patterns (only) 7278 let listhide= split(g:netrw_list_hide,',') 7279 let entries=[] 7280 for entry in w:netrw_treedict[dir] 7281 for pat in listhide 7282 if entry =~ pat 7283 call add(entries,entry) 7284 break 7285 endif 7286 endfor 7287 endfor 7288 let w:netrw_treedict[dir]= entries 7289 endif 7290 if depth != "" 7291 " always remove "." and ".." entries when there's depth 7292 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"') 7293 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"') 7294 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"') 7295 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"') 7296 endif 7297 7298 for entry in w:netrw_treedict[dir] 7299 if dir =~ '/$' 7300 let direntry= substitute(dir.entry,'[@/]$','','e') 7301 else 7302 let direntry= substitute(dir.'/'.entry,'[@/]$','','e') 7303 endif 7304 if entry =~ '/$' && has_key(w:netrw_treedict,direntry) 7305 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth) 7306 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/') 7307 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth) 7308 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@') 7309 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth) 7310 else 7311 sil! NetrwKeepj call setline(line("$")+1,depth.entry) 7312 endif 7313 endfor 7314 endfunction 7315 7316 " s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2 7317 function s:NetrwRefreshTreeDict(dir) 7318 if !exists("w:netrw_treedict") 7319 return 7320 endif 7321 7322 for entry in w:netrw_treedict[a:dir] 7323 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e') 7324 7325 if entry =~ '/$' && has_key(w:netrw_treedict,direntry) 7326 NetrwKeepj call s:NetrwRefreshTreeDict(direntry) 7327 let filelist = s:NetrwLocalListingList(direntry,0) 7328 let w:netrw_treedict[direntry] = sort(filelist) 7329 7330 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/') 7331 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/') 7332 let filelist = s:NetrwLocalListingList(direntry.'/',0) 7333 let w:netrw_treedict[direntry] = sort(filelist) 7334 7335 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@') 7336 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/') 7337 let liststar = netrw#fs#Glob(direntry.'/','*',1) 7338 let listdotstar= netrw#fs#Glob(direntry.'/','.*',1) 7339 7340 else 7341 endif 7342 endfor 7343 endfunction 7344 7345 " s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2 7346 " Called by s:PerformListing() 7347 function s:NetrwTreeListing(dirname) 7348 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 7349 7350 " update the treetop 7351 if !exists("w:netrw_treetop") 7352 let w:netrw_treetop= a:dirname 7353 let s:netrw_treetop= w:netrw_treetop 7354 " use \V in case the directory contains specials chars like '$' or '~' 7355 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) 7356 \ && strdisplaywidth(a:dirname) < strdisplaywidth(w:netrw_treetop)) 7357 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop) 7358 let w:netrw_treetop= a:dirname 7359 let s:netrw_treetop= w:netrw_treetop 7360 endif 7361 if exists("w:netrw_treetop") 7362 let s:netrw_treetop= w:netrw_treetop 7363 else 7364 let w:netrw_treetop= getcwd() 7365 let s:netrw_treetop= w:netrw_treetop 7366 endif 7367 7368 if !exists("w:netrw_treedict") 7369 " insure that we have a treedict, albeit empty 7370 let w:netrw_treedict= {} 7371 endif 7372 7373 " update the dictionary for the current directory 7374 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _' 7375 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$")) 7376 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _" 7377 7378 " if past banner, record word 7379 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt 7380 let fname= expand("<cword>") 7381 else 7382 let fname= "" 7383 endif 7384 7385 " display from treetop on down 7386 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"") 7387 7388 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed) 7389 while getline(1) =~ '^\s*$' && byte2line(1) > 0 7390 1d 7391 endwhile 7392 7393 exe "setl ".g:netrw_bufsettings 7394 7395 return 7396 endif 7397 endfunction 7398 7399 " s:NetrwTreePath: returns path to current file/directory in tree listing {{{2 7400 " Normally, treetop is w:netrw_treetop, but a 7401 " user of the function ( netrw#SetTreetop() ) 7402 " wipes that out prior to calling this function 7403 function s:NetrwTreePath(treetop) 7404 if line(".") < w:netrw_bannercnt + 2 7405 let treedir= a:treetop 7406 if treedir !~ '/$' 7407 let treedir= treedir.'/' 7408 endif 7409 return treedir 7410 endif 7411 7412 let svpos = winsaveview() 7413 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e') 7414 let depth = substitute(depth,'^'.s:treedepthstring,'','') 7415 let curline= getline('.') 7416 if curline =~ '/$' 7417 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e') 7418 elseif curline =~ '@\s\+-->' 7419 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e') 7420 let treedir= substitute(treedir,'@\s\+-->.*$','','e') 7421 else 7422 let treedir= "" 7423 endif 7424 " construct treedir by searching backwards at correct depth 7425 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW') 7426 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e') 7427 let treedir= dirname.treedir 7428 let depth = substitute(depth,'^'.s:treedepthstring,'','') 7429 endwhile 7430 if a:treetop =~ '/$' 7431 let treedir= a:treetop.treedir 7432 else 7433 let treedir= a:treetop.'/'.treedir 7434 endif 7435 let treedir= substitute(treedir,'//$','/','') 7436 call winrestview(svpos) 7437 return treedir 7438 endfunction 7439 7440 " s:NetrwWideListing: {{{2 7441 function s:NetrwWideListing() 7442 7443 if w:netrw_liststyle == s:WIDELIST 7444 " look for longest filename (cpf=characters per filename) 7445 " cpf: characters per filename 7446 " fpl: filenames per line 7447 " fpc: filenames per column 7448 setl ma noro 7449 let dict={} 7450 " save the unnamed register and register 0-9 and a 7451 let dict.a=[getreg('a'), getregtype('a')] 7452 for i in range(0, 9) 7453 let dict[i] = [getreg(i), getregtype(i)] 7454 endfor 7455 let dict.unnamed = [getreg(''), getregtype('')] 7456 let b:netrw_cpf= 0 7457 if line("$") >= w:netrw_bannercnt 7458 " determine the maximum filename size; use that to set cpf 7459 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' 7460 NetrwKeepj call histdel("/",-1) 7461 else 7462 " restore stored registers 7463 call s:RestoreRegister(dict) 7464 return 7465 endif 7466 " allow for two spaces to separate columns 7467 let b:netrw_cpf= b:netrw_cpf + 2 7468 7469 " determine qty files per line (fpl) 7470 let w:netrw_fpl= winwidth(0)/b:netrw_cpf 7471 if w:netrw_fpl <= 0 7472 let w:netrw_fpl= 1 7473 endif 7474 7475 " make wide display 7476 " fpc: files per column of wide listing 7477 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/' 7478 NetrwKeepj call histdel("/",-1) 7479 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl 7480 let newcolstart = w:netrw_bannercnt + fpc 7481 let newcolend = newcolstart + fpc - 1 7482 if has("clipboard") && g:netrw_clipboard 7483 sil! let keepregstar = @* 7484 sil! let keepregplus = @+ 7485 endif 7486 while line("$") >= newcolstart 7487 if newcolend > line("$") | let newcolend= line("$") | endif 7488 let newcolqty= newcolend - newcolstart 7489 exe newcolstart 7490 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @* 7491 if newcolqty == 0 7492 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap" 7493 else 7494 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap' 7495 endif 7496 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _' 7497 exe 'sil! NetrwKeepj '.w:netrw_bannercnt 7498 endwhile 7499 if has("clipboard") 7500 if @* != keepregstar | sil! let @* = keepregstar | endif 7501 if @+ != keepregplus | sil! let @+ = keepregplus | endif 7502 endif 7503 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e' 7504 NetrwKeepj call histdel("/",-1) 7505 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>" 7506 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>" 7507 exe "setl ".g:netrw_bufsettings 7508 call s:RestoreRegister(dict) 7509 return 7510 else 7511 if hasmapto("w","n") 7512 sil! nunmap <buffer> w 7513 endif 7514 if hasmapto("b","n") 7515 sil! nunmap <buffer> b 7516 endif 7517 endif 7518 endfunction 7519 7520 " s:PerformListing: {{{2 7521 function s:PerformListing(islocal) 7522 sil! NetrwKeepj %d _ 7523 " call DechoBuf(bufnr("%")) 7524 7525 " set up syntax highlighting {{{3 7526 sil! setl ft=netrw 7527 7528 NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 7529 setl noro ma 7530 7531 7532 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") 7533 " force a refresh for tree listings 7534 sil! NetrwKeepj %d _ 7535 endif 7536 7537 " save current directory on directory history list 7538 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir) 7539 7540 " Set up the banner {{{3 7541 if g:netrw_banner 7542 NetrwKeepj call setline(1,'" ============================================================================') 7543 if exists("g:netrw_pchk") 7544 " this undocumented option allows pchk to run with different versions of netrw without causing spurious 7545 " failure detections. 7546 NetrwKeepj call setline(2,'" Netrw Directory Listing') 7547 else 7548 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')') 7549 endif 7550 if exists("g:netrw_pchk") 7551 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','') 7552 else 7553 let curdir= b:netrw_curdir 7554 endif 7555 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash 7556 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g')) 7557 else 7558 NetrwKeepj call setline(3,'" '.curdir) 7559 endif 7560 let w:netrw_bannercnt= 3 7561 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt 7562 else 7563 NetrwKeepj 1 7564 let w:netrw_bannercnt= 1 7565 endif 7566 7567 " construct sortby string: [name|time|size|exten] [reversed] 7568 let sortby= g:netrw_sort_by 7569 if g:netrw_sort_direction =~# "^r" 7570 let sortby= sortby." reversed" 7571 endif 7572 7573 " Sorted by... {{{3 7574 if g:netrw_banner 7575 if g:netrw_sort_by =~# "^n" 7576 " sorted by name (also includes the sorting sequence in the banner) 7577 NetrwKeepj put ='\" Sorted by '.sortby 7578 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence 7579 let w:netrw_bannercnt= w:netrw_bannercnt + 2 7580 else 7581 " sorted by time, size, exten 7582 NetrwKeepj put ='\" Sorted by '.sortby 7583 let w:netrw_bannercnt= w:netrw_bannercnt + 1 7584 endif 7585 exe "sil! NetrwKeepj ".w:netrw_bannercnt 7586 endif 7587 7588 " show copy/move target, if any {{{3 7589 if g:netrw_banner 7590 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") 7591 NetrwKeepj put ='' 7592 if s:netrwmftgt_islocal 7593 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)') 7594 else 7595 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)') 7596 endif 7597 let w:netrw_bannercnt= w:netrw_bannercnt + 1 7598 else 7599 endif 7600 exe "sil! NetrwKeepj ".w:netrw_bannercnt 7601 endif 7602 7603 " Hiding... -or- Showing... {{{3 7604 if g:netrw_banner 7605 if g:netrw_list_hide != "" && g:netrw_hide 7606 if g:netrw_hide == 1 7607 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide 7608 else 7609 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide 7610 endif 7611 let w:netrw_bannercnt= w:netrw_bannercnt + 1 7612 endif 7613 exe "NetrwKeepj ".w:netrw_bannercnt 7614 7615 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp) 7616 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp] 7617 NetrwKeepj put ='\" ==============================================================================' 7618 let w:netrw_bannercnt= w:netrw_bannercnt + 2 7619 endif 7620 7621 " bannercnt should index the line just after the banner 7622 if g:netrw_banner 7623 let w:netrw_bannercnt= w:netrw_bannercnt + 1 7624 exe "sil! NetrwKeepj ".w:netrw_bannercnt 7625 endif 7626 7627 " get list of files 7628 if a:islocal 7629 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1) 7630 call append(w:netrw_bannercnt - 1, filelist) 7631 silent! NetrwKeepj g/^$/d 7632 silent! NetrwKeepj %s/\r$//e 7633 execute printf("setl ts=%d", g:netrw_maxfilenamelen + 1) 7634 else " remote 7635 NetrwKeepj let badresult= s:NetrwRemoteListing() 7636 if badresult 7637 return 7638 endif 7639 endif 7640 7641 " manipulate the directory listing (hide, sort) {{{3 7642 if !exists("w:netrw_bannercnt") 7643 let w:netrw_bannercnt= 0 7644 endif 7645 7646 if !g:netrw_banner || line("$") >= w:netrw_bannercnt 7647 if g:netrw_hide && g:netrw_list_hide != "" 7648 NetrwKeepj call s:NetrwListHide() 7649 endif 7650 if !g:netrw_banner || line("$") >= w:netrw_bannercnt 7651 7652 if g:netrw_sort_by =~# "^n" 7653 " sort by name 7654 NetrwKeepj call s:NetrwSetSort() 7655 7656 if !g:netrw_banner || w:netrw_bannercnt < line("$") 7657 if g:netrw_sort_direction =~# 'n' 7658 " name: sort by name of file 7659 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options 7660 else 7661 " reverse direction sorting 7662 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options 7663 endif 7664 endif 7665 7666 " remove priority pattern prefix 7667 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e' 7668 NetrwKeepj call histdel("/",-1) 7669 7670 elseif g:netrw_sort_by =~# "^ext" 7671 " exten: sort by extension 7672 " The histdel(...,-1) calls remove the last search from the search history 7673 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/' 7674 NetrwKeepj call histdel("/",-1) 7675 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/' 7676 NetrwKeepj call histdel("/",-1) 7677 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e' 7678 NetrwKeepj call histdel("/",-1) 7679 if !g:netrw_banner || w:netrw_bannercnt < line("$") 7680 if g:netrw_sort_direction =~# 'n' 7681 " normal direction sorting 7682 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options 7683 else 7684 " reverse direction sorting 7685 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options 7686 endif 7687 endif 7688 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e' 7689 NetrwKeepj call histdel("/",-1) 7690 7691 elseif a:islocal 7692 if !g:netrw_banner || w:netrw_bannercnt < line("$") 7693 if g:netrw_sort_direction =~# 'n' 7694 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options 7695 else 7696 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options 7697 endif 7698 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e' 7699 NetrwKeepj call histdel("/",-1) 7700 endif 7701 endif 7702 7703 elseif g:netrw_sort_direction =~# 'r' 7704 if !g:netrw_banner || w:netrw_bannercnt < line('$') 7705 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt 7706 call histdel("/",-1) 7707 endif 7708 endif 7709 endif 7710 7711 " convert to wide/tree listing {{{3 7712 NetrwKeepj call s:NetrwWideListing() 7713 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir) 7714 7715 " resolve symbolic links if local and (thin or tree) 7716 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)) 7717 sil! keepp g/@$/call s:ShowLink() 7718 endif 7719 7720 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner) 7721 " place cursor on the top-left corner of the file listing 7722 exe 'sil! '.w:netrw_bannercnt 7723 sil! NetrwKeepj norm! 0 7724 else 7725 endif 7726 7727 " record previous current directory 7728 let w:netrw_prvdir= b:netrw_curdir 7729 7730 " save certain window-oriented variables into buffer-oriented variables {{{3 7731 NetrwKeepj call s:SetBufWinVars() 7732 NetrwKeepj call s:NetrwOptionsRestore("w:") 7733 7734 " set display to netrw display settings 7735 exe "setl ".g:netrw_bufsettings 7736 if g:netrw_liststyle == s:LONGLIST 7737 exe "setl ts=".(g:netrw_maxfilenamelen+1) 7738 endif 7739 " call DechoBuf(bufnr("%")) 7740 7741 if exists("s:treecurpos") 7742 NetrwKeepj call winrestview(s:treecurpos) 7743 unlet s:treecurpos 7744 endif 7745 7746 endfunction 7747 7748 " s:SetupNetrwStatusLine: {{{2 7749 function s:SetupNetrwStatusLine(statline) 7750 7751 if !exists("s:netrw_setup_statline") 7752 let s:netrw_setup_statline= 1 7753 7754 if !exists("s:netrw_users_stl") 7755 let s:netrw_users_stl= &stl 7756 endif 7757 if !exists("s:netrw_users_ls") 7758 let s:netrw_users_ls= &laststatus 7759 endif 7760 7761 " set up User9 highlighting as needed 7762 let dict={} 7763 let dict.a=[getreg('a'), getregtype('a')] 7764 redir @a 7765 try 7766 hi User9 7767 catch /^Vim\%((\a\{3,})\)\=:E411/ 7768 if &bg == "dark" 7769 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue 7770 else 7771 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue 7772 endif 7773 endtry 7774 redir END 7775 call s:RestoreRegister(dict) 7776 endif 7777 7778 " set up status line (may use User9 highlighting) 7779 " insure that windows have a statusline 7780 " make sure statusline is displayed 7781 let &l:stl=a:statline 7782 setl laststatus=2 7783 redraw 7784 7785 endfunction 7786 7787 " Remote Directory Browsing Support: {{{1 7788 7789 " s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2 7790 " This function assumes that a long listing will be received. Size, time, 7791 " and reverse sorts will be requested of the server but not otherwise 7792 " enforced here. 7793 function s:NetrwRemoteFtpCmd(path,listcmd) 7794 " sanity check: {{{3 7795 if !exists("w:netrw_method") 7796 if exists("b:netrw_method") 7797 let w:netrw_method= b:netrw_method 7798 else 7799 call netrw#msg#Notify('ERROR', '(s:NetrwRemoteFtpCmd) internal netrw error') 7800 return 7801 endif 7802 endif 7803 7804 " WinXX ftp uses unix style input, so set ff to unix " {{{3 7805 let ffkeep= &ff 7806 setl ma ff=unix noro 7807 7808 " clear off any older non-banner lines " {{{3 7809 " note that w:netrw_bannercnt indexes the line after the banner 7810 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _" 7811 7812 "......................................... 7813 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3 7814 " ftp + <.netrc>: Method #2 7815 if a:path != "" 7816 NetrwKeepj put ='cd \"'.a:path.'\"' 7817 endif 7818 if exists("g:netrw_ftpextracmd") 7819 NetrwKeepj put =g:netrw_ftpextracmd 7820 endif 7821 NetrwKeepj call setline(line("$")+1,a:listcmd) 7822 if exists("g:netrw_port") && g:netrw_port != "" 7823 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1)." ".netrw#os#Escape(g:netrw_port,1) 7824 else 7825 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".netrw#os#Escape(g:netrw_machine,1) 7826 endif 7827 7828 "......................................... 7829 elseif w:netrw_method == 3 " {{{3 7830 " ftp + machine,id,passwd,filename: Method #3 7831 setl ff=unix 7832 if exists("g:netrw_port") && g:netrw_port != "" 7833 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 7834 else 7835 NetrwKeepj put ='open '.g:netrw_machine 7836 endif 7837 7838 " handle userid and password 7839 let host= substitute(g:netrw_machine,'\..*$','','') 7840 if exists("s:netrw_hup") && exists("s:netrw_hup[host]") 7841 call netrw#NetUserPass("ftp:".host) 7842 endif 7843 if exists("g:netrw_uid") && g:netrw_uid != "" 7844 if exists("g:netrw_ftp") && g:netrw_ftp == 1 7845 NetrwKeepj put =g:netrw_uid 7846 if exists("s:netrw_passwd") && s:netrw_passwd != "" 7847 NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 7848 endif 7849 elseif exists("s:netrw_passwd") 7850 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 7851 endif 7852 endif 7853 7854 if a:path != "" 7855 NetrwKeepj put ='cd \"'.a:path.'\"' 7856 endif 7857 if exists("g:netrw_ftpextracmd") 7858 NetrwKeepj put =g:netrw_ftpextracmd 7859 endif 7860 NetrwKeepj call setline(line("$")+1,a:listcmd) 7861 7862 " perform ftp: 7863 " -i : turns off interactive prompting from ftp 7864 " -n unix : DON'T use <.netrc>, even though it exists 7865 " -n win32: quit being obnoxious about password 7866 if exists("w:netrw_bannercnt") 7867 call netrw#os#Execute(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options) 7868 endif 7869 7870 "......................................... 7871 elseif w:netrw_method == 9 " {{{3 7872 " sftp username@machine: Method #9 7873 " s:netrw_sftp_cmd 7874 setl ff=unix 7875 7876 " restore settings 7877 let &l:ff= ffkeep 7878 return 7879 7880 "......................................... 7881 else " {{{3 7882 call netrw#msg#Notify('WARNING', printf('unable to comply with your request<%s>', bufname("%"))) 7883 endif 7884 7885 " cleanup for Windows " {{{3 7886 if has("win32") 7887 sil! NetrwKeepj %s/\r$//e 7888 NetrwKeepj call histdel("/",-1) 7889 endif 7890 if a:listcmd == "dir" 7891 " infer directory/link based on the file permission string 7892 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e 7893 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e 7894 NetrwKeepj call histdel("/",-1) 7895 NetrwKeepj call histdel("/",-1) 7896 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST) 7897 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e' 7898 NetrwKeepj call histdel("/",-1) 7899 endif 7900 endif 7901 7902 " ftp's listing doesn't seem to include ./ or ../ " {{{3 7903 if !search('^\.\/$\|\s\.\/$','wn') 7904 exe 'NetrwKeepj '.w:netrw_bannercnt 7905 NetrwKeepj put ='./' 7906 endif 7907 if !search('^\.\.\/$\|\s\.\.\/$','wn') 7908 exe 'NetrwKeepj '.w:netrw_bannercnt 7909 NetrwKeepj put ='../' 7910 endif 7911 7912 " restore settings " {{{3 7913 let &l:ff= ffkeep 7914 endfunction 7915 7916 " s:NetrwRemoteListing: {{{2 7917 function s:NetrwRemoteListing() 7918 7919 if !exists("w:netrw_bannercnt") && exists("s:bannercnt") 7920 let w:netrw_bannercnt= s:bannercnt 7921 endif 7922 if !exists("w:netrw_bannercnt") && exists("b:bannercnt") 7923 let w:netrw_bannercnt= b:bannercnt 7924 endif 7925 7926 call s:RemotePathAnalysis(b:netrw_curdir) 7927 7928 " sanity check: 7929 if exists("b:netrw_method") && b:netrw_method =~ '[235]' 7930 if !executable("ftp") 7931 call netrw#msg#Notify('ERROR', "this system doesn't support remote directory listing via ftp") 7932 call s:NetrwOptionsRestore("w:") 7933 return -1 7934 endif 7935 7936 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == '' 7937 if g:netrw_list_cmd == "" 7938 call netrw#msg#Notify('ERROR', printf('your g:netrw_list_cmd is empty; perhaps %s is not executable on your system', g:netrw_ssh_cmd)) 7939 else 7940 call netrw#msg#Notify('ERROR', "this system doesn't support remote directory listing via ".g:netrw_list_cmd) 7941 endif 7942 7943 NetrwKeepj call s:NetrwOptionsRestore("w:") 7944 return -1 7945 endif " (remote handling sanity check) 7946 7947 if exists("b:netrw_method") 7948 let w:netrw_method= b:netrw_method 7949 endif 7950 7951 if s:method == "ftp" 7952 " use ftp to get remote file listing {{{3 7953 let s:method = "ftp" 7954 let listcmd = g:netrw_ftp_list_cmd 7955 if g:netrw_sort_by =~# '^t' 7956 let listcmd= g:netrw_ftp_timelist_cmd 7957 elseif g:netrw_sort_by =~# '^s' 7958 let listcmd= g:netrw_ftp_sizelist_cmd 7959 endif 7960 call s:NetrwRemoteFtpCmd(s:path,listcmd) 7961 7962 " report on missing file or directory messages 7963 if search('[Nn]o such file or directory\|Failed to change directory') 7964 let mesg= getline(".") 7965 if exists("w:netrw_bannercnt") 7966 setl ma 7967 exe w:netrw_bannercnt.",$d _" 7968 setl noma 7969 endif 7970 NetrwKeepj call s:NetrwOptionsRestore("w:") 7971 call netrw#msg#Notify('WARNING', mesg) 7972 return -1 7973 endif 7974 7975 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST) 7976 " shorten the listing 7977 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt 7978 7979 " cleanup 7980 if g:netrw_ftp_browse_reject != "" 7981 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d" 7982 NetrwKeepj call histdel("/",-1) 7983 endif 7984 sil! NetrwKeepj %s/\r$//e 7985 NetrwKeepj call histdel("/",-1) 7986 7987 " if there's no ../ listed, then put ../ in 7988 let line1= line(".") 7989 exe "sil! NetrwKeepj ".w:netrw_bannercnt 7990 let line2= search('\.\.\/\%(\s\|$\)','cnW') 7991 if line2 == 0 7992 sil! NetrwKeepj put='../' 7993 endif 7994 exe "sil! NetrwKeepj ".line1 7995 sil! NetrwKeepj norm! 0 7996 7997 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup 7998 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//' 7999 NetrwKeepj call histdel("/",-1) 8000 else " normal ftp cleanup 8001 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' 8002 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e' 8003 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e' 8004 NetrwKeepj call histdel("/",-1) 8005 NetrwKeepj call histdel("/",-1) 8006 NetrwKeepj call histdel("/",-1) 8007 endif 8008 endif 8009 8010 else 8011 " use ssh to get remote file listing {{{3 8012 let listcmd= s:MakeSshCmd(g:netrw_list_cmd) 8013 if g:netrw_scp_cmd =~ '^pscp' 8014 exe "NetrwKeepj r! ".listcmd.netrw#os#Escape(s:path, 1) 8015 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like 8016 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d 8017 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e 8018 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e 8019 NetrwKeepj call histdel("/",-1) 8020 NetrwKeepj call histdel("/",-1) 8021 NetrwKeepj call histdel("/",-1) 8022 if g:netrw_liststyle != s:LONGLIST 8023 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e 8024 NetrwKeepj call histdel("/",-1) 8025 endif 8026 else 8027 if s:path == "" 8028 exe "NetrwKeepj keepalt r! ".listcmd 8029 else 8030 exe "NetrwKeepj keepalt r! ".listcmd.' '.netrw#os#Escape(fnameescape(s:path),1) 8031 endif 8032 endif 8033 8034 " cleanup 8035 if g:netrw_ssh_browse_reject != "" 8036 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d" 8037 NetrwKeepj call histdel("/",-1) 8038 endif 8039 endif 8040 8041 if w:netrw_liststyle == s:LONGLIST 8042 " do a long listing; these substitutions need to be done prior to sorting {{{3 8043 8044 if s:method == "ftp" 8045 " cleanup 8046 exe "sil! NetrwKeepj ".w:netrw_bannercnt 8047 while getline('.') =~# g:netrw_ftp_browse_reject 8048 sil! NetrwKeepj d 8049 endwhile 8050 " if there's no ../ listed, then put ../ in 8051 let line1= line(".") 8052 sil! NetrwKeepj 1 8053 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W') 8054 let line2= line(".") 8055 if line2 == 0 8056 if b:netrw_curdir != '/' 8057 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'" 8058 endif 8059 endif 8060 exe "sil! NetrwKeepj ".line1 8061 sil! NetrwKeepj norm! 0 8062 endif 8063 8064 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup 8065 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/' 8066 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") 8067 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e' 8068 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e' 8069 exe 'sil NetrwKeepj '.w:netrw_bannercnt 8070 NetrwKeepj call histdel("/",-1) 8071 NetrwKeepj call histdel("/",-1) 8072 NetrwKeepj call histdel("/",-1) 8073 endif 8074 endif 8075 8076 8077 return 0 8078 endfunction 8079 8080 " s:NetrwRemoteRm: remove/delete a remote file or directory {{{2 8081 function s:NetrwRemoteRm(usrhost,path) range 8082 let svpos= winsaveview() 8083 8084 let all= 0 8085 if exists("s:netrwmarkfilelist_{bufnr('%')}") 8086 " remove all marked files 8087 for fname in s:netrwmarkfilelist_{bufnr("%")} 8088 let ok= s:NetrwRemoteRmFile(a:path,fname,all) 8089 if ok =~# 'q\%[uit]' 8090 break 8091 elseif ok =~# 'a\%[ll]' 8092 let all= 1 8093 endif 8094 endfor 8095 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) 8096 8097 else 8098 " remove files specified by range 8099 8100 " preparation for removing multiple files/directories 8101 let keepsol = &l:sol 8102 setl nosol 8103 let ctr = a:firstline 8104 8105 " remove multiple files and directories 8106 while ctr <= a:lastline 8107 exe "NetrwKeepj ".ctr 8108 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all) 8109 if ok =~# 'q\%[uit]' 8110 break 8111 elseif ok =~# 'a\%[ll]' 8112 let all= 1 8113 endif 8114 let ctr= ctr + 1 8115 endwhile 8116 let &l:sol = keepsol 8117 endif 8118 8119 " refresh the (remote) directory listing 8120 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 8121 NetrwKeepj call winrestview(svpos) 8122 endfunction 8123 8124 " s:NetrwRemoteRmFile: {{{2 8125 function s:NetrwRemoteRmFile(path,rmfile,all) 8126 8127 let all= a:all 8128 let ok = "" 8129 8130 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$') 8131 " attempt to remove file 8132 if !all 8133 echohl Statement 8134 call inputsave() 8135 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") 8136 call inputrestore() 8137 echohl NONE 8138 if ok == "" 8139 let ok="no" 8140 endif 8141 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') 8142 if ok =~# 'a\%[ll]' 8143 let all= 1 8144 endif 8145 endif 8146 8147 if all || ok =~# 'y\%[es]' || ok == "" 8148 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) 8149 let path= a:path 8150 if path =~ '^\a\{3,}://' 8151 let path= substitute(path,'^\a\{3,}://[^/]\+/','','') 8152 endif 8153 sil! NetrwKeepj .,$d _ 8154 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"') 8155 else 8156 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd) 8157 if !exists("b:netrw_curdir") 8158 call netrw#msg#Notify('ERROR', "for some reason b:netrw_curdir doesn't exist!") 8159 let ok="q" 8160 else 8161 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','') 8162 if remotedir != "" 8163 let netrw_rm_cmd= netrw_rm_cmd." ".netrw#os#Escape(fnameescape(remotedir.a:rmfile)) 8164 else 8165 let netrw_rm_cmd= netrw_rm_cmd." ".netrw#os#Escape(fnameescape(a:rmfile)) 8166 endif 8167 let ret= system(netrw_rm_cmd) 8168 if v:shell_error != 0 8169 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir 8170 call netrw#msg#Notify('ERROR', printf("remove failed; perhaps due to vim's current directory<%s> not matching netrw's (%s) (see :help netrw-cd)", getcwd(), b:netrw_curdir)) 8171 else 8172 call netrw#msg#Notify('WARNING', printf('cmd<%s> failed', netrw_rm_cmd)) 8173 endif 8174 elseif ret != 0 8175 call netrw#msg#Notify('WARNING', printf('cmd<%s> failed', netrw_rm_cmd)) 8176 endif 8177 endif 8178 endif 8179 elseif ok =~# 'q\%[uit]' 8180 endif 8181 8182 else 8183 " attempt to remove directory 8184 if !all 8185 call inputsave() 8186 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ") 8187 call inputrestore() 8188 if ok == "" 8189 let ok="no" 8190 endif 8191 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e') 8192 if ok =~# 'a\%[ll]' 8193 let all= 1 8194 endif 8195 endif 8196 8197 if all || ok =~# 'y\%[es]' || ok == "" 8198 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) 8199 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile) 8200 else 8201 let rmfile = substitute(a:path.a:rmfile,'/$','','') 8202 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#fs#WinPath(g:netrw_rmdir_cmd)).' '.netrw#os#Escape(netrw#fs#WinPath(rmfile)) 8203 let ret= system(netrw_rmdir_cmd) 8204 8205 if v:shell_error != 0 8206 let netrw_rmf_cmd= s:MakeSshCmd(netrw#fs#WinPath(g:netrw_rmf_cmd)).' '.netrw#os#Escape(netrw#fs#WinPath(substitute(rmfile,'[\/]$','','e'))) 8207 let ret= system(netrw_rmf_cmd) 8208 8209 if v:shell_error != 0 8210 call netrw#msg#Notify('ERROR', printf('unable to remove directory<%s> -- is it empty?', rmfile)) 8211 endif 8212 endif 8213 endif 8214 8215 elseif ok =~# 'q\%[uit]' 8216 endif 8217 endif 8218 8219 return ok 8220 endfunction 8221 8222 " s:NetrwRemoteRename: rename a remote file or directory {{{2 8223 function s:NetrwRemoteRename(usrhost,path) range 8224 8225 " preparation for removing multiple files/directories 8226 let svpos = winsaveview() 8227 let ctr = a:firstline 8228 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd) 8229 8230 " rename files given by the markfilelist 8231 if exists("s:netrwmarkfilelist_{bufnr('%')}") 8232 for oldname in s:netrwmarkfilelist_{bufnr("%")} 8233 if exists("subfrom") 8234 let newname= substitute(oldname,subfrom,subto,'') 8235 else 8236 call inputsave() 8237 let newname= input("Moving ".oldname." to : ",oldname) 8238 call inputrestore() 8239 if newname =~ '^s/' 8240 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','') 8241 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','') 8242 let newname = substitute(oldname,subfrom,subto,'') 8243 endif 8244 endif 8245 8246 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) 8247 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname) 8248 else 8249 let oldname= netrw#os#Escape(a:path.oldname) 8250 let newname= netrw#os#Escape(a:path.newname) 8251 let ret = system(netrw#fs#WinPath(rename_cmd).' '.oldname.' '.newname) 8252 endif 8253 8254 endfor 8255 call s:NetrwUnMarkFile(1) 8256 8257 else 8258 8259 " attempt to rename files/directories 8260 let keepsol= &l:sol 8261 setl nosol 8262 while ctr <= a:lastline 8263 exe "NetrwKeepj ".ctr 8264 8265 let oldname= s:NetrwGetWord() 8266 8267 call inputsave() 8268 let newname= input("Moving ".oldname." to : ",oldname) 8269 call inputrestore() 8270 8271 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3) 8272 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname) 8273 else 8274 let oldname= netrw#os#Escape(a:path.oldname) 8275 let newname= netrw#os#Escape(a:path.newname) 8276 let ret = system(netrw#fs#WinPath(rename_cmd).' '.oldname.' '.newname) 8277 endif 8278 8279 let ctr= ctr + 1 8280 endwhile 8281 let &l:sol= keepsol 8282 endif 8283 8284 " refresh the directory 8285 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 8286 NetrwKeepj call winrestview(svpos) 8287 endfunction 8288 8289 " Local Directory Browsing Support: {{{1 8290 8291 " netrw#FileUrlEdit: handles editing file://* files {{{2 8292 " Should accept: file://localhost/etc/fstab 8293 " file:///etc/fstab 8294 " file:///c:/WINDOWS/clock.avi 8295 " file:///c|/WINDOWS/clock.avi 8296 " file://localhost/c:/WINDOWS/clock.avi 8297 " file://localhost/c|/WINDOWS/clock.avi 8298 " file://c:/foo.txt 8299 " file:///c:/foo.txt 8300 " and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value 8301 function netrw#FileUrlEdit(fname) 8302 let fname = a:fname 8303 if fname =~ '^file://localhost/' 8304 let fname= substitute(fname,'^file://localhost/','file:///','') 8305 endif 8306 if has("win32") 8307 if fname =~ '^file:///\=\a[|:]/' 8308 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','') 8309 endif 8310 endif 8311 let fname2396 = netrw#RFC2396(fname) 8312 let fname2396e= fnameescape(fname2396) 8313 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"") 8314 if has("win32") 8315 if plainfname =~ '^/\+\a:' 8316 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','') 8317 endif 8318 endif 8319 8320 exe "sil doau BufReadPre ".fname2396e 8321 exe 'NetrwKeepj keepalt edit '. fnameescape(plainfname) 8322 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname) 8323 8324 exe "sil doau BufReadPost ".fname2396e 8325 endfunction 8326 8327 " netrw#LocalBrowseCheck: {{{2 8328 function netrw#LocalBrowseCheck(dirname) 8329 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(), 8330 " and by <cr> when atop a listed file/directory (via a buffer-local map) 8331 " 8332 " unfortunate interaction -- split window debugging can't be used here, must use 8333 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers 8334 " another call to LocalBrowseCheck() when attempts to write 8335 " to the DBG buffer are made. 8336 " 8337 " The &ft == "netrw" test was installed because the BufEnter event 8338 " would hit when re-entering netrw windows, creating unexpected 8339 " refreshes (and would do so in the middle of NetrwSaveOptions(), too) 8340 " getting E930: Cannot use :redir inside execute 8341 8342 let ykeep= @@ 8343 if isdirectory(s:NetrwFile(a:dirname)) 8344 8345 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1 8346 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8347 8348 elseif &ft == "netrw" && line("$") == 1 8349 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8350 8351 elseif exists("s:treeforceredraw") 8352 unlet s:treeforceredraw 8353 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8354 endif 8355 return 8356 endif 8357 8358 " The following code wipes out currently unused netrw buffers 8359 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected) 8360 " AND IF the listing style is not a tree listing 8361 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST 8362 let ibuf = 1 8363 let buflast = bufnr("$") 8364 while ibuf <= buflast 8365 if bufwinnr(ibuf) == -1 && !empty(bufname(ibuf)) && isdirectory(s:NetrwFile(bufname(ibuf))) 8366 exe "sil! keepj keepalt ".ibuf."bw!" 8367 endif 8368 let ibuf= ibuf + 1 8369 endwhile 8370 endif 8371 let @@= ykeep 8372 " not a directory, ignore it 8373 endfunction 8374 8375 " s:LocalBrowseRefresh: this function is called after a user has {{{2 8376 " performed any shell command. The idea is to cause all local-browsing 8377 " buffers to be refreshed after a user has executed some shell command, 8378 " on the chance that s/he removed/created a file/directory with it. 8379 function s:LocalBrowseRefresh() 8380 " determine which buffers currently reside in a tab 8381 if !exists("s:netrw_browselist") 8382 return 8383 endif 8384 if !exists("w:netrw_bannercnt") 8385 return 8386 endif 8387 if !empty(getcmdwintype()) 8388 " cannot move away from cmdline window, see :h E11 8389 return 8390 endif 8391 if exists("s:netrw_events") && s:netrw_events == 1 8392 " s:LocalFastBrowser gets called (indirectly) from a 8393 let s:netrw_events= 2 8394 return 8395 endif 8396 let itab = 1 8397 let buftablist = [] 8398 let ykeep = @@ 8399 while itab <= tabpagenr("$") 8400 let buftablist = buftablist + tabpagebuflist() 8401 let itab = itab + 1 8402 sil! tabn 8403 endwhile 8404 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers): 8405 " | refresh any netrw window 8406 " | wipe out any non-displaying netrw buffer 8407 let curwinid = win_getid(winnr()) 8408 let ibl = 0 8409 for ibuf in s:netrw_browselist 8410 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1 8411 " wipe out any non-displaying netrw buffer 8412 " (ibuf not shown in a current window AND 8413 " ibuf not in any tab) 8414 exe "sil! keepj bd ".fnameescape(ibuf) 8415 call remove(s:netrw_browselist,ibl) 8416 continue 8417 elseif index(tabpagebuflist(),ibuf) != -1 8418 " refresh any netrw buffer 8419 exe bufwinnr(ibuf)."wincmd w" 8420 if getline(".") =~# 'Quick Help' 8421 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp 8422 " (counteracts s:NetrwBrowseChgDir()'s incrementing) 8423 let g:netrw_quickhelp= g:netrw_quickhelp - 1 8424 endif 8425 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 8426 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop) 8427 endif 8428 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8429 endif 8430 let ibl= ibl + 1 8431 endfor 8432 call win_gotoid(curwinid) 8433 let @@= ykeep 8434 endfunction 8435 8436 " s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2 8437 " 8438 " g:netrw_ Directory Is 8439 " fastbrowse Local Remote 8440 " slow 0 D D D=Deleting a buffer implies it will not be re-used (slow) 8441 " med 1 D H H=Hiding a buffer implies it may be re-used (fast) 8442 " fast 2 H H 8443 " 8444 " Deleting a buffer means that it will be re-loaded when examined, hence "slow". 8445 " Hiding a buffer means that it will be re-used when examined, hence "fast". 8446 " (re-using a buffer may not be as accurate) 8447 " 8448 " s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing 8449 " =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing. 8450 " BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event. 8451 " If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored. 8452 " =2: autocmds installed (doesn't ignore any FocusGained events) 8453 function s:LocalFastBrowser() 8454 8455 " initialize browselist, a list of buffer numbers that the local browser has used 8456 if !exists("s:netrw_browselist") 8457 let s:netrw_browselist= [] 8458 endif 8459 8460 " append current buffer to fastbrowse list 8461 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1] 8462 call add(s:netrw_browselist,bufnr("%")) 8463 endif 8464 8465 " enable autocmd events to handle refreshing/removing local browser buffers 8466 " If local browse buffer is currently showing: refresh it 8467 " If local browse buffer is currently hidden : wipe it 8468 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing 8469 " =1 : medium speed, re-use directory listing for remote only 8470 " =2 : fast speed, always re-use directory listing when possible 8471 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events") 8472 let s:netrw_events= 1 8473 augroup AuNetrwEvent 8474 au! 8475 if has("win32") 8476 au ShellCmdPost * call s:LocalBrowseRefresh() 8477 else 8478 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh() 8479 endif 8480 augroup END 8481 8482 " user must have changed fastbrowse to its fast setting, so remove 8483 " the associated autocmd events 8484 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events") 8485 unlet s:netrw_events 8486 augroup AuNetrwEvent 8487 au! 8488 augroup END 8489 augroup! AuNetrwEvent 8490 endif 8491 endfunction 8492 8493 function s:NetrwLocalListingList(dirname,setmaxfilenamelen) 8494 " get the list of files contained in the current directory 8495 let dirname = a:dirname 8496 let dirnamelen = strlen(dirname) 8497 let filelist = map(['.', '..'] + readdir(dirname), 'netrw#fs#PathJoin(dirname, v:val)') 8498 8499 if g:netrw_cygwin == 0 && has("win32") 8500 elseif index(filelist,'..') == -1 && dirname !~ '/' 8501 " include ../ in the glob() entry if its missing 8502 let filelist= filelist+[netrw#fs#ComposePath(dirname,"../")] 8503 endif 8504 8505 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0) 8506 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")') 8507 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1 8508 endif 8509 8510 let resultfilelist = [] 8511 for filename in filelist 8512 8513 let ftype = getftype(filename) 8514 if ftype ==# "link" 8515 " indicate a symbolic link 8516 let pfile= filename."@" 8517 8518 elseif ftype ==# "socket" 8519 " indicate a socket 8520 let pfile= filename."=" 8521 8522 elseif ftype ==# "fifo" 8523 " indicate a fifo 8524 let pfile= filename."|" 8525 8526 elseif ftype ==# "dir" 8527 " indicate a directory 8528 let pfile= filename."/" 8529 8530 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename)) 8531 if has("win32") 8532 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$' 8533 " indicate an executable 8534 let pfile= filename."*" 8535 else 8536 " normal file 8537 let pfile= filename 8538 endif 8539 elseif executable(filename) 8540 " indicate an executable 8541 let pfile= filename."*" 8542 else 8543 " normal file 8544 let pfile= filename 8545 endif 8546 8547 else 8548 " normal file 8549 let pfile= filename 8550 endif 8551 8552 if pfile =~ '//$' 8553 let pfile= substitute(pfile,'//$','/','e') 8554 endif 8555 let pfile= strpart(pfile,dirnamelen) 8556 let pfile= substitute(pfile,'^[/\\]','','e') 8557 8558 if w:netrw_liststyle == s:LONGLIST 8559 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile) 8560 let sz = getfsize(filename) 8561 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen) 8562 let szlen = (szlen > 0) ? szlen : 0 8563 8564 if g:netrw_sizestyle =~# "[hH]" 8565 let sz= s:NetrwHumanReadable(sz) 8566 endif 8567 let fsz = printf("%".szlen."S",sz) 8568 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename)) 8569 endif 8570 8571 if g:netrw_sort_by =~# "^t" 8572 " sort by time (handles time up to 1 quintillion seconds, US) 8573 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time. 8574 let t = getftime(filename) 8575 let ft = printf("%018d",t) 8576 let ftpfile= ft.'/'.pfile 8577 let resultfilelist += [ftpfile] 8578 8579 elseif g:netrw_sort_by =~ "^s" 8580 " sort by size (handles file sizes up to 1 quintillion bytes, US) 8581 let sz = getfsize(filename) 8582 let fsz = printf("%018d",sz) 8583 let fszpfile= fsz.'/'.pfile 8584 let resultfilelist += [fszpfile] 8585 8586 else 8587 " sort by name 8588 let resultfilelist += [pfile] 8589 endif 8590 endfor 8591 8592 return resultfilelist 8593 endfunction 8594 8595 " s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2 8596 function s:NetrwLocalExecute(cmd) 8597 let ykeep= @@ 8598 " sanity check 8599 if !executable(a:cmd) 8600 call netrw#msg#Notify('ERROR', printf("the file<%s> is not executable!", a:cmd)) 8601 let @@= ykeep 8602 return 8603 endif 8604 8605 let optargs= input(":!".a:cmd,"","file") 8606 let result= system(a:cmd.optargs) 8607 8608 " strip any ansi escape sequences off 8609 let result = substitute(result,"\e\\[[0-9;]*m","","g") 8610 8611 " show user the result(s) 8612 echomsg result 8613 let @@= ykeep 8614 8615 endfunction 8616 8617 " s:NetrwLocalRename: rename a local file or directory {{{2 8618 function s:NetrwLocalRename(path) range 8619 8620 if !exists("w:netrw_bannercnt") 8621 let w:netrw_bannercnt= b:netrw_bannercnt 8622 endif 8623 8624 " preparation for removing multiple files/directories 8625 let ykeep = @@ 8626 let ctr = a:firstline 8627 let svpos = winsaveview() 8628 let all = 0 8629 8630 " rename files given by the markfilelist 8631 if exists("s:netrwmarkfilelist_{bufnr('%')}") 8632 for oldname in s:netrwmarkfilelist_{bufnr("%")} 8633 if exists("subfrom") 8634 let newname= substitute(oldname,subfrom,subto,'') 8635 else 8636 call inputsave() 8637 let newname= input("Moving ".oldname." to : ",oldname,"file") 8638 call inputrestore() 8639 if newname =~ '' 8640 " two ctrl-x's : ignore all of string preceding the ctrl-x's 8641 let newname = substitute(newname,'^.*','','') 8642 elseif newname =~ '' 8643 " one ctrl-x : ignore portion of string preceding ctrl-x but after last / 8644 let newname = substitute(newname,'[^/]*','','') 8645 endif 8646 if newname =~ '^s/' 8647 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','') 8648 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','') 8649 let newname = substitute(oldname,subfrom,subto,'') 8650 endif 8651 endif 8652 if !all && filereadable(newname) 8653 call inputsave() 8654 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ") 8655 call inputrestore() 8656 if response == "all" 8657 let all= 1 8658 elseif response != "y" && response != "yes" 8659 " refresh the directory 8660 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8661 NetrwKeepj call winrestview(svpos) 8662 let @@= ykeep 8663 return 8664 endif 8665 endif 8666 call rename(oldname,newname) 8667 endfor 8668 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) 8669 8670 else 8671 8672 " attempt to rename files/directories 8673 while ctr <= a:lastline 8674 exe "NetrwKeepj ".ctr 8675 8676 " sanity checks 8677 if line(".") < w:netrw_bannercnt 8678 let ctr= ctr + 1 8679 continue 8680 endif 8681 let curword= s:NetrwGetWord() 8682 if curword == "./" || curword == "../" 8683 let ctr= ctr + 1 8684 continue 8685 endif 8686 8687 NetrwKeepj norm! 0 8688 let reset_ssl = 0 8689 if exists('+shellslash') && !&ssl 8690 let reset_ssl = 1 8691 set ssl 8692 endif 8693 " Consistently use / as directory separator 8694 let oldname= netrw#fs#ComposePath(a:path,curword) 8695 if reset_ssl 8696 set nossl 8697 endif 8698 8699 call inputsave() 8700 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e')) 8701 call inputrestore() 8702 8703 call rename(oldname,newname) 8704 let ctr= ctr + 1 8705 endwhile 8706 endif 8707 8708 " refresh the directory 8709 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8710 NetrwKeepj call winrestview(svpos) 8711 let @@= ykeep 8712 endfunction 8713 8714 " s:NetrwLocalRm: {{{2 8715 function s:NetrwLocalRm(path) range 8716 if !exists("w:netrw_bannercnt") 8717 let w:netrw_bannercnt = b:netrw_bannercnt 8718 endif 8719 8720 " preparation for removing multiple files/directories 8721 let ykeep = @@ 8722 let ret = 0 8723 let all = 0 8724 let svpos = winsaveview() 8725 8726 if exists("s:netrwmarkfilelist_{bufnr('%')}") 8727 " remove all marked files 8728 for fname in s:netrwmarkfilelist_{bufnr("%")} 8729 let ok = s:NetrwLocalRmFile(a:path, fname, all) 8730 if ok =~# '^a\%[ll]$' 8731 let all = 1 8732 elseif ok =~# "n\%[o]" 8733 break 8734 endif 8735 endfor 8736 call s:NetrwUnMarkFile(1) 8737 8738 else 8739 " remove (multiple) files and directories 8740 8741 let keepsol = &l:sol 8742 setl nosol 8743 let ctr = a:firstline 8744 while ctr <= a:lastline 8745 exe "NetrwKeepj ".ctr 8746 8747 " sanity checks 8748 if line(".") < w:netrw_bannercnt 8749 let ctr = ctr + 1 8750 continue 8751 endif 8752 8753 let curword = s:NetrwGetWord() 8754 if curword == "./" || curword == "../" 8755 let ctr = ctr + 1 8756 continue 8757 endif 8758 8759 let ok = s:NetrwLocalRmFile(a:path, curword, all) 8760 if ok =~# '^a\%[ll]$' 8761 let all = 1 8762 elseif ok =~# "n\%[o]" 8763 break 8764 endif 8765 8766 let ctr = ctr + 1 8767 endwhile 8768 8769 let &l:sol = keepsol 8770 endif 8771 8772 " refresh the directory 8773 if bufname("%") != "NetrwMessage" 8774 NetrwKeepj call s:NetrwRefresh(1, s:NetrwBrowseChgDir(1, './', 0)) 8775 NetrwKeepj call winrestview(svpos) 8776 endif 8777 8778 let @@= ykeep 8779 endfunction 8780 8781 " s:NetrwLocalRmFile: remove file fname given the path {{{2 8782 " Give confirmation prompt unless all==1 8783 function s:NetrwLocalRmFile(path, fname, all) 8784 let all = a:all 8785 let ok = "" 8786 let dir = 0 8787 NetrwKeepj norm! 0 8788 let rmfile = s:NetrwFile(netrw#fs#ComposePath(a:path, escape(a:fname, '\\')))->fnamemodify(':.') 8789 8790 " if not a directory 8791 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$') 8792 let msg = "Confirm deletion of file <%s> [{y(es)},n(o),a(ll)]: " 8793 else 8794 let msg = "Confirm *recursive* deletion of directory <%s> [{y(es)},n(o),a(ll)]: " 8795 let dir = 1 8796 endif 8797 8798 " Ask confirmation 8799 if !all 8800 echohl Statement 8801 call inputsave() 8802 let ok = input(printf(msg, rmfile)) 8803 call inputrestore() 8804 echohl NONE 8805 if ok =~# '^a\%[ll]$' || ok =~# '^y\%[es]$' 8806 let all = 1 8807 else 8808 let ok = 'no' 8809 endif 8810 endif 8811 8812 if !dir && (all || empty(ok)) 8813 " This works because delete return 0 if successful 8814 if netrw#fs#Remove(rmfile) 8815 call netrw#msg#Notify('ERROR', printf("unable to delete <%s>!", rmfile)) 8816 else 8817 " Remove file only if there are no pending changes 8818 execute printf('silent! bwipeout %s', fnameescape(rmfile)) 8819 endif 8820 8821 elseif dir && (all || empty(ok)) 8822 " Remove trailing / 8823 let rmfile = substitute(rmfile, '[\/]$', '', 'e') 8824 if delete(rmfile, "rf") 8825 call netrw#msg#Notify('ERROR', printf("unable to delete directory <%s>!", rmfile)) 8826 endif 8827 8828 endif 8829 8830 return ok 8831 endfunction 8832 8833 " Support Functions: {{{1 8834 8835 " netrw#Call: allows user-specified mappings to call internal netrw functions {{{2 8836 function netrw#Call(funcname,...) 8837 return call("s:".a:funcname,a:000) 8838 endfunction 8839 8840 " netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2 8841 " I expect this function to be used in 8842 " :PChkAssert netrw#Expose("netrwmarkfilelist") 8843 " for example. 8844 function netrw#Expose(varname) 8845 if exists("s:".a:varname) 8846 exe "let retval= s:".a:varname 8847 if exists("g:netrw_pchk") 8848 if type(retval) == 3 8849 let retval = copy(retval) 8850 let i = 0 8851 while i < len(retval) 8852 let retval[i]= substitute(retval[i],expand("$HOME"),'~','') 8853 let i = i + 1 8854 endwhile 8855 endif 8856 return string(retval) 8857 else 8858 endif 8859 else 8860 let retval= "n/a" 8861 endif 8862 8863 return retval 8864 endfunction 8865 8866 " netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2 8867 function netrw#Modify(varname,newvalue) 8868 exe "let s:".a:varname."= ".string(a:newvalue) 8869 endfunction 8870 8871 " netrw#RFC2396: converts %xx into characters {{{2 8872 function netrw#RFC2396(fname) 8873 return substitute(a:fname, '%\(\x\x\)', '\=printf("%c","0x".submatch(1))', 'ge') 8874 endfunction 8875 8876 " netrw#UserMaps: supports user-specified maps {{{2 8877 " see :help function() 8878 " 8879 " g:Netrw_UserMaps is a List with members such as: 8880 " [[keymap sequence, function reference],...] 8881 " 8882 " The referenced function may return a string, 8883 " refresh : refresh the display 8884 " -other- : this string will be executed 8885 " or it may return a List of strings. 8886 " 8887 " Each keymap-sequence will be set up with a nnoremap 8888 " to invoke netrw#UserMaps(a:islocal). 8889 " Related functions: 8890 " netrw#Expose(varname) -- see s:varname variables 8891 " netrw#Modify(varname,newvalue) -- modify value of s:varname variable 8892 " netrw#Call(funcname,...) -- call internal netrw function with optional arguments 8893 function netrw#UserMaps(islocal) 8894 8895 " set up usermaplist 8896 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3 8897 for umap in g:Netrw_UserMaps 8898 " if umap[0] is a string and umap[1] is a string holding a function name 8899 if type(umap[0]) == 1 && type(umap[1]) == 1 8900 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>" 8901 else 8902 call netrw#msg#Notify('WARNING', printf('ignoring usermap <%s> -- not a [string,funcref] entry', string(umap[0]))) 8903 endif 8904 endfor 8905 endif 8906 endfunction 8907 8908 " s:NetrwBadd: adds marked files to buffer list or vice versa {{{2 8909 " cb : bl2mf=0 add marked files to buffer list 8910 " cB : bl2mf=1 use bufferlist to mark files 8911 " (mnemonic: cb = copy (marked files) to buffer list) 8912 function s:NetrwBadd(islocal,bl2mf) 8913 if a:bl2mf 8914 " cB: add buffer list to marked files 8915 redir => bufl 8916 ls 8917 redir END 8918 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')') 8919 for fname in bufl 8920 call s:NetrwMarkFile(a:islocal,fname) 8921 endfor 8922 else 8923 " cb: add marked files to buffer list 8924 for fname in s:netrwmarkfilelist_{bufnr("%")} 8925 exe "badd ".fnameescape(fname) 8926 endfor 8927 let curbufnr = bufnr("%") 8928 let curdir = s:NetrwGetCurdir(a:islocal) 8929 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer 8930 endif 8931 endfunction 8932 8933 " s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2 8934 " Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark() 8935 function s:DeleteBookmark(fname) 8936 call s:MergeBookmarks() 8937 8938 if exists("g:netrw_bookmarklist") 8939 let indx= index(g:netrw_bookmarklist,a:fname) 8940 if indx == -1 8941 let indx= 0 8942 while indx < len(g:netrw_bookmarklist) 8943 if g:netrw_bookmarklist[indx] =~ a:fname 8944 call remove(g:netrw_bookmarklist,indx) 8945 let indx= indx - 1 8946 endif 8947 let indx= indx + 1 8948 endwhile 8949 else 8950 " remove exact match 8951 call remove(g:netrw_bookmarklist,indx) 8952 endif 8953 endif 8954 8955 endfunction 8956 8957 " s:FileReadable: o/s independent filereadable {{{2 8958 function s:FileReadable(fname) 8959 if g:netrw_cygwin 8960 let ret = filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/',''))) 8961 else 8962 let ret = filereadable(s:NetrwFile(a:fname)) 8963 endif 8964 8965 return ret 8966 endfunction 8967 8968 " s:GetTempfile: gets a tempname that'll work for various o/s's {{{2 8969 " Places correct suffix on end of temporary filename, 8970 " using the suffix provided with fname 8971 function s:GetTempfile(fname) 8972 8973 if !exists("b:netrw_tmpfile") 8974 " get a brand new temporary filename 8975 let tmpfile= tempname() 8976 8977 let tmpfile= substitute(tmpfile,'\','/','ge') 8978 8979 " sanity check -- does the temporary file's directory exist? 8980 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e'))) 8981 call netrw#msg#Notify('ERROR', printf('your <%s> directory is missing!', substitute(tmpfile,'[^/]\+$','','e'))) 8982 return "" 8983 endif 8984 8985 " let netrw#NetSource() know about the tmpfile 8986 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX() 8987 8988 " o/s dependencies 8989 if g:netrw_cygwin != 0 8990 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e') 8991 elseif has("win32") 8992 if !exists("+shellslash") || !&ssl 8993 let tmpfile = substitute(tmpfile,'/','\','g') 8994 endif 8995 else 8996 let tmpfile = tmpfile 8997 endif 8998 let b:netrw_tmpfile= tmpfile 8999 else 9000 " re-use temporary filename 9001 let tmpfile= b:netrw_tmpfile 9002 endif 9003 9004 " use fname's suffix for the temporary file 9005 " Restrict the suffix to word characters so shell metacharacters in a 9006 " remote filename (e.g. sftp://host/foo.txt;id) cannot ride along into 9007 " the tempfile name and out into a downstream shell command. 9008 if a:fname != "" 9009 if a:fname =~ '\.\w\+$' 9010 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$' 9011 let suffix = ".tar".substitute(a:fname,'^.*\(\.\w\+\)$','\1','e') 9012 elseif a:fname =~ '.txz$' 9013 let suffix = ".txz".substitute(a:fname,'^.*\(\.\w\+\)$','\1','e') 9014 else 9015 let suffix = substitute(a:fname,'^.*\(\.\w\+\)$','\1','e') 9016 endif 9017 let tmpfile= substitute(tmpfile,'\.tmp$','','e') 9018 let tmpfile .= suffix 9019 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource() 9020 endif 9021 endif 9022 9023 return tmpfile 9024 endfunction 9025 9026 " s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2 9027 " a correct command for use with a system() call 9028 function s:MakeSshCmd(sshcmd) 9029 let machine = shellescape(s:machine, 1) 9030 if s:user != '' 9031 let machine = shellescape(s:user, 1).'@'.machine 9032 endif 9033 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',machine,'') 9034 if exists("g:netrw_port") && g:netrw_port != "" 9035 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.shellescape(g:netrw_port,1),'') 9036 elseif exists("s:port") && s:port != "" 9037 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.shellescape(s:port,1),'') 9038 else 9039 let sshcmd= substitute(sshcmd,"USEPORT ",'','') 9040 endif 9041 return sshcmd 9042 endfunction 9043 9044 " s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2 9045 " Note that bookmark paths should always be absolute. 9046 function s:MakeBookmark(fname) 9047 9048 if !exists("g:netrw_bookmarklist") 9049 let g:netrw_bookmarklist = [] 9050 endif 9051 9052 " Normalize path to prevent duplicate entries 9053 let bookmark_path = netrw#fs#AbsPath(s:NetrwFile(a:fname)) 9054 let ignore_case = 0 9055 if has('win32') 9056 let bookmark_path = substitute(bookmark_path, '\\', '/', 'ge') 9057 let ignore_case = 1 9058 endif 9059 let bookmark_path = simplify(bookmark_path) 9060 9061 if isdirectory(bookmark_path) && bookmark_path !~ '/$' 9062 let bookmark_path .= '/' 9063 endif 9064 9065 if index(g:netrw_bookmarklist, bookmark_path, 0, ignore_case) == -1 9066 " Not currently in the bookmarks list, so include it 9067 call add(g:netrw_bookmarklist, bookmark_path) 9068 call sort(g:netrw_bookmarklist) 9069 endif 9070 9071 endfunction 9072 9073 " s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2 9074 function s:MergeBookmarks() 9075 " get bookmarks from .netrwbook file 9076 let savefile= s:NetrwHome()."/.netrwbook" 9077 if filereadable(s:NetrwFile(savefile)) 9078 NetrwKeepj call s:NetrwBookHistSave() 9079 NetrwKeepj call delete(savefile) 9080 endif 9081 endfunction 9082 9083 " s:NetrwBMShow: {{{2 9084 function s:NetrwBMShow() 9085 redir => bmshowraw 9086 menu 9087 redir END 9088 let bmshowlist = split(bmshowraw,'\n') 9089 if bmshowlist != [] 9090 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"') 9091 if bmshowfuncs != [] 9092 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','') 9093 if bmshowfunc =~# '^call.*BMShow()' 9094 exe "sil! NetrwKeepj ".bmshowfunc 9095 endif 9096 endif 9097 endif 9098 endfunction 9099 9100 " s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2 9101 function s:NetrwCursor(editfile) 9102 if !exists("w:netrw_liststyle") 9103 let w:netrw_liststyle= g:netrw_liststyle 9104 endif 9105 9106 9107 if &ft != "netrw" 9108 " if the current window isn't a netrw directory listing window, then use user cursorline/column 9109 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc. 9110 9111 elseif g:netrw_cursor == 8 9112 if w:netrw_liststyle == s:WIDELIST 9113 setl cursorline 9114 setl cursorcolumn 9115 else 9116 setl cursorline 9117 endif 9118 elseif g:netrw_cursor == 7 9119 setl cursorline 9120 elseif g:netrw_cursor == 6 9121 if w:netrw_liststyle == s:WIDELIST 9122 setl cursorline 9123 endif 9124 elseif g:netrw_cursor == 4 9125 " all styles: cursorline, cursorcolumn 9126 setl cursorline 9127 setl cursorcolumn 9128 9129 elseif g:netrw_cursor == 3 9130 " thin-long-tree: cursorline, user's cursorcolumn 9131 " wide : cursorline, cursorcolumn 9132 if w:netrw_liststyle == s:WIDELIST 9133 setl cursorline 9134 setl cursorcolumn 9135 else 9136 setl cursorline 9137 endif 9138 9139 elseif g:netrw_cursor == 2 9140 " thin-long-tree: cursorline, user's cursorcolumn 9141 " wide : cursorline, user's cursorcolumn 9142 setl cursorline 9143 9144 elseif g:netrw_cursor == 1 9145 " thin-long-tree: user's cursorline, user's cursorcolumn 9146 " wide : cursorline, user's cursorcolumn 9147 if w:netrw_liststyle == s:WIDELIST 9148 setl cursorline 9149 else 9150 endif 9151 9152 else 9153 " all styles: user's cursorline, user's cursorcolumn 9154 let &l:cursorline = s:netrw_usercul 9155 let &l:cursorcolumn = s:netrw_usercuc 9156 endif 9157 9158 endfunction 9159 9160 " s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2 9161 function s:RestoreCursorline() 9162 if exists("s:netrw_usercul") 9163 let &l:cursorline = s:netrw_usercul 9164 endif 9165 if exists("s:netrw_usercuc") 9166 let &l:cursorcolumn = s:netrw_usercuc 9167 endif 9168 endfunction 9169 9170 " s:RestoreRegister: restores all registers given in the dict {{{2 9171 function s:RestoreRegister(dict) 9172 for [key, val] in items(a:dict) 9173 if key == 'unnamed' 9174 let key = '' 9175 endif 9176 call setreg(key, val[0], val[1]) 9177 endfor 9178 endfunction 9179 9180 " s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2 9181 function s:NetrwEnew(...) 9182 9183 " Clean out the last buffer: 9184 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window 9185 " If so, delete it. 9186 let bufid = bufnr('$') 9187 if bufid > 1 && !buflisted(bufid) && bufloaded(bufid) && bufname(bufid) == "" && bufwinid(bufid) == -1 9188 execute printf("silent! bdelete! %s", bufid) 9189 endif 9190 9191 " grab a function-local-variable copy of buffer variables 9192 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif 9193 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif 9194 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif 9195 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif 9196 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif 9197 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif 9198 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif 9199 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif 9200 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif 9201 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif 9202 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif 9203 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif 9204 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif 9205 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif 9206 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif 9207 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif 9208 9209 NetrwKeepj call s:NetrwOptionsRestore("w:") 9210 " when tree listing uses file TreeListing... a new buffer is made. 9211 " Want the old buffer to be unlisted. 9212 " COMBAK: this causes a problem, see P43 9213 " setl nobl 9214 let netrw_keepdiff= &l:diff 9215 call s:NetrwEditFile("enew!","","") 9216 let &l:diff= netrw_keepdiff 9217 NetrwKeepj call s:NetrwOptionsSave("w:") 9218 9219 " copy function-local-variables to buffer variable equivalents 9220 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif 9221 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif 9222 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif 9223 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif 9224 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif 9225 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif 9226 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif 9227 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif 9228 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif 9229 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif 9230 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif 9231 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif 9232 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif 9233 if exists("netrw_method") |let b:netrw_method = netrw_method |endif 9234 if exists("netrw_option") |let b:netrw_option = netrw_option |endif 9235 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif 9236 9237 if a:0 > 0 9238 let b:netrw_curdir= a:1 9239 if b:netrw_curdir =~ '/$' 9240 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST 9241 setl nobl 9242 file NetrwTreeListing 9243 setl nobl bt=nowrite bh=hide 9244 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr> 9245 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr> 9246 else 9247 call s:NetrwBufRename(b:netrw_curdir) 9248 endif 9249 endif 9250 endif 9251 endfunction 9252 9253 " s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2 9254 function s:NetrwInsureWinVars() 9255 if !exists("w:netrw_liststyle") 9256 let curbuf = bufnr("%") 9257 let curwin = winnr() 9258 let iwin = 1 9259 while iwin <= winnr("$") 9260 exe iwin."wincmd w" 9261 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle") 9262 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer 9263 let winvars= w: 9264 break 9265 endif 9266 let iwin= iwin + 1 9267 endwhile 9268 exe "keepalt ".curwin."wincmd w" 9269 if exists("winvars") 9270 for k in keys(winvars) 9271 let w:{k}= winvars[k] 9272 endfor 9273 endif 9274 endif 9275 endfunction 9276 9277 " s:NetrwLcd: handles changing the (local) directory {{{2 9278 " Returns: 0=success 9279 " -1=failed 9280 function s:NetrwLcd(newdir) 9281 9282 let err472= 0 9283 try 9284 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir) 9285 catch /^Vim\%((\a\+)\)\=:E344/ 9286 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share. 9287 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at 9288 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or 9289 " forward slashes ('//Foo'), depending on whether backslashes have been converted to 9290 " forward slashes by earlier code; so check for both. 9291 if has("win32") && !g:netrw_cygwin 9292 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+' 9293 let dirname = '\' 9294 exe 'NetrwKeepj sil lcd '.fnameescape(dirname) 9295 endif 9296 endif 9297 catch /^Vim\%((\a\+)\)\=:E472/ 9298 let err472= 1 9299 endtry 9300 9301 if err472 9302 call netrw#msg#Notify('ERROR', printf('unable to change directory to <%s> (permissions?)', a:newdir)) 9303 if !exists("w:netrw_prvdir") 9304 call s:NetrwOptionsRestore("w:") 9305 exe "setl ".g:netrw_bufsettings 9306 endif 9307 return -1 9308 endif 9309 9310 return 0 9311 endfunction 9312 9313 " s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2 9314 " changed sorting, etc. Also see s:NetrwRestoreWordPosn(). 9315 function s:NetrwSaveWordPosn() 9316 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$' 9317 endfunction 9318 9319 " s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2 9320 " 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G 9321 function s:NetrwHumanReadable(sz) 9322 9323 if g:netrw_sizestyle ==# 'h' 9324 if a:sz >= 1000000000 9325 let sz = printf("%.1f",a:sz/1000000000.0)."g" 9326 elseif a:sz >= 10000000 9327 let sz = printf("%d",a:sz/1000000)."m" 9328 elseif a:sz >= 1000000 9329 let sz = printf("%.1f",a:sz/1000000.0)."m" 9330 elseif a:sz >= 10000 9331 let sz = printf("%d",a:sz/1000)."k" 9332 elseif a:sz >= 1000 9333 let sz = printf("%.1f",a:sz/1000.0)."k" 9334 else 9335 let sz= a:sz 9336 endif 9337 9338 elseif g:netrw_sizestyle ==# 'H' 9339 if a:sz >= 1073741824 9340 let sz = printf("%.1f",a:sz/1073741824.0)."G" 9341 elseif a:sz >= 10485760 9342 let sz = printf("%d",a:sz/1048576)."M" 9343 elseif a:sz >= 1048576 9344 let sz = printf("%.1f",a:sz/1048576.0)."M" 9345 elseif a:sz >= 10240 9346 let sz = printf("%d",a:sz/1024)."K" 9347 elseif a:sz >= 1024 9348 let sz = printf("%.1f",a:sz/1024.0)."K" 9349 else 9350 let sz= a:sz 9351 endif 9352 9353 else 9354 let sz= a:sz 9355 endif 9356 9357 return sz 9358 endfunction 9359 9360 " s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2 9361 " changed sorting, etc. Also see s:NetrwSaveWordPosn(). 9362 function s:NetrwRestoreWordPosn() 9363 sil! call search(s:netrw_saveword,'w') 9364 endfunction 9365 9366 " s:RestoreBufVars: {{{2 9367 function s:RestoreBufVars() 9368 9369 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif 9370 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif 9371 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif 9372 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif 9373 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif 9374 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif 9375 9376 endfunction 9377 9378 " s:RemotePathAnalysis: {{{2 9379 function s:RemotePathAnalysis(dirname) 9380 9381 " method :// user @ machine :port /path 9382 let dirpat = '^\(\w\{-}\)://\(\([^@]\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$' 9383 let s:method = substitute(a:dirname,dirpat,'\1','') 9384 let s:user = substitute(a:dirname,dirpat,'\3','') 9385 let s:machine = substitute(a:dirname,dirpat,'\4','') 9386 let s:port = substitute(a:dirname,dirpat,'\5','') 9387 let s:path = substitute(a:dirname,dirpat,'\6','') 9388 let s:fname = substitute(s:path,'^.*/\ze.','','') 9389 if s:machine =~ '@' 9390 let dirpat = '^\(.*\)@\(.\{-}\)$' 9391 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','') 9392 let s:machine = substitute(s:machine,dirpat,'\2','') 9393 endif 9394 9395 9396 endfunction 9397 9398 " s:RemoteSystem: runs a command on a remote host using ssh {{{2 9399 " Returns status 9400 " Runs system() on 9401 " [cd REMOTEDIRPATH;] a:cmd 9402 " Note that it doesn't do netrw#os#Escape(a:cmd)! 9403 function s:RemoteSystem(cmd) 9404 if !executable(g:netrw_ssh_cmd) 9405 call netrw#msg#Notify('ERROR', printf('g:netrw_ssh_cmd<%s> is not executable!', g:netrw_ssh_cmd)) 9406 elseif !exists("b:netrw_curdir") 9407 call netrw#msg#Notify('ERROR', "for some reason b:netrw_curdir doesn't exist!") 9408 else 9409 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME") 9410 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','') 9411 if remotedir != "" 9412 let cmd= cmd.' cd '.netrw#os#Escape(remotedir).";" 9413 else 9414 let cmd= cmd.' ' 9415 endif 9416 let cmd= cmd.a:cmd 9417 let ret= system(cmd) 9418 endif 9419 return ret 9420 endfunction 9421 9422 " s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2 9423 function s:RestoreWinVars() 9424 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif 9425 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif 9426 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif 9427 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif 9428 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif 9429 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif 9430 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif 9431 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif 9432 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif 9433 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif 9434 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif 9435 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif 9436 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif 9437 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif 9438 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif 9439 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif 9440 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif 9441 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif 9442 endfunction 9443 9444 " s:Rexplore: implements returning from a buffer to a netrw directory {{{2 9445 " 9446 " s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap 9447 " is true) and a command, :Rexplore, which call this function. 9448 " 9449 " s:netrw_posn is set up by s:NetrwBrowseChgDir() 9450 " 9451 " s:rexposn_BUFNR used to save/restore cursor position 9452 function s:NetrwRexplore(islocal,dirname) 9453 if exists("s:netrwdrag") 9454 return 9455 endif 9456 9457 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != "" 9458 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile 9459 exe "NetrwKeepj e ".w:netrw_rexfile 9460 unlet w:netrw_rexfile 9461 return 9462 endif 9463 9464 " --------------------------- 9465 " :Rex issued while in a file 9466 " --------------------------- 9467 9468 " record current file so :Rex can return to it from netrw 9469 let w:netrw_rexfile= expand("%") 9470 9471 if !exists("w:netrw_rexlocal") 9472 return 9473 endif 9474 if w:netrw_rexlocal 9475 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir) 9476 else 9477 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir) 9478 endif 9479 if exists("s:initbeval") 9480 setl beval 9481 endif 9482 if exists("s:rexposn_".bufnr("%")) 9483 " restore position in directory listing 9484 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')}) 9485 if exists("s:rexposn_".bufnr('%')) 9486 unlet s:rexposn_{bufnr('%')} 9487 endif 9488 else 9489 endif 9490 9491 if has("syntax") && exists("g:syntax_on") && g:syntax_on 9492 if exists("s:explore_match") 9493 exe "2match netrwMarkFile /".s:explore_match."/" 9494 endif 9495 endif 9496 9497 endfunction 9498 9499 " s:SaveBufVars: save selected b: variables to s: variables {{{2 9500 " use s:RestoreBufVars() to restore b: variables from s: variables 9501 function s:SaveBufVars() 9502 9503 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif 9504 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif 9505 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif 9506 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif 9507 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif 9508 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif 9509 9510 endfunction 9511 9512 " s:SavePosn: saves position associated with current buffer into a dictionary {{{2 9513 function s:SavePosn(posndict) 9514 9515 if !exists("a:posndict[bufnr('%')]") 9516 let a:posndict[bufnr("%")]= [] 9517 endif 9518 call add(a:posndict[bufnr("%")],winsaveview()) 9519 9520 return a:posndict 9521 endfunction 9522 9523 " s:RestorePosn: restores position associated with current buffer using dictionary {{{2 9524 function s:RestorePosn(posndict) 9525 if exists("a:posndict") 9526 if has_key(a:posndict,bufnr("%")) 9527 let posnlen= len(a:posndict[bufnr("%")]) 9528 if posnlen > 0 9529 let posnlen= posnlen - 1 9530 call winrestview(a:posndict[bufnr("%")][posnlen]) 9531 call remove(a:posndict[bufnr("%")],posnlen) 9532 endif 9533 endif 9534 endif 9535 endfunction 9536 9537 " s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2 9538 function s:SaveWinVars() 9539 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif 9540 if exists("w:netrw_col") |let s:col = w:netrw_col |endif 9541 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif 9542 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif 9543 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif 9544 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif 9545 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif 9546 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif 9547 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif 9548 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif 9549 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif 9550 if exists("w:netrw_line") |let s:line = w:netrw_line |endif 9551 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif 9552 if exists("w:netrw_method") |let s:method = w:netrw_method |endif 9553 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif 9554 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif 9555 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif 9556 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif 9557 endfunction 9558 9559 " s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2 9560 " To allow separate windows to have their own activities, such as 9561 " Explore **/pattern, several variables have been made window-oriented. 9562 " However, when the user splits a browser window (ex: ctrl-w s), these 9563 " variables are not inherited by the new window. SetBufWinVars() and 9564 " UseBufWinVars() get around that. 9565 function s:SetBufWinVars() 9566 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif 9567 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif 9568 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif 9569 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif 9570 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif 9571 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif 9572 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif 9573 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif 9574 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif 9575 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif 9576 endfunction 9577 9578 " s:SetRexDir: set directory for :Rexplore {{{2 9579 function s:SetRexDir(islocal,dirname) 9580 let w:netrw_rexdir = a:dirname 9581 let w:netrw_rexlocal = a:islocal 9582 let s:rexposn_{bufnr("%")} = winsaveview() 9583 endfunction 9584 9585 " s:ShowLink: used to modify thin and tree listings to show links {{{2 9586 function s:ShowLink() 9587 if exists("b:netrw_curdir") 9588 keepp :norm! $?\a 9589 "call histdel("/",-1) 9590 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop") 9591 let basedir = s:NetrwTreePath(w:netrw_treetop) 9592 else 9593 let basedir = b:netrw_curdir.'/' 9594 endif 9595 let fname = basedir.s:NetrwGetWord() 9596 let resname = resolve(fname) 9597 if resname =~ '^\M'.basedir 9598 let dirlen = strlen(basedir) 9599 let resname = strpart(resname,dirlen) 9600 endif 9601 let modline = getline(".")."\t --> ".resname 9602 setl noro ma 9603 call setline(".",modline) 9604 setl ro noma nomod 9605 endif 9606 endfunction 9607 9608 " s:ShowStyle: {{{2 9609 function s:ShowStyle() 9610 if !exists("w:netrw_liststyle") 9611 let liststyle= g:netrw_liststyle 9612 else 9613 let liststyle= w:netrw_liststyle 9614 endif 9615 if liststyle == s:THINLIST 9616 return s:THINLIST.":thin" 9617 elseif liststyle == s:LONGLIST 9618 return s:LONGLIST.":long" 9619 elseif liststyle == s:WIDELIST 9620 return s:WIDELIST.":wide" 9621 elseif liststyle == s:TREELIST 9622 return s:TREELIST.":tree" 9623 else 9624 return 'n/a' 9625 endif 9626 endfunction 9627 9628 " s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2 9629 function s:TreeListMove(dir) 9630 let curline = getline('.') 9631 let prvline = (line(".") > 1)? getline(line(".")-1) : '' 9632 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : '' 9633 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e') 9634 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','') 9635 let treedepthchr = substitute(s:treedepthstring,' ','','g') 9636 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1 9637 " COMBAK : need to handle when on a directory 9638 " COMBAK : need to handle ]] and ][. In general, needs work!!! 9639 if curline !~ '/$' 9640 if a:dir == '[[' && prvline != '' 9641 NetrwKeepj norm! 0 9642 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards 9643 elseif a:dir == '[]' && nxtline != '' 9644 NetrwKeepj norm! 0 9645 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards 9646 if nl != 0 9647 NetrwKeepj norm! k 9648 else 9649 NetrwKeepj norm! G 9650 endif 9651 endif 9652 endif 9653 9654 endfunction 9655 9656 " s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2 9657 " The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function 9658 " can't be called except via emenu. But due to locale, that menu line may not be called 9659 " Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway. 9660 function s:UpdateBuffersMenu() 9661 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu 9662 try 9663 sil emenu Buffers.Refresh\ menu 9664 catch /^Vim\%((\a\+)\)\=:E/ 9665 let v:errmsg= "" 9666 sil NetrwKeepj call s:NetrwBMShow() 9667 endtry 9668 endif 9669 endfunction 9670 9671 " s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2 9672 " Matching function to s:SetBufWinVars() 9673 function s:UseBufWinVars() 9674 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif 9675 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif 9676 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif 9677 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif 9678 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif 9679 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif 9680 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif 9681 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif 9682 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif 9683 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif 9684 endfunction 9685 9686 " s:UserMaps: supports user-defined UserMaps {{{2 9687 " * calls a user-supplied funcref(islocal,curdir) 9688 " * interprets result 9689 " See netrw#UserMaps() 9690 function s:UserMaps(islocal,funcname) 9691 if !exists("b:netrw_curdir") 9692 let b:netrw_curdir= getcwd() 9693 endif 9694 let Funcref = function(a:funcname) 9695 let result = Funcref(a:islocal) 9696 9697 if type(result) == 1 9698 " if result from user's funcref is a string... 9699 if result == "refresh" 9700 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 9701 elseif result != "" 9702 exe result 9703 endif 9704 9705 elseif type(result) == 3 9706 " if result from user's funcref is a List... 9707 for action in result 9708 if action == "refresh" 9709 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 9710 elseif action != "" 9711 exe action 9712 endif 9713 endfor 9714 endif 9715 endfunction 9716 9717 " Deprecated: {{{1 9718 9719 " }}} 9720 " Settings Restoration: {{{1 9721 9722 let &cpo= s:keepcpo 9723 unlet s:keepcpo 9724 9725 " }}} 9726 " vim:ts=8 sts=4 sw=4 et fdm=marker