robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
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 19if & cp || exists ( "g:loaded_netrw" ) 20finish 21endif 22 23let g: loaded_netrw = "v184" 24 25if ! has ( "patch-9.1.1054" ) && ! has ( 'nvim' ) 26echoerr 'netrw needs Vim v9.1.1054' 27finish 28endif 29 30let s: keepcpo = & cpo 31setl cpo & vim 32 33" Netrw Variables: {{{1 34 35" s:NetrwInit: initializes variables if they haven't been defined {{{2 36 37function s: NetrwInit ( name , default ) 38if ! exists ( a: name ) 39let { a: name } = a: default 40endif 41endfunction 42 43" Netrw Constants: {{{2 44call s: NetrwInit ( "g:netrw_dirhistcnt" , 0 ) 45if ! exists ( "s:LONGLIST" ) 46call s: NetrwInit ( "s:THINLIST" , 0 ) 47call s: NetrwInit ( "s:LONGLIST" , 1 ) 48call s: NetrwInit ( "s:WIDELIST" , 2 ) 49call s: NetrwInit ( "s:TREELIST" , 3 ) 50call s: NetrwInit ( "s:MAXLIST" , 4 ) 51endif 52 53" Default option values: {{{2 54call s: NetrwInit ( "g:netrw_localcopycmdopt" , "" ) 55call s: NetrwInit ( "g:netrw_localcopydircmdopt" , "" ) 56call s: NetrwInit ( "g:netrw_localmkdiropt" , "" ) 57call s: NetrwInit ( "g:netrw_localmovecmdopt" , "" ) 58 59" Default values for netrw's global protocol variables {{{2 60 61if ! exists ( "g:netrw_dav_cmd" ) 62if executable ( "cadaver" ) 63let g: netrw_dav_cmd = "cadaver" 64elseif executable ( "curl" ) 65let g: netrw_dav_cmd = "curl" 66else 67let g: netrw_dav_cmd = "" 68endif 69endif 70if ! exists ( "g:netrw_fetch_cmd" ) 71if executable ( "fetch" ) 72let g: netrw_fetch_cmd = "fetch -o" 73else 74let g: netrw_fetch_cmd = "" 75endif 76endif 77if ! exists ( "g:netrw_file_cmd" ) 78if executable ( "elinks" ) 79call s: NetrwInit ( "g:netrw_file_cmd" , "elinks" ) 80elseif executable ( "links" ) 81call s: NetrwInit ( "g:netrw_file_cmd" , "links" ) 82endif 83endif 84if ! exists ( "g:netrw_ftp_cmd" ) 85let g: netrw_ftp_cmd = "ftp" 86endif 87let s: netrw_ftp_cmd = g: netrw_ftp_cmd 88if ! exists ( "g:netrw_ftp_options" ) 89let g: netrw_ftp_options = "-i -n" 90endif 91if ! exists ( "g:netrw_http_cmd" ) 92if executable ( "wget" ) 93let g: netrw_http_cmd = "wget" 94call s: NetrwInit ( "g:netrw_http_xcmd" , "-q -O" ) 95elseif executable ( "curl" ) 96let g: netrw_http_cmd = "curl" 97call s: NetrwInit ( "g:netrw_http_xcmd" , "-L -o" ) 98elseif executable ( "elinks" ) 99let g: netrw_http_cmd = "elinks" 100call s: NetrwInit ( "g:netrw_http_xcmd" , "-source >" ) 101elseif executable ( "fetch" ) 102let g: netrw_http_cmd = "fetch" 103call s: NetrwInit ( "g:netrw_http_xcmd" , "-o" ) 104elseif executable ( "links" ) 105let g: netrw_http_cmd = "links" 106call s: NetrwInit ( "g:netrw_http_xcmd" , "-http.extra-header " . shellescape ( "Accept-Encoding: identity" , 1 ) . " -source >" ) 107else 108let g: netrw_http_cmd = "" 109endif 110endif 111call s: NetrwInit ( "g:netrw_http_put_cmd" , "curl -T" ) 112call s: NetrwInit ( "g:netrw_keepj" , "keepj" ) 113call s: NetrwInit ( "g:netrw_rcp_cmd" , "rcp" ) 114call s: NetrwInit ( "g:netrw_rsync_cmd" , "rsync" ) 115call s: NetrwInit ( "g:netrw_rsync_sep" , "/" ) 116if ! exists ( "g:netrw_scp_cmd" ) 117if executable ( "scp" ) 118call s: NetrwInit ( "g:netrw_scp_cmd" , "scp -q" ) 119elseif executable ( "pscp" ) 120call s: NetrwInit ( "g:netrw_scp_cmd" , 'pscp -q' ) 121else 122call s: NetrwInit ( "g:netrw_scp_cmd" , "scp -q" ) 123endif 124endif 125call s: NetrwInit ( "g:netrw_sftp_cmd" , "sftp" ) 126call s: NetrwInit ( "g:netrw_ssh_cmd" , "ssh" ) 127 128if has ( "win32" ) 129 \&& exists ( "g:netrw_use_nt_rcp" ) 130 \&& g: netrw_use_nt_rcp 131 \&& executable ( $ SystemRoot . '/system32/rcp.exe' ) 132let s: netrw_has_nt_rcp = 1 133let s: netrw_rcpmode = '-b' 134else 135let s: netrw_has_nt_rcp = 0 136let s: netrw_rcpmode = '' 137endif 138 139" Default values for netrw's global variables {{{2 140" Cygwin Detection ------- {{{3 141if ! exists ( "g:netrw_cygwin" ) 142if has ( "win32unix" ) && & shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' 143let g: netrw_cygwin = 1 144else 145let g: netrw_cygwin = 0 146endif 147endif 148" Default values - a-c ---------- {{{3 149call s: NetrwInit ( "g:netrw_alto" , & sb ) 150call s: NetrwInit ( "g:netrw_altv" , & spr ) 151call s: NetrwInit ( "g:netrw_banner" , 1 ) 152call s: NetrwInit ( "g:netrw_browse_split" , 0 ) 153call s: NetrwInit ( "g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu" ) 154call s: NetrwInit ( "g:netrw_chgwin" , -1 ) 155call s: NetrwInit ( "g:netrw_clipboard" , 1 ) 156call s: NetrwInit ( "g:netrw_compress" , "gzip" ) 157call s: NetrwInit ( "g:netrw_ctags" , "ctags" ) 158call s: NetrwInit ( "g:netrw_cursor" , 2 ) 159let s: netrw_usercul = & cursorline 160let s: netrw_usercuc = & cursorcolumn 161call s: NetrwInit ( "g:netrw_cygdrive" , "/cygdrive" ) 162" Default values - d-g ---------- {{{3 163call s: NetrwInit ( "s:didstarstar" , 0 ) 164call s: NetrwInit ( "g:netrw_dirhistcnt" , 0 ) 165let s: xz_opt = has ( 'unix' ) ? "XZ_OPT=-T0" : 166 \( has ( "win32" ) && & shell =~? '\vcmd(\.exe)?$' ? 167 \"setx XZ_OPT=-T0 &&" : "" ) 168call 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 \}) 197unlet s: xz_opt 198call s: NetrwInit ( "g:netrw_dirhistmax" , 10 ) 199call s: NetrwInit ( "g:netrw_fastbrowse" , 1 ) 200call 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$' ) 201if ! exists ( "g:netrw_ftp_list_cmd" ) 202if has ( "unix" ) || g: netrw_cygwin 203let g: netrw_ftp_list_cmd = "ls -lF" 204let g: netrw_ftp_timelist_cmd = "ls -tlF" 205let g: netrw_ftp_sizelist_cmd = "ls -slF" 206else 207let g: netrw_ftp_list_cmd = "dir" 208let g: netrw_ftp_timelist_cmd = "dir" 209let g: netrw_ftp_sizelist_cmd = "dir" 210endif 211endif 212call s: NetrwInit ( "g:netrw_ftpmode" , 'binary' ) 213" Default values - h-lh ---------- {{{3 214call s: NetrwInit ( "g:netrw_hide" , 1 ) 215if ! exists ( "g:netrw_ignorenetrc" ) 216if & shell =~ '\c\<\%(cmd\|4nt\)\.exe$' 217let g: netrw_ignorenetrc = 1 218else 219let g: netrw_ignorenetrc = 0 220endif 221endif 222call s: NetrwInit ( "g:netrw_keepdir" , 1 ) 223if ! exists ( "g:netrw_list_cmd" ) 224if g: netrw_scp_cmd =~ '^pscp' && executable ( "pscp" ) 225if exists ( "g:netrw_list_cmd_options" ) 226let g: netrw_list_cmd = g: netrw_scp_cmd . " -ls USEPORT HOSTNAME: " . g: netrw_list_cmd_options 227else 228let g: netrw_list_cmd = g: netrw_scp_cmd . " -ls USEPORT HOSTNAME:" 229endif 230elseif executable ( g: netrw_ssh_cmd ) 231" provide a scp-based default listing command 232if exists ( "g:netrw_list_cmd_options" ) 233let g: netrw_list_cmd = g: netrw_ssh_cmd . " USEPORT HOSTNAME ls -FLa " . g: netrw_list_cmd_options 234else 235let g: netrw_list_cmd = g: netrw_ssh_cmd . " USEPORT HOSTNAME ls -FLa" 236endif 237else 238let g: netrw_list_cmd = "" 239endif 240endif 241call s: NetrwInit ( "g:netrw_list_hide" , "" ) 242" Default values - lh-lz ---------- {{{3 243if ! exists ( "g:netrw_localcmdshell" ) 244let g: netrw_localcmdshell = "" 245endif 246 247if ! exists ( "g:netrw_localcopycmd" ) 248let g: netrw_localcopycmd = 'cp' 249let g: netrw_localcopycmdopt = '' 250 251if has ( "win32" ) && ! g: netrw_cygwin 252let g: netrw_localcopycmd = $ COMSPEC 253let g: netrw_localcopycmdopt = ' /c copy' 254endif 255endif 256 257if ! exists ( "g:netrw_localcopydircmd" ) 258let g: netrw_localcopydircmd = 'cp' 259let g: netrw_localcopydircmdopt = '-R' 260 261if has ( "win32" ) && ! g: netrw_cygwin 262let g: netrw_localcopydircmd = "xcopy" 263let g: netrw_localcopydircmdopt = " /E /I /H /C /Y" 264endif 265endif 266 267if ! exists ( "g:netrw_localmkdir" ) 268if has ( "win32" ) 269if g: netrw_cygwin 270let g: netrw_localmkdir = "mkdir" 271else 272let g: netrw_localmkdir = $ COMSPEC 273let g: netrw_localmkdiropt = " /c mkdir" 274endif 275else 276let g: netrw_localmkdir = "mkdir" 277endif 278endif 279 280if ! exists ( "g:netrw_localmovecmd" ) 281if has ( "win32" ) 282if g: netrw_cygwin 283let g: netrw_localmovecmd = "mv" 284else 285let g: netrw_localmovecmd = $ COMSPEC 286let g: netrw_localmovecmdopt = " /c move" 287endif 288elseif has ( "unix" ) || has ( "macunix" ) 289let g: netrw_localmovecmd = "mv" 290else 291let g: netrw_localmovecmd = "" 292endif 293endif 294 295call s: NetrwInit ( "g:netrw_liststyle" , s: THINLIST ) 296" sanity checks 297if g: netrw_liststyle < 0 || g: netrw_liststyle >= s: MAXLIST 298let g: netrw_liststyle = s: THINLIST 299endif 300if g: netrw_liststyle == s: LONGLIST && g: netrw_scp_cmd !~ '^pscp' 301let g: netrw_list_cmd = g: netrw_list_cmd . " -l" 302endif 303" Default values - m-r ---------- {{{3 304call s: NetrwInit ( "g:netrw_markfileesc" , '*./[\~' ) 305call s: NetrwInit ( "g:netrw_maxfilenamelen" , 32 ) 306call s: NetrwInit ( "g:netrw_menu" , 1 ) 307call s: NetrwInit ( "g:netrw_mkdir_cmd" , g: netrw_ssh_cmd . " USEPORT HOSTNAME mkdir" ) 308call s: NetrwInit ( "g:netrw_mousemaps" , ( exists ( "+mouse" ) && & mouse =~# '[anh]' )) 309call s: NetrwInit ( "g:netrw_retmap" , 0 ) 310if has ( "unix" ) || g: netrw_cygwin 311call s: NetrwInit ( "g:netrw_chgperm" , "chmod PERM FILENAME" ) 312elseif has ( "win32" ) 313call s: NetrwInit ( "g:netrw_chgperm" , "cacls FILENAME /e /p PERM" ) 314else 315call s: NetrwInit ( "g:netrw_chgperm" , "chmod PERM FILENAME" ) 316endif 317call s: NetrwInit ( "g:netrw_preview" , 0 ) 318call s: NetrwInit ( "g:netrw_scpport" , "-P" ) 319call s: NetrwInit ( "g:netrw_servername" , "NETRWSERVER" ) 320call s: NetrwInit ( "g:netrw_sshport" , "-p" ) 321call s: NetrwInit ( "g:netrw_rename_cmd" , g: netrw_ssh_cmd . " USEPORT HOSTNAME mv" ) 322call s: NetrwInit ( "g:netrw_rm_cmd" , g: netrw_ssh_cmd . " USEPORT HOSTNAME rm" ) 323call s: NetrwInit ( "g:netrw_rmdir_cmd" , g: netrw_ssh_cmd . " USEPORT HOSTNAME rmdir" ) 324call s: NetrwInit ( "g:netrw_rmf_cmd" , g: netrw_ssh_cmd . " USEPORT HOSTNAME rm -f " ) 325" Default values - q-s ---------- {{{3 326call s: NetrwInit ( "g:netrw_quickhelp" , 0 ) 327let 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 336call s: NetrwInit ( "g:netrw_sepchr" , ( & enc == "euc-jp" ) ? "\<Char-0x01>" : "\<Char-0xff>" ) 337if ! exists ( "g:netrw_keepj" ) || g: netrw_keepj == "keepj" 338call s: NetrwInit ( "s:netrw_silentxfer" , ( exists ( "g:netrw_silent" ) && g: netrw_silent != 0 ) ? "sil keepj " : "keepj " ) 339else 340call s: NetrwInit ( "s:netrw_silentxfer" , ( exists ( "g:netrw_silent" ) && g: netrw_silent != 0 ) ? "sil " : " " ) 341endif 342call s: NetrwInit ( "g:netrw_sort_by" , "name" ) " alternatives: date , size 343call s: NetrwInit ( "g:netrw_sort_options" , "" ) 344call s: NetrwInit ( "g:netrw_sort_direction" , "normal" ) " alternative: reverse (z y x ...) 345if ! exists ( "g:netrw_sort_sequence" ) 346let g: netrw_sort_sequence = ! empty ( & suffixes ) 347 \? printf ( '[\/]$,*,\%(%s\)[*@]\=$' , & suffixes ->split ( ',' ) ->map ( 'escape(v:val, ".*$~")' ) ->join ( '\|' )) 348 \: '[\/]$,*' 349endif 350call s: NetrwInit ( "g:netrw_special_syntax" , 0 ) 351call s: NetrwInit ( "g:netrw_ssh_browse_reject" , '^total\s\+\d\+$' ) 352call s: NetrwInit ( "g:netrw_use_noswf" , 1 ) 353call s: NetrwInit ( "g:netrw_sizestyle" , "b" ) 354" Default values - t-w ---------- {{{3 355call s: NetrwInit ( "g:netrw_timefmt" , "%c" ) 356if ! exists ( "g:netrw_xstrlen" ) 357if exists ( "g:Align_xstrlen" ) 358let g: netrw_xstrlen = g: Align_xstrlen 359elseif exists ( "g:drawit_xstrlen" ) 360let g: netrw_xstrlen = g: drawit_xstrlen 361elseif & enc == "latin1" || ! has ( "multi_byte" ) 362let g: netrw_xstrlen = 0 363else 364let g: netrw_xstrlen = 1 365endif 366endif 367call s: NetrwInit ( "g:NetrwTopLvlMenu" , "Netrw." ) 368call s: NetrwInit ( "g:netrw_winsize" , 50 ) 369call s: NetrwInit ( "g:netrw_wiw" , 1 ) 370if g: netrw_winsize > 100 |let g: netrw_winsize = 100 |endif 371" Default values for netrw's script variables: {{{2 372call s: NetrwInit ( "g:netrw_fname_escape" , ' ?&;%' ) 373if has ( "win32" ) 374call s: NetrwInit ( "g:netrw_glob_escape" , '*?`{[]$' ) 375else 376call s: NetrwInit ( "g:netrw_glob_escape" , '*[]?`{~$\' ) 377endif 378call s: NetrwInit ( "g:netrw_menu_escape" , '.&? \|' ) 379call s: NetrwInit ( "s:netrw_map_escape" , "<|\n\r\\\<C-V>\"" ) 380if has ( "gui_running" ) && ( & enc == 'utf-8' || & enc == 'utf-16' || & enc == 'ucs-4' ) 381let s: treedepthstring = "│ " 382else 383let s: treedepthstring = "| " 384endif 385call 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 393au WinEnter * if & ft == "netrw" |call s: NetrwInsureWinVars () |endif 394 395if g: netrw_keepj =~# "keepj" 396com ! -nargs = * NetrwKeepj keepj <args> 397else 398let g: netrw_keepj = "" 399com ! -nargs = * NetrwKeepj <args> 400endif 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 419function netrw#Explore ( indx , dosplit , style ,...) 420if ! exists ( "b:netrw_curdir" ) 421let b: netrw_curdir = netrw#fs#Cwd ( 0 ) 422endif 423 424" record current file for Rexplore's benefit 425if & ft != "netrw" 426let w: netrw_rexfile = expand ( "%:p" ) 427endif 428 429" record current directory 430let curdir = simplify ( b: netrw_curdir ) 431if ! g: netrw_cygwin && has ( "win32" ) 432let curdir = substitute ( curdir , '\' , '/' , 'g' ) 433endif 434let curfiledir = substitute ( expand ( "%:p" ), '^\(.*[/\\]\)[^/\\]*$' , '\1' , 'e' ) 435if & buftype == "terminal" 436let curfiledir = curdir 437endif 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. 442if a: 0 > 0 443if a: 1 =~ "\\\s" && ! filereadable ( s: NetrwFile ( a: 1 )) && ! isdirectory ( s: NetrwFile ( a: 1 )) 444let a1 = substitute ( a: 1 , '\\\(\s\)' , '\1' , 'g' ) 445if a1 != a: 1 446call netrw#Explore ( a: indx , a: dosplit , a: style , a1 ) 447return 448endif 449endif 450endif 451 452" save registers 453if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 454sil ! let keepregstar = @* 455sil ! let keepregplus = @+ 456endif 457sil ! 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 462if a: dosplit || ( & buftype != "terminal" && & modified && & hidden == 0 && & bufhidden != "hide" ) || a: style == 6 463call s: SaveWinVars () 464let winsz = g: netrw_winsize 465if a: indx > 0 466let winsz = a: indx 467endif 468 469if a: style == 0 " Explore, Sexplore 470let winsz = ( winsz > 0 ) ? ( winsz * winheight ( 0 )) / 100 : - winsz 471if winsz == 0 |let winsz = "" |endif 472exe "noswapfile " . ( g: netrw_alto ? "below " : "above " ). winsz . "wincmd s" 473 474elseif a: style == 1 " Explore!, Sexplore! 475let winsz = ( winsz > 0 ) ? ( winsz * winwidth ( 0 )) / 100 : - winsz 476if winsz == 0 |let winsz = "" |endif 477exe "keepalt noswapfile " . ( g: netrw_altv ? "rightbelow " : "leftabove " ). winsz . "wincmd v" 478 479elseif a: style == 2 " Hexplore 480let winsz = ( winsz > 0 ) ? ( winsz * winheight ( 0 )) / 100 : - winsz 481if winsz == 0 |let winsz = "" |endif 482exe "keepalt noswapfile " . ( g: netrw_alto ? "below " : "above " ). winsz . "wincmd s" 483 484elseif a: style == 3 " Hexplore! 485let winsz = ( winsz > 0 ) ? ( winsz * winheight ( 0 )) / 100 : - winsz 486if winsz == 0 |let winsz = "" |endif 487exe "keepalt noswapfile " . ( ! g: netrw_alto ? "below " : "above " ). winsz . "wincmd s" 488 489elseif a: style == 4 " Vexplore 490let winsz = ( winsz > 0 ) ? ( winsz * winwidth ( 0 )) / 100 : - winsz 491if winsz == 0 |let winsz = "" |endif 492exe "keepalt noswapfile " . ( g: netrw_altv ? "rightbelow " : "leftabove " ). winsz . "wincmd v" 493 494elseif a: style == 5 " Vexplore! 495let winsz = ( winsz > 0 ) ? ( winsz * winwidth ( 0 )) / 100 : - winsz 496if winsz == 0 |let winsz = "" |endif 497exe "keepalt noswapfile " . ( ! g: netrw_altv ? "rightbelow " : "leftabove " ). winsz . "wincmd v" 498 499elseif a: style == 6 " Texplore 500call s: SaveBufVars () 501exe "keepalt tabnew " . fnameescape ( curdir ) 502call s: RestoreBufVars () 503endif 504call s: RestoreWinVars () 505endif 506NetrwKeepj norm! 0 507 508if a: 0 > 0 509if a: 1 =~ '^\~' && ( has ( "unix" ) || has ( "win32" ) || g: netrw_cygwin ) 510let dirname = simplify ( substitute ( a: 1 , '^\~' , escape ( expand ( "$HOME" ), '\&~' ), '' )) 511elseif a: 1 == '.' 512let dirname = simplify ( exists ( "b:netrw_curdir" ) ? b: netrw_curdir : getcwd ()) 513if dirname !~ '/$' 514let dirname = dirname . "/" 515endif 516elseif a: 1 =~ '\$' 517let dirname = simplify ( expand ( a: 1 )) 518elseif a: 1 !~ '^\*\{1,2}/' && a: 1 !~ '^\a\{3,}://' 519let dirname = simplify ( a: 1 ) 520else 521let dirname = a: 1 522endif 523else 524" clear explore 525call s: NetrwClearExplore () 526return 527endif 528" Win32: Use forward slashes 529if ! g: netrw_cygwin && has ( "win32" ) 530let dirname = substitute ( dirname , '\' , '/' , 'g' ) 531endif 532 533if dirname =~ '\.\./\=$' 534let dirname = simplify ( fnamemodify ( dirname , ':p:h' )) 535elseif dirname =~ '\.\.' || dirname == '.' 536let dirname = simplify ( fnamemodify ( dirname , ':p' )) 537endif 538 539if dirname =~ '^\*//' 540" starpat=1: Explore *//pattern (current directory only search for files containing pattern) 541let pattern = substitute ( dirname , '^\*//\(.*\)$' , '\1' , '' ) 542let starpat = 1 543if & hls |let keepregslash = s: ExplorePatHls ( pattern ) |endif 544 545elseif dirname =~ '^\*\*//' 546" starpat=2: Explore **//pattern (recursive descent search for files containing pattern) 547let pattern = substitute ( dirname , '^\*\*//' , '' , '' ) 548let starpat = 2 549 550elseif dirname =~ '/\*\*/' 551" handle .../**/.../filepat 552let prefixdir = substitute ( dirname , '^\(.\{-}\)\*\*.*$' , '\1' , '' ) 553if prefixdir =~ '^/' || ( prefixdir =~ '^\a:/' && has ( "win32" )) 554let b: netrw_curdir = prefixdir 555else 556let b: netrw_curdir = getcwd () . '/' . prefixdir 557endif 558let dirname = substitute ( dirname , '^.\{-}\(\*\*/.*\)$' , '\1' , '' ) 559let starpat = 4 560 561elseif dirname =~ '^\*/' 562" case starpat=3: Explore */filepat (search in current directory for filenames matching filepat) 563let starpat = 3 564 565elseif dirname =~ '^\*\*/' 566" starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) 567let starpat = 4 568 569else 570let starpat = 0 571endif 572 573if starpat == 0 && a: indx >= 0 574if dirname == "" 575let dirname = curfiledir 576endif 577" [Explore Hexplore Vexplore Sexplore] [dirname] 578if dirname =~# '^scp://' || dirname =~ '^ftp://' 579call netrw#Nread ( 2 , dirname ) 580else 581if dirname == "" 582let dirname = netrw#fs#Cwd ( 0 ) 583elseif 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). 586if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+' 587let dirname = b: netrw_curdir . "/" . dirname 588endif 589elseif dirname !~ '^/' 590let dirname = b: netrw_curdir . "/" . dirname 591endif 592call netrw#LocalBrowseCheck ( dirname ) 593endif 594if 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. 597exe w: netrw_bannercnt 598endif 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) 605elseif a: indx <= 0 606" Nexplore, Pexplore, Explore: handle starpat 607if ! mapcheck ( "<s-up>" , "n" ) && ! mapcheck ( "<s-down>" , "n" ) && exists ( "b:netrw_curdir" ) 608let s: didstarstar = 1 609nnoremap <buffer> <silent> < s-up > :Pexplore< cr > 610nnoremap <buffer> <silent> < s-down > :Nexplore< cr > 611endif 612 613if has ( "path_extra" ) 614if ! exists ( "w:netrw_explore_indx" ) 615let w: netrw_explore_indx = 0 616endif 617 618let indx = a: indx 619 620if indx == -1 621" Nexplore 622if ! exists ( "w:netrw_explore_list" ) " sanity check 623call netrw#msg#Notify ( 'WARNING' , 'using Nexplore or <s-down> improperly; see help for netrw-starstar' ) 624if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 625if @*!= keepregstar |sil ! let @*= keepregstar |endif 626if @+!= keepregplus |sil ! let @+= keepregplus |endif 627endif 628sil ! let @/= keepregslash 629return 630endif 631let indx = w: netrw_explore_indx 632if indx < 0 |let indx = 0 |endif 633if indx >= w: netrw_explore_listlen |let indx = w: netrw_explore_listlen - 1 |endif 634let curfile = w: netrw_explore_list [ indx ] 635while indx < w: netrw_explore_listlen && curfile == w: netrw_explore_list [ indx ] 636let indx = indx + 1 637endwhile 638if indx >= w: netrw_explore_listlen |let indx = w: netrw_explore_listlen - 1 |endif 639 640elseif indx == -2 641" Pexplore 642if ! exists ( "w:netrw_explore_list" ) " sanity check 643call netrw#msg#Notify ( 'WARNING' , 'using Pexplore or <s-up> improperly; see help for netrw-starstar' ) 644if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 645if @*!= keepregstar |sil ! let @*= keepregstar |endif 646if @+!= keepregplus |sil ! let @+= keepregplus |endif 647endif 648sil ! let @/= keepregslash 649return 650endif 651let indx = w: netrw_explore_indx 652if indx < 0 |let indx = 0 |endif 653if indx >= w: netrw_explore_listlen |let indx = w: netrw_explore_listlen - 1 |endif 654let curfile = w: netrw_explore_list [ indx ] 655while indx >= 0 && curfile == w: netrw_explore_list [ indx ] 656let indx = indx - 1 657endwhile 658if indx < 0 |let indx = 0 |endif 659 660else 661" Explore -- initialize 662" build list of files to Explore with Nexplore/Pexplore 663NetrwKeepj keepalt call s:NetrwClearExplore() 664let w: netrw_explore_indx = 0 665if ! exists ( "b:netrw_curdir" ) 666let b: netrw_curdir = getcwd () 667endif 668 669" switch on starpat to build the w:netrw_explore_list of files 670if starpat == 1 671" starpat=1: Explore *//pattern (current directory only search for files containing pattern) 672try 673exe "NetrwKeepj noautocmd vimgrep /" . pattern . "/gj " . fnameescape ( b: netrw_curdir ) . "/*" 674catch /^Vim\%((\a\+)\)\=:E480/ 675call netrw#msg#Notify ( 'WARNING' , printf ( "no match with pattern<%s>" , pattern )) 676return 677endtry 678let w: netrw_explore_list = s: NetrwExploreListUniq ( map ( getqflist (), 'bufname(v:val.bufnr)' )) 679if & hls |let keepregslash = s: ExplorePatHls ( pattern ) |endif 680 681elseif starpat == 2 682" starpat=2: Explore **//pattern (recursive descent search for files containing pattern) 683try 684exe "sil NetrwKeepj noautocmd keepalt vimgrep /" . pattern . "/gj " . "**/*" 685catch /^Vim\%((\a\+)\)\=:E480/ 686call netrw#msg#Notify ( 'WARNING' , printf ( 'no files matched pattern<%s>' , pattern )) 687if & hls |let keepregslash = s: ExplorePatHls ( pattern ) |endif 688if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 689if @*!= keepregstar |sil ! let @*= keepregstar |endif 690if @+!= keepregplus |sil ! let @+= keepregplus |endif 691endif 692sil ! let @/= keepregslash 693return 694endtry 695let s: netrw_curdir = b: netrw_curdir 696let w: netrw_explore_list = getqflist () 697let w: netrw_explore_list = s: NetrwExploreListUniq ( map ( w: netrw_explore_list , 's:netrw_curdir."/".bufname(v:val.bufnr)' )) 698if & hls |let keepregslash = s: ExplorePatHls ( pattern ) |endif 699 700elseif starpat == 3 701" starpat=3: Explore */filepat (search in current directory for filenames matching filepat) 702let filepat = substitute ( dirname , '^\*/' , '' , '' ) 703let filepat = substitute ( filepat , '^[%#<]' , '\\&' , '' ) 704let w: netrw_explore_list = s: NetrwExploreListUniq ( split ( expand ( b: netrw_curdir . "/" . filepat ), '\n' )) 705if & hls |let keepregslash = s: ExplorePatHls ( filepat ) |endif 706 707elseif starpat == 4 708" starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat) 709let w: netrw_explore_list = s: NetrwExploreListUniq ( split ( expand ( b: netrw_curdir . "/" . dirname ), '\n' )) 710if & hls |let keepregslash = s: ExplorePatHls ( dirname ) |endif 711endif " switch on starpat to build w:netrw_explore_list 712 713let w: netrw_explore_listlen = len ( w: netrw_explore_list ) 714 715if w: netrw_explore_listlen == 0 || ( w: netrw_explore_listlen == 1 && w: netrw_explore_list [ 0 ] =~ '\*\*\/' ) 716call netrw#msg#Notify ( 'WARNING' , 'no files matched' ) 717if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 718if @*!= keepregstar |sil ! let @*= keepregstar |endif 719if @+!= keepregplus |sil ! let @+= keepregplus |endif 720endif 721sil ! let @/= keepregslash 722return 723endif 724endif " if indx ... endif 725 726" NetrwStatusLine support - for exploring support 727let w: netrw_explore_indx = indx 728 729" wrap the indx around, but issue a note 730if indx >= w: netrw_explore_listlen || indx < 0 731let indx = ( indx < 0 ) ? ( w: netrw_explore_listlen - 1 ) : 0 732let w: netrw_explore_indx = indx 733call netrw#msg#Notify ( 'NOTE' , 'no more files match Explore pattern' ) 734endif 735 736exe "let dirfile= w:netrw_explore_list[" . indx . "]" 737let newdir = substitute ( dirfile , '/[^/]*$' , '' , 'e' ) 738 739call netrw#LocalBrowseCheck ( newdir ) 740if ! exists ( "w:netrw_liststyle" ) 741let w: netrw_liststyle = g: netrw_liststyle 742endif 743if w: netrw_liststyle == s: THINLIST || w: netrw_liststyle == s: LONGLIST 744keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W") 745else 746keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w") 747endif 748let w: netrw_explore_mtchcnt = indx + 1 749let w: netrw_explore_bufnr = bufnr ( "%" ) 750let w: netrw_explore_line = line ( "." ) 751keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}') 752 753else 754call netrw#msg#Notify ( 'WARNING' , 'your vim needs the +path_extra feature for Exploring with **!' ) 755if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 756if @*!= keepregstar |sil ! let @*= keepregstar |endif 757if @+!= keepregplus |sil ! let @+= keepregplus |endif 758endif 759sil ! let @/= keepregslash 760return 761endif 762 763else 764if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && dirname =~ '/' 765sil ! unlet w: netrw_treedict 766sil ! unlet w: netrw_treetop 767endif 768let newdir = dirname 769if ! exists ( "b:netrw_curdir" ) 770NetrwKeepj call netrw#LocalBrowseCheck(getcwd()) 771else 772NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0)) 773endif 774endif 775 776" visual display of **/ **// */ Exploration files 777if exists ( "w:netrw_explore_indx" ) && exists ( "b:netrw_curdir" ) 778if ! exists ( "s:explore_prvdir" ) || s: explore_prvdir != b: netrw_curdir 779" only update match list when current directory isn't the same as before 780let s: explore_prvdir = b: netrw_curdir 781let s: explore_match = "" 782let dirlen = strlen ( b: netrw_curdir ) 783if b: netrw_curdir !~ '/$' 784let dirlen = dirlen + 1 785endif 786let prvfname = "" 787for fname in w: netrw_explore_list 788if fname =~ '^' . b: netrw_curdir 789if s: explore_match == "" 790let s: explore_match = '\<' . escape ( strpart ( fname , dirlen ), g: netrw_markfileesc ) . '\>' 791else 792let s: explore_match = s: explore_match . '\|\<' . escape ( strpart ( fname , dirlen ), g: netrw_markfileesc ) . '\>' 793endif 794elseif fname !~ '^/' && fname != prvfname 795if s: explore_match == "" 796let s: explore_match = '\<' . escape ( fname , g: netrw_markfileesc ) . '\>' 797else 798let s: explore_match = s: explore_match . '\|\<' . escape ( fname , g: netrw_markfileesc ) . '\>' 799endif 800endif 801let prvfname = fname 802endfor 803if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 804exe "2match netrwMarkFile /" . s: explore_match . "/" 805endif 806endif 807echo "<s-up>==Pexplore <s-down>==Nexplore" 808else 8092 match none 810if exists ( "s:explore_match" ) |unlet s: explore_match |endif 811if exists ( "s:explore_prvdir" ) |unlet s: explore_prvdir |endif 812endif 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. 817let s: netrw_events = 2 818if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 819if @*!= keepregstar |sil ! let @*= keepregstar |endif 820if @+!= keepregplus |sil ! let @+= keepregplus |endif 821endif 822sil ! let @/= keepregslash 823endfunction 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) 831function netrw#Lexplore ( count , rightside ,...) 832let curwin = winnr () 833 834if 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. 838let a1 = expand ( a: 1 ) 839exe "1wincmd w" 840if & ft == "netrw" 841exe "Explore " . fnameescape ( a1 ) 842exe curwin . "wincmd w" 843let s: lexplore_win = curwin 844let w: lexplore_buf = bufnr ( "%" ) 845if exists ( "t:netrw_lexposn" ) 846unlet t: netrw_lexposn 847endif 848return 849endif 850exe curwin . "wincmd w" 851else 852let a1 = "" 853endif 854 855if exists ( "t:netrw_lexbufnr" ) 856" check if t:netrw_lexbufnr refers to a netrw window 857let lexwinnr = bufwinnr ( t: netrw_lexbufnr ) 858else 859let lexwinnr = 0 860endif 861 862if lexwinnr > 0 863" close down netrw explorer window 864exe lexwinnr . "wincmd w" 865let g: netrw_winsize = - winwidth ( 0 ) 866let t: netrw_lexposn = winsaveview () 867close 868if lexwinnr < curwin 869let curwin = curwin - 1 870endif 871if lexwinnr != curwin 872exe curwin . "wincmd w" 873endif 874unlet t: netrw_lexbufnr 875 876else 877" open netrw explorer window 878exe "1wincmd w" 879let keep_altv = g: netrw_altv 880let g: netrw_altv = 0 881if a: count != 0 882let netrw_winsize = g: netrw_winsize 883let g: netrw_winsize = a: count 884endif 885let curfile = expand ( "%" ) 886exe ( a: rightside ? "botright" : "topleft" ) . " vertical " . (( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize ) . " new" 887if a: 0 > 0 && a1 != "" 888call netrw#Explore ( 0 , 0 , 0 , a1 ) 889exe "Explore " . fnameescape ( a1 ) 890elseif curfile =~ '^\a\{3,}://' 891call netrw#Explore ( 0 , 0 , 0 , substitute ( curfile , '[^/\\]*$' , '' , '' )) 892else 893call netrw#Explore ( 0 , 0 , 0 , "." ) 894endif 895if a: count != 0 896let g: netrw_winsize = netrw_winsize 897endif 898setlocal winfixwidth 899let g: netrw_altv = keep_altv 900let 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. 904set bh = wipe 905if exists ( "t:netrw_lexposn" ) 906call winrestview ( t: netrw_lexposn ) 907unlet t: netrw_lexposn 908endif 909endif 910 911" set up default window for editing via <cr> 912if exists ( "g:netrw_chgwin" ) && g: netrw_chgwin == -1 913if a: rightside 914let g: netrw_chgwin = 1 915else 916let g: netrw_chgwin = 2 917endif 918endif 919 920endfunction 921 922" netrw#MakeTgt: make a target out of the directory name provided {{{2 923function netrw#MakeTgt ( dname ) 924" simplify the target (eg. /abc/def/../ghi -> /abc/ghi) 925let svpos = winsaveview () 926let s: netrwmftgt_islocal = ( a: dname !~ '^\a\{3,}://' ) 927if s: netrwmftgt_islocal 928let netrwmftgt = simplify ( a: dname ) 929else 930let netrwmftgt = a: dname 931endif 932if exists ( "s:netrwmftgt" ) && netrwmftgt == s: netrwmftgt 933" re-selected target, so just clear it 934unlet s: netrwmftgt s: netrwmftgt_islocal 935else 936let s: netrwmftgt = netrwmftgt 937endif 938if g: netrw_fastbrowse <= 1 939call s: NetrwRefresh (( b: netrw_curdir !~ '\a\{3,}://' ), b: netrw_curdir ) 940endif 941call winrestview ( svpos ) 942endfunction 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()) 950function netrw#Obtain ( islocal , fname ,...) 951" NetrwStatusLine support - for obtaining support 952 953if type ( a: fname ) == 1 954let fnamelist = [ a: fname ] 955elseif type ( a: fname ) == 3 956let fnamelist = a: fname 957else 958call netrw#msg#Notify ( 'ERROR' , 'attempting to use NetrwObtain on something not a filename or a list' ) 959return 960endif 961if a: 0 > 0 962let tgtdir = a: 1 963else 964let tgtdir = getcwd () 965endif 966 967if exists ( "b:netrw_islocal" ) && b: netrw_islocal 968" obtain a file from local b:netrw_curdir to (local) tgtdir 969if exists ( "b:netrw_curdir" ) && getcwd () != b: netrw_curdir 970let topath = netrw#fs#ComposePath ( tgtdir , "" ) 971if has ( "win32" ) && ! g: netrw_cygwin 972" transfer files one at time 973for fname in fnamelist 974call system ( g: netrw_localcopycmd . g: netrw_localcopycmdopt . " " . netrw#os#Escape ( fname ) . " " . netrw#os#Escape ( topath )) 975if v: shell_error != 0 976call netrw#msg#Notify ( 'WARNING' , printf ( 'consider setting g:netrw_localcopycmd<%s> to something that works' , g: netrw_localcopycmd )) 977return 978endif 979endfor 980else 981" transfer files with one command 982let filelist = join ( map ( deepcopy ( fnamelist ), "netrw#os#Escape(v:val)" )) 983call system ( g: netrw_localcopycmd . g: netrw_localcopycmdopt . " " . filelist . " " . netrw#os#Escape ( topath )) 984if v: shell_error != 0 985call netrw#msg#Notify ( 'WARNING' , printf ( 'consider setting g:netrw_localcopycmd<%s> to something that works' , g: netrw_localcopycmd )) 986return 987endif 988endif 989elseif ! exists ( "b:netrw_curdir" ) 990call netrw#msg#Notify ( 'ERROR' , "local browsing directory doesn't exist!" ) 991else 992call netrw#msg#Notify ( 'WARNING' , 'local browsing directory and current directory are identical' ) 993endif 994 995else 996" obtain files from remote b:netrw_curdir to local tgtdir 997if type ( a: fname ) == 1 998call s: SetupNetrwStatusLine ( '%f %h%m%r%=%9*Obtaining ' . a: fname ) 999endif 1000call s: NetrwMethod ( b: netrw_curdir ) 1001if ! s: NetrwValidateHostname ( g: netrw_machine ) 1002call netrw#msg#Notify ( 'ERROR' , 'Rejecting invalid hostname: <%s>' , g: netrw_machine ) 1003return 1004endif 1005 1006if b: netrw_method == 4 1007" obtain file using scp 1008if exists ( "g:netrw_port" ) && g: netrw_port != "" 1009let useport = " " . g: netrw_scpport . " " . g: netrw_port 1010else 1011let useport = "" 1012endif 1013if b: netrw_fname =~ '/' 1014let path = substitute ( b: netrw_fname , '^\(.*/\).\{-}$' , '\1' , '' ) 1015else 1016let path = "" 1017endif 1018let filelist = join ( map ( deepcopy ( fnamelist ), 'escape(netrw#os#Escape(g:netrw_machine.":".path.v:val,1)," ")' )) 1019call netrw#os#Execute ( s: netrw_silentxfer . "!" . g: netrw_scp_cmd . netrw#os#Escape ( useport , 1 ) . " " . filelist . " " . netrw#os#Escape ( tgtdir , 1 )) 1020 1021elseif b: netrw_method == 2 1022" obtain file using ftp + .netrc 1023call s: SaveBufVars () |sil NetrwKeepj new|call s:RestoreBufVars() 1024let tmpbufnr = bufnr ( "%" ) 1025setl ff = unix 1026if exists ( "g:netrw_ftpmode" ) && g: netrw_ftpmode != "" 1027NetrwKeepj put =g:netrw_ftpmode 1028endif 1029 1030if exists ( "b:netrw_fname" ) && b: netrw_fname != "" 1031call setline ( line ( "$" ) + 1 , 'cd "' . b: netrw_fname . '"' ) 1032endif 1033 1034if exists ( "g:netrw_ftpextracmd" ) 1035NetrwKeepj put =g:netrw_ftpextracmd 1036endif 1037for fname in fnamelist 1038call setline ( line ( "$" ) + 1 , 'get "' . fname . '"' ) 1039endfor 1040if exists ( "g:netrw_port" ) && g: netrw_port != "" 1041call 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 )) 1042else 1043call netrw#os#Execute ( s: netrw_silentxfer . "%!" . s: netrw_ftp_cmd . " -i " . netrw#os#Escape ( g: netrw_machine , 1 )) 1044endif 1045" If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1046if getline ( 1 ) !~ "^$" && getline ( 1 ) !~ '^Trying ' 1047let debugkeep = & debug 1048setl debug = msg 1049call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 1050let & debug = debugkeep 1051endif 1052 1053elseif b: netrw_method == 3 1054" obtain with ftp + machine, id, passwd, and fname (ie. no .netrc) 1055call s: SaveBufVars () |sil NetrwKeepj new|call s:RestoreBufVars() 1056let tmpbufnr = bufnr ( "%" ) 1057setl ff = unix 1058 1059if exists ( "g:netrw_port" ) && g: netrw_port != "" 1060NetrwKeepj put ='open'.g:netrw_machine.' '.g:netrw_port 1061else 1062NetrwKeepj put ='open '.g:netrw_machine 1063endif 1064 1065if exists ( "g:netrw_uid" ) && g: netrw_uid != "" 1066if exists ( "g:netrw_ftp" ) && g: netrw_ftp == 1 1067NetrwKeepj put =g:netrw_uid 1068if exists ( "s:netrw_passwd" ) && s: netrw_passwd != "" 1069NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 1070endif 1071elseif exists ( "s:netrw_passwd" ) 1072NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 1073endif 1074endif 1075 1076if exists ( "g:netrw_ftpmode" ) && g: netrw_ftpmode != "" 1077NetrwKeepj put =g:netrw_ftpmode 1078endif 1079 1080if exists ( "b:netrw_fname" ) && b: netrw_fname != "" 1081NetrwKeepj call setline(line("$")+1,'cd"'.b:netrw_fname.'" ') 1082endif 1083 1084if exists ( "g:netrw_ftpextracmd" ) 1085NetrwKeepj put =g:netrw_ftpextracmd 1086endif 1087 1088if exists ( "g:netrw_ftpextracmd" ) 1089NetrwKeepj put =g:netrw_ftpextracmd 1090endif 1091for fname in fnamelist 1092NetrwKeepj call setline(line("$")+1,'get"'.fname.'" ') 1093endfor 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 @@ 1100NetrwKeepj norm! 1G"_dd 1101call 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) 1103if getline ( 1 ) !~ "^$" 1104call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 1105endif 1106 1107elseif b: netrw_method == 9 1108" obtain file using sftp 1109if a: fname =~ '/' 1110let localfile = substitute ( a: fname , '^.*/' , '' , '' ) 1111else 1112let localfile = a: fname 1113endif 1114call 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 1116elseif ! exists ( "b:netrw_method" ) || b: netrw_method < 0 1117" probably a badly formed url; protocol not recognized 1118return 1119 1120else 1121" protocol recognized but not supported for Obtain (yet?) 1122call netrw#msg#Notify ( 'ERROR' , 'current protocol not supported for obtaining file' ) 1123return 1124endif 1125 1126" restore status line 1127if type ( a: fname ) == 1 && exists ( "s:netrw_users_stl" ) 1128NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl) 1129endif 1130 1131endif 1132 1133" cleanup 1134if exists ( "tmpbufnr" ) 1135if bufnr ( "%" ) != tmpbufnr 1136exe tmpbufnr . "bw!" 1137else 1138q ! 1139endif 1140endif 1141 1142endfunction 1143 1144" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2 1145function netrw#Nread ( mode , fname ) 1146let svpos = winsaveview () 1147call netrw#NetRead ( a: mode , a: fname ) 1148call winrestview ( svpos ) 1149 1150if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle != s: TREELIST 1151if exists ( "w:netrw_bannercnt" ) 1152" start with cursor just after the banner 1153exe w: netrw_bannercnt 1154endif 1155endif 1156endfunction 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:" 1168function s: NetrwOptionsSave ( vt ) 1169 1170if ! exists ( "{a:vt}netrw_optionsave" ) 1171let { a: vt } netrw_optionsave = 1 1172else 1173return 1174endif 1175 1176" Save current settings and current directory 1177let s: yykeep = @@ 1178if exists ( "&l:acd" ) |let { a: vt } netrw_acdkeep = & l: acd |endif 1179let { a: vt } netrw_aikeep = & l: ai 1180let { a: vt } netrw_awkeep = & l: aw 1181let { a: vt } netrw_bhkeep = & l: bh 1182let { a: vt } netrw_blkeep = & l: bl 1183let { a: vt } netrw_btkeep = & l: bt 1184let { a: vt } netrw_bombkeep = & l: bomb 1185let { a: vt } netrw_cedit = & cedit 1186let { a: vt } netrw_cikeep = & l: ci 1187let { a: vt } netrw_cinkeep = & l: cin 1188let { a: vt } netrw_cinokeep = & l: cino 1189let { a: vt } netrw_comkeep = & l: com 1190let { a: vt } netrw_cpokeep = & l: cpo 1191let { a: vt } netrw_cuckeep = & l: cuc 1192let { a: vt } netrw_culkeep = & l: cul 1193let { a: vt } netrw_diffkeep = & l: diff 1194let { a: vt } netrw_fenkeep = & l: fen 1195if ! exists ( "g:netrw_ffkeep" ) || g: netrw_ffkeep 1196let { a: vt } netrw_ffkeep = & l: ff 1197endif 1198let { a: vt } netrw_fokeep = & l: fo " formatoptions 1199let { a: vt } netrw_gdkeep = & l: gd " gdefault 1200let { a: vt } netrw_gokeep = & go " guioptions 1201let { a: vt } netrw_hidkeep = & l: hidden 1202let { a: vt } netrw_imkeep = & l: im 1203let { a: vt } netrw_iskkeep = & l: isk 1204let { a: vt } netrw_lines = & lines 1205let { a: vt } netrw_lskeep = & l: ls 1206let { a: vt } netrw_makeep = & l: ma 1207let { a: vt } netrw_magickeep = & l: magic 1208let { a: vt } netrw_modkeep = & l: mod 1209let { a: vt } netrw_nukeep = & l: nu 1210let { a: vt } netrw_rnukeep = & l: rnu 1211let { a: vt } netrw_repkeep = & l: report 1212let { a: vt } netrw_rokeep = & l: ro 1213let { a: vt } netrw_selkeep = & l: sel 1214let { a: vt } netrw_spellkeep = & l: spell 1215if ! g: netrw_use_noswf 1216let { a: vt } netrw_swfkeep = & l: swf 1217endif 1218let { a: vt } netrw_tskeep = & l: ts 1219let { a: vt } netrw_twkeep = & l: tw " textwidth 1220let { a: vt } netrw_wigkeep = & l: wig " wildignore 1221let { a: vt } netrw_wrapkeep = & l: wrap 1222let { a: vt } netrw_writekeep = & l: write 1223 1224" save a few selected netrw-related variables 1225if g: netrw_keepdir 1226let { a: vt } netrw_dirkeep = getcwd () 1227endif 1228if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 1229sil ! let { a: vt } netrw_starkeep = @* 1230sil ! let { a: vt } netrw_pluskeep = @+ 1231endif 1232sil ! let { a: vt } netrw_slashkeep = @/ 1233 1234endfunction 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 1239function s: NetrwOptionsSafe ( islocal ) 1240if exists ( "+acd" ) |call s: NetrwSetSafeSetting ( "&l:acd" , 0 ) |endif 1241call s: NetrwSetSafeSetting ( "&l:ai" , 0 ) 1242call s: NetrwSetSafeSetting ( "&l:aw" , 0 ) 1243call s: NetrwSetSafeSetting ( "&l:bl" , 0 ) 1244call s: NetrwSetSafeSetting ( "&l:bomb" , 0 ) 1245if a: islocal 1246call s: NetrwSetSafeSetting ( "&l:bt" , "nofile" ) 1247else 1248call s: NetrwSetSafeSetting ( "&l:bt" , "acwrite" ) 1249endif 1250call s: NetrwSetSafeSetting ( "&l:ci" , 0 ) 1251call s: NetrwSetSafeSetting ( "&l:cin" , 0 ) 1252if g: netrw_fastbrowse > a: islocal 1253call s: NetrwSetSafeSetting ( "&l:bh" , "hide" ) 1254else 1255call s: NetrwSetSafeSetting ( "&l:bh" , "delete" ) 1256endif 1257call s: NetrwSetSafeSetting ( "&l:cino" , "" ) 1258call s: NetrwSetSafeSetting ( "&l:com" , "" ) 1259if & cpo =~ 'a' |call s: NetrwSetSafeSetting ( "&cpo" , substitute ( & cpo , 'a' , '' , 'g' )) |endif 1260if & cpo =~ 'A' |call s: NetrwSetSafeSetting ( "&cpo" , substitute ( & cpo , 'A' , '' , 'g' )) |endif 1261setl fo = nroql2 1262if & go =~ 'a' |set go -= a |endif 1263if & go =~ 'A' |set go -= A |endif 1264if & go =~ 'P' |set go -= P |endif 1265call s: NetrwSetSafeSetting ( "&l:hid" , 0 ) 1266call s: NetrwSetSafeSetting ( "&l:im" , 0 ) 1267setl isk += @isk += *isk += / 1268call s: NetrwSetSafeSetting ( "&l:magic" , 1 ) 1269if g: netrw_use_noswf 1270call s: NetrwSetSafeSetting ( "swf" , 0 ) 1271endif 1272call s: NetrwSetSafeSetting ( "&l:report" , 10000 ) 1273call s: NetrwSetSafeSetting ( "&l:sel" , "inclusive" ) 1274call s: NetrwSetSafeSetting ( "&l:spell" , 0 ) 1275call s: NetrwSetSafeSetting ( "&l:tw" , 0 ) 1276call s: NetrwSetSafeSetting ( "&l:wig" , "" ) 1277setl cedit & 1278 1279" set up cuc and cul based on g:netrw_cursor and listing style 1280" COMBAK -- cuc cul related 1281call s: NetrwCursor ( 0 ) 1282 1283" allow the user to override safe options 1284if & ft == "netrw" 1285keepalt NetrwKeepj doau FileType netrw 1286endif 1287 1288endfunction 1289 1290" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2 1291function s: NetrwOptionsRestore ( vt ) 1292if ! 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 1295if filereadable ( expand ( "%" )) || expand ( "%" ) =~# '^\w\+://\f\+' 1296filetype detect 1297else 1298setl ft = netrw 1299endif 1300return 1301endif 1302unlet { a: vt } netrw_optionsave 1303 1304if exists ( "+acd" ) 1305if exists ( "{a:vt}netrw_acdkeep" ) 1306let curdir = getcwd () 1307let & l: acd = { a: vt } netrw_acdkeep 1308unlet { a: vt } netrw_acdkeep 1309if & l: acd 1310call s: NetrwLcd ( curdir ) 1311endif 1312endif 1313endif 1314call s: NetrwRestoreSetting ( a: vt . "netrw_aikeep" , "&l:ai" ) 1315call s: NetrwRestoreSetting ( a: vt . "netrw_awkeep" , "&l:aw" ) 1316call s: NetrwRestoreSetting ( a: vt . "netrw_blkeep" , "&l:bl" ) 1317call s: NetrwRestoreSetting ( a: vt . "netrw_btkeep" , "&l:bt" ) 1318call s: NetrwRestoreSetting ( a: vt . "netrw_bombkeep" , "&l:bomb" ) 1319call s: NetrwRestoreSetting ( a: vt . "netrw_cedit" , "&cedit" ) 1320call s: NetrwRestoreSetting ( a: vt . "netrw_cikeep" , "&l:ci" ) 1321call s: NetrwRestoreSetting ( a: vt . "netrw_cinkeep" , "&l:cin" ) 1322call s: NetrwRestoreSetting ( a: vt . "netrw_cinokeep" , "&l:cino" ) 1323call s: NetrwRestoreSetting ( a: vt . "netrw_comkeep" , "&l:com" ) 1324call s: NetrwRestoreSetting ( a: vt . "netrw_cpokeep" , "&l:cpo" ) 1325call s: NetrwRestoreSetting ( a: vt . "netrw_diffkeep" , "&l:diff" ) 1326call s: NetrwRestoreSetting ( a: vt . "netrw_fenkeep" , "&l:fen" ) 1327if exists ( "g:netrw_ffkeep" ) && g: netrw_ffkeep 1328call s: NetrwRestoreSetting ( a: vt . "netrw_ffkeep" ) ","&l:ff") 1329endif 1330call s: NetrwRestoreSetting ( a: vt . "netrw_fokeep" , "&l:fo" ) 1331call s: NetrwRestoreSetting ( a: vt . "netrw_gdkeep" , "&l:gd" ) 1332call s: NetrwRestoreSetting ( a: vt . "netrw_gokeep" , "&go" ) 1333call s: NetrwRestoreSetting ( a: vt . "netrw_hidkeep" , "&l:hidden" ) 1334call s: NetrwRestoreSetting ( a: vt . "netrw_imkeep" , "&l:im" ) 1335call s: NetrwRestoreSetting ( a: vt . "netrw_iskkeep" , "&l:isk" ) 1336call s: NetrwRestoreSetting ( a: vt . "netrw_lines" , "&lines" ) 1337call s: NetrwRestoreSetting ( a: vt . "netrw_lskeep" , "&l:ls" ) 1338call s: NetrwRestoreSetting ( a: vt . "netrw_makeep" , "&l:ma" ) 1339call s: NetrwRestoreSetting ( a: vt . "netrw_magickeep" , "&l:magic" ) 1340call s: NetrwRestoreSetting ( a: vt . "netrw_modkeep" , "&l:mod" ) 1341call s: NetrwRestoreSetting ( a: vt . "netrw_nukeep" , "&l:nu" ) 1342call s: NetrwRestoreSetting ( a: vt . "netrw_rnukeep" , "&l:rnu" ) 1343call s: NetrwRestoreSetting ( a: vt . "netrw_repkeep" , "&l:report" ) 1344call s: NetrwRestoreSetting ( a: vt . "netrw_rokeep" , "&l:ro" ) 1345call s: NetrwRestoreSetting ( a: vt . "netrw_selkeep" , "&l:sel" ) 1346call s: NetrwRestoreSetting ( a: vt . "netrw_spellkeep" , "&l:spell" ) 1347call s: NetrwRestoreSetting ( a: vt . "netrw_twkeep" , "&l:tw" ) 1348call s: NetrwRestoreSetting ( a: vt . "netrw_wigkeep" , "&l:wig" ) 1349call s: NetrwRestoreSetting ( a: vt . "netrw_wrapkeep" , "&l:wrap" ) 1350call s: NetrwRestoreSetting ( a: vt . "netrw_writekeep" , "&l:write" ) 1351call 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) 1355call s: NetrwRestoreSetting ( a: vt . "netrw_tskeep" , "&l:ts" ) 1356 1357if exists ( "{a:vt}netrw_swfkeep" ) 1358if & 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(). 1362let & l: directory = getcwd () 1363sil ! let & l: swf = { a: vt } netrw_swfkeep 1364setl directory = 1365unlet { a: vt } netrw_swfkeep 1366elseif & l: swf != { a: vt } netrw_swfkeep 1367if ! g: netrw_use_noswf 1368" following line causes a Press ENTER in windows -- can't seem to work around it!!! 1369sil ! let & l: swf = { a: vt } netrw_swfkeep 1370endif 1371unlet { a: vt } netrw_swfkeep 1372endif 1373endif 1374if exists ( "{a:vt}netrw_dirkeep" ) && isdirectory ( s: NetrwFile ( { a: vt } netrw_dirkeep )) && g: netrw_keepdir 1375let dirkeep = substitute ( { a: vt } netrw_dirkeep , '\\' , '/' , 'g' ) 1376if exists ( "{a:vt}netrw_dirkeep" ) 1377call s: NetrwLcd ( dirkeep ) 1378unlet { a: vt } netrw_dirkeep 1379endif 1380endif 1381if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 1382call s: NetrwRestoreSetting ( a: vt . "netrw_starkeep" , "@*" ) 1383call s: NetrwRestoreSetting ( a: vt . "netrw_pluskeep" , "@+" ) 1384endif 1385call 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. 1390if & ft != "netrw" 1391filetype detect 1392endif 1393endfunction 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") 1402function s: NetrwSetSafeSetting ( setting , safesetting ) 1403 1404if a: setting =~ '^&' 1405exe "let settingval= " . a: setting 1406 1407if settingval != a: safesetting 1408if type ( a: safesetting ) == 0 1409exe "let " . a: setting . "=" . a: safesetting 1410elseif type ( a: safesetting ) == 1 1411exe "let " . a: setting . "= '" . a: safesetting . "'" 1412else 1413call 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 ))) 1414endif 1415endif 1416endif 1417 1418endfunction 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 1427function 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 1433if exists ( a: keepvar ) 1434exe "let keepvarval= " . a: keepvar 1435exe "let setting= " . a: setting 1436 1437 1438if setting != keepvarval 1439if type ( a: setting ) == 0 1440exe "let " . a: setting . "= " . keepvarval 1441elseif type ( a: setting ) == 1 1442exe "let " . a: setting . "= '" . substitute ( keepvarval , "'" , "''" , "g" ) . "'" 1443else 1444call 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 ))) 1445endif 1446endif 1447 1448exe "unlet " . a: keepvar 1449endif 1450 1451endfunction 1452 1453" NetrwStatusLine: {{{2 1454 1455function NetrwStatusLine () 1456if ! 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" ) 1457let & stl = s: netrw_explore_stl 1458unlet ! w: netrw_explore_bufnr w: netrw_explore_line 1459return "" 1460else 1461return "Match " . w: netrw_explore_mtchcnt . " of " . w: netrw_explore_listlen 1462endif 1463endfunction 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 1472function netrw#NetRead ( mode ,...) 1473 1474" NetRead: save options {{{3 1475call s: NetrwOptionsSave ( "w:" ) 1476call s: NetrwOptionsSafe ( 0 ) 1477call 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. 1480setl bl 1481 1482" NetRead: interpret mode into a readcmd {{{3 1483if a: mode == 0 " read remote file before current line 1484let readcmd = "0r" 1485elseif a: mode == 1 " read file after current line 1486let readcmd = "r" 1487elseif a: mode == 2 " replace with remote file 1488let readcmd = "%r" 1489elseif a: mode == 3 " skip read of file (leave as temporary) 1490let readcmd = "t" 1491else 1492exe a: mode 1493let readcmd = "r" 1494endif 1495let ichoice = ( a: 0 == 0 ) ? 0 : 1 1496 1497" NetRead: get temporary filename {{{3 1498let tmpfile = s: GetTempfile ( "" ) 1499if tmpfile == "" 1500return 1501endif 1502 1503while ichoice <= a: 0 1504 1505" attempt to repeat with previous host-file-etc 1506if exists ( "b:netrw_lastfile" ) && a: 0 == 0 1507let choice = b: netrw_lastfile 1508let ichoice = ichoice + 1 1509 1510else 1511exe "let choice= a:" . ichoice 1512 1513if match ( choice , "?" ) == 0 1514" give help 1515echomsg 'NetRead Usage:' 1516echomsg ':Nread machine:path uses rcp' 1517echomsg ':Nread "machine path" uses ftp with <.netrc>' 1518echomsg ':Nread "machine id password path" uses ftp' 1519echomsg ':Nread dav://machine[:port]/path uses cadaver' 1520echomsg ':Nread fetch://machine/path uses fetch' 1521echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' 1522echomsg ':Nread http://[user@]machine/path uses http wget' 1523echomsg ':Nread file:///path uses elinks' 1524echomsg ':Nread https://[user@]machine/path uses http wget' 1525echomsg ':Nread rcp://[user@]machine/path uses rcp' 1526echomsg ':Nread rsync://machine[:port]/path uses rsync' 1527echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp' 1528echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' 1529sleep 4 1530break 1531 1532elseif match ( choice , '^"' ) != -1 1533" Reconstruct Choice if choice starts with '"' 1534if match ( choice , '"$' ) != -1 1535" case "..." 1536let choice = strpart ( choice , 1 , strlen ( choice ) - 2 ) 1537else 1538" case "... ... ..." 1539let choice = strpart ( choice , 1 , strlen ( choice ) - 1 ) 1540let wholechoice = "" 1541 1542while match ( choice , '"$' ) == -1 1543let wholechoice = wholechoice . " " . choice 1544let ichoice = ichoice + 1 1545if ichoice > a: 0 1546call netrw#msg#Notify ( 'ERROR' , printf ( 'Unbalanced string in filename "%s"' , wholechoice )) 1547return 1548endif 1549let choice = a: {ichoice} 1550endwhile 1551let choice = strpart ( wholechoice , 1 , strlen ( wholechoice ) - 1 ) . " " . strpart ( choice , 0 , strlen ( choice ) - 1 ) 1552endif 1553endif 1554endif 1555 1556let ichoice = ichoice + 1 1557 1558" NetRead: Determine method of read (ftp, rcp, etc) {{{3 1559call s: NetrwMethod ( choice ) 1560if ! exists ( "b:netrw_method" ) || b: netrw_method < 0 1561return 1562endif 1563if ! s: NetrwValidateHostname ( g: netrw_machine ) 1564call netrw#msg#Notify ( 'ERROR' , printf ( 'Rejecting invalid hostname: <%s>' , g: netrw_machine )) 1565return 1566endif 1567let tmpfile = s: GetTempfile ( b: netrw_fname ) " apply correct suffix 1568 1569" Check whether or not NetrwBrowse() should be handling this request 1570if choice =~ "^.*[\/]$" && b: netrw_method != 5 && choice !~ '^https\=://' 1571NetrwKeepj call s:NetrwBrowse(0,choice) 1572return 1573endif 1574 1575" ============ 1576" NetRead: Perform Protocol-Based Read {{{3 1577" =========================== 1578if exists ( "g:netrw_silent" ) && g: netrw_silent == 0 && & ch >= 1 1579echo "(netrw) Processing your read request..." 1580endif 1581 1582"......................................... 1583" NetRead: (rcp) NetRead Method #1 {{{3 1584if 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 1589if s: netrw_has_nt_rcp == 1 1590if exists ( "g:netrw_uid" ) && ( g: netrw_uid != "" ) 1591let uid_machine = g: netrw_machine . '.' . g: netrw_uid 1592else 1593" Any way needed it machine contains a '.' 1594let uid_machine = g: netrw_machine . '.' . $ USERNAME 1595endif 1596else 1597if exists ( "g:netrw_uid" ) && ( g: netrw_uid != "" ) 1598let uid_machine = g: netrw_uid . '@' . g: netrw_machine 1599else 1600let uid_machine = g: netrw_machine 1601endif 1602endif 1603call 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 )) 1604let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1605let b: netrw_lastfile = choice 1606 1607"......................................... 1608" NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3 1609elseif b: netrw_method == 2 " read with ftp + <.netrc> 1610let netrw_fname = b: netrw_fname 1611NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars() 1612let filtbuf = bufnr ( "%" ) 1613setl ff = unix 1614NetrwKeepj put =g:netrw_ftpmode 1615if exists ( "g:netrw_ftpextracmd" ) 1616NetrwKeepj put =g:netrw_ftpextracmd 1617endif 1618call setline ( line ( "$" ) + 1 , 'get "' . netrw_fname . '" ' . tmpfile ) 1619if exists ( "g:netrw_port" ) && g: netrw_port != "" 1620call 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 )) 1621else 1622call netrw#os#Execute ( s: netrw_silentxfer . "%!" . s: netrw_ftp_cmd . " -i " . netrw#os#Escape ( g: netrw_machine , 1 )) 1623endif 1624" If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1625if getline ( 1 ) !~ "^$" && getline ( 1 ) !~ '^Trying ' 1626let debugkeep = & debug 1627setl debug = msg 1628call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 1629let & debug = debugkeep 1630endif 1631call s: SaveBufVars () 1632keepj bd! 1633if bufname ( "%" ) == "" && getline ( "$" ) == "" && line ( '$' ) == 1 1634" needed when one sources a file in a nolbl setting window via ftp 1635q ! 1636endif 1637call s: RestoreBufVars () 1638let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1639let b: netrw_lastfile = choice 1640 1641"......................................... 1642" NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3 1643elseif b: netrw_method == 3 " read with ftp + machine, id, passwd, and fname 1644" Construct execution string (four lines) which will be passed through filter 1645let netrw_fname = escape ( b: netrw_fname , g: netrw_fname_escape ) 1646NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars() 1647let filtbuf = bufnr ( "%" ) 1648setl ff = unix 1649if exists ( "g:netrw_port" ) && g: netrw_port != "" 1650NetrwKeepj put ='open'.g:netrw_machine.' '.g:netrw_port 1651else 1652NetrwKeepj put ='open '.g:netrw_machine 1653endif 1654 1655if exists ( "g:netrw_uid" ) && g: netrw_uid != "" 1656if exists ( "g:netrw_ftp" ) && g: netrw_ftp == 1 1657NetrwKeepj put =g:netrw_uid 1658if exists ( "s:netrw_passwd" ) 1659NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 1660endif 1661elseif exists ( "s:netrw_passwd" ) 1662NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 1663endif 1664endif 1665 1666if exists ( "g:netrw_ftpmode" ) && g: netrw_ftpmode != "" 1667NetrwKeepj put =g:netrw_ftpmode 1668endif 1669if exists ( "g:netrw_ftpextracmd" ) 1670NetrwKeepj put =g:netrw_ftpextracmd 1671endif 1672NetrwKeepj 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 1678NetrwKeepj norm! 1G"_dd 1679call 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) 1681if getline ( 1 ) !~ "^$" 1682call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 1683endif 1684call s: SaveBufVars () |keepj bd!|call s:RestoreBufVars() 1685let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1686let b: netrw_lastfile = choice 1687 1688"......................................... 1689" NetRead: (scp) NetRead Method #4 {{{3 1690elseif b: netrw_method == 4 " read with scp 1691if exists ( "g:netrw_port" ) && g: netrw_port != "" 1692let useport = " " . g: netrw_scpport . " " . g: netrw_port 1693else 1694let useport = "" 1695endif 1696" Using UNC notation in windows to get a unix like path. 1697" This is workaround to avoid mis-handle windows local-path: 1698if g: netrw_scp_cmd =~ '^scp' && has ( "win32" ) 1699let tmpfile_get = substitute ( tr ( tmpfile , '\' , '/' ), '^\(\a\):[/\\]\(.*\)$' , '//' .. $ COMPUTERNAME .. '/\1$/\2' , '' ) 1700else 1701let tmpfile_get = tmpfile 1702endif 1703call 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 )) 1704let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1705let b: netrw_lastfile = choice 1706 1707"......................................... 1708" NetRead: (http) NetRead Method #5 (wget) {{{3 1709elseif b: netrw_method == 5 1710if g: netrw_http_cmd == "" 1711call netrw#msg#Notify ( 'ERROR' , 'neither the wget nor the fetch command is available' ) 1712return 1713endif 1714 1715if match ( b: netrw_fname , "#" ) == -1 || exists ( "g:netrw_http_xcmd" ) 1716" using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch) 1717if exists ( "g:netrw_http_xcmd" ) 1718call 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 )) 1719else 1720call 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 )) 1721endif 1722let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1723 1724else 1725" wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) 1726let netrw_html = substitute ( b: netrw_fname , "#.*$" , "" , "" ) 1727let netrw_tag = substitute ( b: netrw_fname , "^.*#" , "" , "" ) 1728call 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 )) 1729let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1730exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"' . netrw_tag . '"/' . "\<CR>" 1731endif 1732let b: netrw_lastfile = choice 1733setl ro nomod 1734 1735"......................................... 1736" NetRead: (dav) NetRead Method #6 {{{3 1737elseif b: netrw_method == 6 1738 1739if ! executable ( g: netrw_dav_cmd ) 1740call netrw#msg#Notify ( 'ERROR' , printf ( '%s is not executable' , g: netrw_dav_cmd )) 1741return 1742endif 1743if g: netrw_dav_cmd =~ "curl" 1744call 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 )) 1745else 1746" Construct execution string (four lines) which will be passed through filter 1747let netrw_fname = escape ( b: netrw_fname , g: netrw_fname_escape ) 1748new 1749setl ff = unix 1750if exists ( "g:netrw_port" ) && g: netrw_port != "" 1751NetrwKeepj put ='open'.g:netrw_machine.' '.g:netrw_port 1752else 1753NetrwKeepj put ='open '.g:netrw_machine 1754endif 1755if exists ( "g:netrw_uid" ) && exists ( "s:netrw_passwd" ) && g: netrw_uid != "" 1756NetrwKeepj put ='user'.g:netrw_uid.' '.s:netrw_passwd 1757endif 1758NetrwKeepj put ='get'.netrw_fname.' '.tmpfile 1759NetrwKeepj put ='quit' 1760 1761" perform cadaver operation: 1762NetrwKeepj norm! 1G"_dd 1763call netrw#os#Execute ( s: netrw_silentxfer . "%!" . g: netrw_dav_cmd ) 1764keepj bd! 1765endif 1766let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1767let b: netrw_lastfile = choice 1768 1769"......................................... 1770" NetRead: (rsync) NetRead Method #7 {{{3 1771elseif b: netrw_method == 7 1772call 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 )) 1773let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1774let b: netrw_lastfile = choice 1775 1776"......................................... 1777" NetRead: (fetch) NetRead Method #8 {{{3 1778" fetch://[user@]host[:http]/path 1779elseif b: netrw_method == 8 1780if g: netrw_fetch_cmd == "" 1781call netrw#msg#Notify ( 'ERROR' , "fetch command not available" ) 1782return 1783endif 1784if exists ( "g:netrw_option" ) && g: netrw_option =~ ":https\=" 1785let netrw_option = "http" 1786else 1787let netrw_option = "ftp" 1788endif 1789 1790if exists ( "g:netrw_uid" ) && g: netrw_uid != "" && exists ( "s:netrw_passwd" ) && s: netrw_passwd != "" 1791call 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 )) 1792else 1793call 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 )) 1794endif 1795 1796let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1797let b: netrw_lastfile = choice 1798setl ro nomod 1799 1800"......................................... 1801" NetRead: (sftp) NetRead Method #9 {{{3 1802elseif b: netrw_method == 9 1803call 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 )) 1804let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1805let b: netrw_lastfile = choice 1806 1807"......................................... 1808" NetRead: (file) NetRead Method #10 {{{3 1809elseif b: netrw_method == 10 && exists ( "g:netrw_file_cmd" ) 1810call netrw#os#Execute ( s: netrw_silentxfer . "!" . g: netrw_file_cmd . " " . netrw#os#Escape ( b: netrw_fname , 1 ) . " " . netrw#os#Escape ( tmpfile , 1 )) 1811let result = s: NetrwGetFile ( readcmd , tmpfile , b: netrw_method ) 1812let b: netrw_lastfile = choice 1813 1814"......................................... 1815" NetRead: Complain {{{3 1816else 1817call netrw#msg#Notify ( 'WARNING' , printf ( 'unable to comply with your request<%s>' , choice )) 1818endif 1819endwhile 1820 1821" NetRead: cleanup {{{3 1822if exists ( "b:netrw_method" ) 1823unlet b: netrw_method 1824unlet b: netrw_fname 1825endif 1826if s: FileReadable ( tmpfile ) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz' 1827call netrw#fs#Remove ( tmpfile ) 1828endif 1829NetrwKeepj call s:NetrwOptionsRestore("w:") 1830 1831endfunction 1832 1833" netrw#NetWrite: responsible for writing a file over the net {{{2 1834function netrw#NetWrite (...) range 1835 1836" NetWrite: option handling {{{3 1837let mod = 0 1838call s: NetrwOptionsSave ( "w:" ) 1839call s: NetrwOptionsSafe ( 0 ) 1840 1841" NetWrite: Get Temporary Filename {{{3 1842let tmpfile = s: GetTempfile ( "" ) 1843if tmpfile == "" 1844return 1845endif 1846 1847if a: 0 == 0 1848let ichoice = 0 1849else 1850let ichoice = 1 1851endif 1852 1853let curbufname = expand ( "%" ) 1854if & 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. 1858exe "sil NetrwKeepj w! " . fnameescape ( v: cmdarg ) . " " . fnameescape ( tmpfile ) 1859elseif g: netrw_cygwin 1860" write (selected portion of) file to temporary 1861let cygtmpfile = substitute ( tmpfile , g: netrw_cygdrive . '/\(.\)' , '\1:' , '' ) 1862exe "sil NetrwKeepj " . a: firstline . "," . a: lastline . "w! " . fnameescape ( v: cmdarg ) . " " . fnameescape ( cygtmpfile ) 1863else 1864" write (selected portion of) file to temporary 1865exe "sil NetrwKeepj " . a: firstline . "," . a: lastline . "w! " . fnameescape ( v: cmdarg ) . " " . fnameescape ( tmpfile ) 1866endif 1867 1868if 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. 18720 file ! 1873endif 1874 1875" NetWrite: while choice loop: {{{3 1876while ichoice <= a: 0 1877 1878" Process arguments: {{{4 1879" attempt to repeat with previous host-file-etc 1880if exists ( "b:netrw_lastfile" ) && a: 0 == 0 1881let choice = b: netrw_lastfile 1882let ichoice = ichoice + 1 1883else 1884exe "let choice= a:" . ichoice 1885 1886" Reconstruct Choice when choice starts with '"' 1887if match ( choice , "?" ) == 0 1888echomsg 'NetWrite Usage:"' 1889echomsg ':Nwrite machine:path uses rcp' 1890echomsg ':Nwrite "machine path" uses ftp with <.netrc>' 1891echomsg ':Nwrite "machine id password path" uses ftp' 1892echomsg ':Nwrite dav://[user@]machine/path uses cadaver' 1893echomsg ':Nwrite fetch://[user@]machine/path uses fetch' 1894echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' 1895echomsg ':Nwrite rcp://machine/path uses rcp' 1896echomsg ':Nwrite rsync://[user@]machine/path uses rsync' 1897echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' 1898echomsg ':Nwrite sftp://[user@]machine/path uses sftp' 1899sleep 4 1900break 1901 1902elseif match ( choice , "^\"" ) != -1 1903if match ( choice , "\"$" ) != -1 1904" case "..." 1905let choice = strpart ( choice , 1 , strlen ( choice ) - 2 ) 1906else 1907" case "... ... ..." 1908let choice = strpart ( choice , 1 , strlen ( choice ) - 1 ) 1909let wholechoice = "" 1910 1911while match ( choice , "\"$" ) == -1 1912let wholechoice = wholechoice . " " . choice 1913let ichoice = ichoice + 1 1914if choice > a: 0 1915call netrw#msg#Notify ( 'ERROR' , printf ( 'Unbalanced string in filename "%s"' , wholechoice )) 1916return 1917endif 1918let choice = a: {ichoice} 1919endwhile 1920let choice = strpart ( wholechoice , 1 , strlen ( wholechoice ) - 1 ) . " " . strpart ( choice , 0 , strlen ( choice ) - 1 ) 1921endif 1922endif 1923endif 1924let ichoice = ichoice + 1 1925 1926" Determine method of write (ftp, rcp, etc) {{{4 1927NetrwKeepj call s:NetrwMethod(choice) 1928if ! exists ( "b:netrw_method" ) || b: netrw_method < 0 1929return 1930endif 1931if ! s: NetrwValidateHostname ( g: netrw_machine ) 1932call netrw#msg#Notify ( 'ERROR' , printf ( 'Rejecting invalid hostname: <%s>' , g: netrw_machine )) 1933return 1934endif 1935 1936" ============= 1937" NetWrite: Perform Protocol-Based Write {{{3 1938" ============================ 1939if exists ( "g:netrw_silent" ) && g: netrw_silent == 0 && & ch >= 1 1940echo "(netrw) Processing your write request..." 1941endif 1942 1943"......................................... 1944" NetWrite: (rcp) NetWrite Method #1 {{{3 1945if b: netrw_method == 1 1946if s: netrw_has_nt_rcp == 1 1947if exists ( "g:netrw_uid" ) && ( g: netrw_uid != "" ) 1948let uid_machine = g: netrw_machine . '.' . g: netrw_uid 1949else 1950let uid_machine = g: netrw_machine . '.' . $ USERNAME 1951endif 1952else 1953if exists ( "g:netrw_uid" ) && ( g: netrw_uid != "" ) 1954let uid_machine = g: netrw_uid . '@' . g: netrw_machine 1955else 1956let uid_machine = g: netrw_machine 1957endif 1958endif 1959call 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 )) 1960let b: netrw_lastfile = choice 1961 1962"......................................... 1963" NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3 1964elseif b: netrw_method == 2 1965let netrw_fname = b: netrw_fname 1966 1967" formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 1968let bhkeep = & l: bh 1969let curbuf = bufnr ( "%" ) 1970setl bh = hide 1971keepj keepalt enew 1972 1973setl ff = unix 1974NetrwKeepj put =g:netrw_ftpmode 1975if exists ( "g:netrw_ftpextracmd" ) 1976NetrwKeepj put =g:netrw_ftpextracmd 1977endif 1978NetrwKeepj call setline(line("$")+1,'put"'.tmpfile.'" "'.netrw_fname.'" ') 1979if exists ( "g:netrw_port" ) && g: netrw_port != "" 1980call 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 )) 1981else 1982call netrw#os#Execute ( s: netrw_silentxfer . "%!" . s: netrw_ftp_cmd . " -i " . netrw#os#Escape ( g: netrw_machine , 1 )) 1983endif 1984" If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 1985if getline ( 1 ) !~ "^$" 1986call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 1987let mod = 1 1988endif 1989 1990" remove enew buffer (quietly) 1991let filtbuf = bufnr ( "%" ) 1992exe curbuf . "b!" 1993let & l: bh = bhkeep 1994exe filtbuf . "bw!" 1995 1996let b: netrw_lastfile = choice 1997 1998"......................................... 1999" NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3 2000elseif b: netrw_method == 3 2001" Construct execution string (three or more lines) which will be passed through filter 2002let netrw_fname = b: netrw_fname 2003let bhkeep = & l: bh 2004 2005" formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2006let curbuf = bufnr ( "%" ) 2007setl bh = hide 2008keepj keepalt enew 2009setl ff = unix 2010 2011if exists ( "g:netrw_port" ) && g: netrw_port != "" 2012NetrwKeepj put ='open'.g:netrw_machine.' '.g:netrw_port 2013else 2014NetrwKeepj put ='open '.g:netrw_machine 2015endif 2016if exists ( "g:netrw_uid" ) && g: netrw_uid != "" 2017if exists ( "g:netrw_ftp" ) && g: netrw_ftp == 1 2018NetrwKeepj put =g:netrw_uid 2019if exists ( "s:netrw_passwd" ) && s: netrw_passwd != "" 2020NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 2021endif 2022elseif exists ( "s:netrw_passwd" ) && s: netrw_passwd != "" 2023NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 2024endif 2025endif 2026NetrwKeepj put =g:netrw_ftpmode 2027if exists ( "g:netrw_ftpextracmd" ) 2028NetrwKeepj put =g:netrw_ftpextracmd 2029endif 2030NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"' 2031" save choice/id/password for future use 2032let 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 2038NetrwKeepj norm! 1G"_dd 2039call 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) 2041if getline ( 1 ) !~ "^$" 2042call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 2043let mod = 1 2044endif 2045 2046" remove enew buffer (quietly) 2047let filtbuf = bufnr ( "%" ) 2048exe curbuf . "b!" 2049let & l: bh = bhkeep 2050exe filtbuf . "bw!" 2051 2052"......................................... 2053" NetWrite: (scp) NetWrite Method #4 {{{3 2054elseif b: netrw_method == 4 2055if exists ( "g:netrw_port" ) && g: netrw_port != "" 2056let useport = " " . g: netrw_scpport . " " . fnameescape ( g: netrw_port ) 2057else 2058let useport = "" 2059endif 2060call 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 )) 2061let b: netrw_lastfile = choice 2062 2063"......................................... 2064" NetWrite: (http) NetWrite Method #5 {{{3 2065elseif b: netrw_method == 5 2066let curl = substitute ( g: netrw_http_put_cmd , '\s\+.*$' , "" , "" ) 2067if executable ( curl ) 2068let url = g: netrw_choice 2069call netrw#os#Execute ( s: netrw_silentxfer . "!" . g: netrw_http_put_cmd . " " . netrw#os#Escape ( tmpfile , 1 ) . " " . netrw#os#Escape ( url , 1 ) ) 2070else 2071call netrw#msg#Notify ( 'ERROR' , printf ( "can't write to http using <%s>" , g: netrw_http_put_cmd )) 2072endif 2073 2074"......................................... 2075" NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3 2076elseif b: netrw_method == 6 2077 2078" Construct execution string (four lines) which will be passed through filter 2079let netrw_fname = escape ( b: netrw_fname , g: netrw_fname_escape ) 2080let bhkeep = & l: bh 2081 2082" formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2083let curbuf = bufnr ( "%" ) 2084setl bh = hide 2085keepj keepalt enew 2086 2087setl ff = unix 2088if exists ( "g:netrw_port" ) && g: netrw_port != "" 2089NetrwKeepj put ='open'.g:netrw_machine.' '.g:netrw_port 2090else 2091NetrwKeepj put ='open '.g:netrw_machine 2092endif 2093if exists ( "g:netrw_uid" ) && exists ( "s:netrw_passwd" ) && g: netrw_uid != "" 2094NetrwKeepj put ='user'.g:netrw_uid.' '.s:netrw_passwd 2095endif 2096NetrwKeepj put ='put'.tmpfile.' '.netrw_fname 2097 2098" perform cadaver operation: 2099NetrwKeepj norm! 1G"_dd 2100call netrw#os#Execute ( s: netrw_silentxfer . "%!" . g: netrw_dav_cmd ) 2101 2102" remove enew buffer (quietly) 2103let filtbuf = bufnr ( "%" ) 2104exe curbuf . "b!" 2105let & l: bh = bhkeep 2106exe filtbuf . "bw!" 2107 2108let b: netrw_lastfile = choice 2109 2110"......................................... 2111" NetWrite: (rsync) NetWrite Method #7 {{{3 2112elseif b: netrw_method == 7 2113call 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 )) 2114let b: netrw_lastfile = choice 2115 2116"......................................... 2117" NetWrite: (sftp) NetWrite Method #9 {{{3 2118elseif b: netrw_method == 9 2119let netrw_fname = escape ( b: netrw_fname , g: netrw_fname_escape ) 2120if exists ( "g:netrw_uid" ) && ( g: netrw_uid != "" ) 2121let uid_machine = g: netrw_uid . '@' . g: netrw_machine 2122else 2123let uid_machine = g: netrw_machine 2124endif 2125 2126" formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead 2127let bhkeep = & l: bh 2128let curbuf = bufnr ( "%" ) 2129setl bh = hide 2130keepj keepalt enew 2131 2132setl ff = unix 2133call setline ( 1 , 'put "' . escape ( tmpfile , '\' ) . '" ' . netrw_fname ) 2134let sftpcmd = substitute ( g: netrw_sftp_cmd , "%TEMPFILE%" , escape ( tmpfile , '\' ), "g" ) 2135call netrw#os#Execute ( s: netrw_silentxfer . "%!" . sftpcmd . ' ' . netrw#os#Escape ( uid_machine , 1 )) 2136let filtbuf = bufnr ( "%" ) 2137exe curbuf . "b!" 2138let & l: bh = bhkeep 2139exe filtbuf . "bw!" 2140let b: netrw_lastfile = choice 2141 2142"......................................... 2143" NetWrite: Complain {{{3 2144else 2145call netrw#msg#Notify ( 'WARNING' , printf ( 'unable to comply with your request<%s>' , choice )) 2146let leavemod = 1 2147endif 2148endwhile 2149 2150" NetWrite: Cleanup: {{{3 2151if s: FileReadable ( tmpfile ) 2152call netrw#fs#Remove ( tmpfile ) 2153endif 2154call s: NetrwOptionsRestore ( "w:" ) 2155 2156if a: firstline == 1 && a: lastline == line ( "$" ) 2157" restore modifiability; usually equivalent to set nomod 2158let & l: mod = mod 2159elseif ! exists ( "leavemod" ) 2160" indicate that the buffer has not been modified since last written 2161setl nomod 2162endif 2163 2164endfunction 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. 2170function netrw#NetSource (...) 2171if a: 0 > 0 && a: 1 == '?' 2172" give help 2173echomsg 'NetSource Usage:' 2174echomsg ':Nsource dav://machine[:port]/path uses cadaver' 2175echomsg ':Nsource fetch://machine/path uses fetch' 2176echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' 2177echomsg ':Nsource http[s]://[user@]machine/path uses http wget' 2178echomsg ':Nsource rcp://[user@]machine/path uses rcp' 2179echomsg ':Nsource rsync://machine[:port]/path uses rsync' 2180echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp' 2181echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp' 2182sleep 4 2183else 2184let i = 1 2185while i <= a: 0 2186call netrw#NetRead ( 3 , a: {i}) 2187if s: FileReadable ( s: netrw_tmpfile ) 2188exe "so " . fnameescape ( s: netrw_tmpfile ) 2189if delete ( s: netrw_tmpfile ) 2190call netrw#msg#Notify ( 'ERROR' , 'unable to delete directory <%s>' , s: netrw_tmpfile ) 2191endif 2192unlet s: netrw_tmpfile 2193else 2194call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to source <%s>!' , a: {i})) 2195endif 2196let i = i + 1 2197endwhile 2198endif 2199endfunction 2200 2201" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2 2202" (implements the :Ntree command) 2203function 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 2208if exists ( "w:netrw_treetop" ) 2209let inittreetop = w: netrw_treetop 2210unlet w: netrw_treetop 2211endif 2212if exists ( "w:netrw_treedict" ) 2213unlet w: netrw_treedict 2214endif 2215 2216if ( a: iscmd == 0 || a: 1 == "" ) && exists ( "inittreetop" ) 2217let treedir = s: NetrwTreePath ( inittreetop ) 2218else 2219if isdirectory ( s: NetrwFile ( a: 1 )) 2220let treedir = a: 1 2221let s: netrw_treetop = treedir 2222elseif exists ( "b:netrw_curdir" ) && ( isdirectory ( s: NetrwFile ( b: netrw_curdir . "/" . a: 1 )) || a: 1 =~ '^\a\{3,}://' ) 2223let treedir = b: netrw_curdir . "/" . a: 1 2224let s: netrw_treetop = treedir 2225else 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. 2228let netrwbuf = bufnr ( "%" ) 2229call netrw#msg#Notify ( 'ERROR' , printf ( "sorry, %s doesn't seem to be a directory!" , a: 1 )) 2230exe bufwinnr ( netrwbuf ) . "wincmd w" 2231let treedir = "." 2232let s: netrw_treetop = getcwd () 2233endif 2234endif 2235 2236" determine if treedir is remote or local 2237let islocal = expand ( "%" ) !~ '^\a\{3,}://' 2238 2239" browse the resulting directory 2240if islocal 2241call netrw#LocalBrowseCheck ( s: NetrwBrowseChgDir ( islocal , treedir , 0 )) 2242else 2243call s: NetrwBrowse ( islocal , s: NetrwBrowseChgDir ( islocal , treedir , 0 )) 2244endif 2245 2246endfunction 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) 2253function s: NetrwGetFile ( readcmd , tfile , method ) 2254 2255" readcmd=='t': simply do nothing 2256if a: readcmd == 't' 2257return 2258endif 2259 2260" get name of remote filename (ie. url and all) 2261let rfile = bufname ( "%" ) 2262 2263if exists ( "*NetReadFixup" ) 2264" for the use of NetReadFixup (not otherwise used internally) 2265let line2 = line ( "$" ) 2266endif 2267 2268if a: readcmd [ 0 ] == '%' 2269" get file into buffer 2270 2271" rename the current buffer to the temp file (ie. tfile) 2272if g: netrw_cygwin 2273let tfile = substitute ( a: tfile , g: netrw_cygdrive . '/\(.\)' , '\1:' , '' ) 2274else 2275let tfile = a: tfile 2276endif 2277call s: NetrwBufRename ( tfile ) 2278 2279" edit temporary file (ie. read the temporary file in) 2280if rfile =~ '\.zip$' 2281if exists ( "#zip" ) 2282call zip#Browse ( tfile ) 2283elseif exists ( "#nvim.zip" ) 2284call s: NetrwBufRename ( rfile ) 2285call luaeval ( "require('nvim.zip').browse(_A[1], _A[2])" , [ bufnr (), tfile ]) 2286endif 2287elseif rfile =~ '\.tar$' 2288call tar#Browse ( tfile ) 2289elseif rfile =~ '\.tar\.gz$' 2290call tar#Browse ( tfile ) 2291elseif rfile =~ '\.tar\.bz2$' 2292call tar#Browse ( tfile ) 2293elseif rfile =~ '\.tar\.xz$' 2294call tar#Browse ( tfile ) 2295elseif rfile =~ '\.txz$' 2296call tar#Browse ( tfile ) 2297else 2298NetrwKeepj e! 2299endif 2300 2301" rename buffer back to remote filename 2302call s: NetrwBufRename ( rfile ) 2303 2304" Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype 2305" Detect filetype of local version of remote file. 2306" Note that isk must not include a "/" for scripts.vim 2307" to process this detection correctly. 2308" setl ft= 2309let iskkeep = & isk 2310setl isk -= / 2311filetype detect 2312let & l: isk = iskkeep 2313let line1 = 1 2314let line2 = line ( "$" ) 2315 2316elseif !& ma 2317" attempting to read a file after the current line in the file, but the buffer is not modifiable 2318call netrw#msg#Notify ( 'WARNING' , printf ( 'attempt to read<%s> into a non-modifiable buffer!' , a: tfile )) 2319return 2320 2321elseif s: FileReadable ( a: tfile ) 2322" read file after current line 2323let curline = line ( "." ) 2324let lastline = line ( "$" ) 2325exe "NetrwKeepj " . a: readcmd . " " . fnameescape ( v: cmdarg ) . " " . fnameescape ( a: tfile ) 2326let line1 = curline + 1 2327let line2 = line ( "$" ) - lastline + 1 2328 2329else 2330" not readable 2331call netrw#msg#Notify ( 'WARNING' , printf ( 'file <%s> not readable' , a: tfile )) 2332return 2333endif 2334 2335" User-provided (ie. optional) fix-it-up command 2336if exists ( "*NetReadFixup" ) 2337NetrwKeepj call NetReadFixup(a:method, line1, line2) 2338endif 2339 2340if has ( "gui" ) && has ( "menu" ) && has ( "gui_running" ) && & go =~# 'm' && g: netrw_menu 2341" update the Buffers menu 2342NetrwKeepj call s:UpdateBuffersMenu() 2343endif 2344 2345 2346" make sure file is being displayed 2347" redraw! 2348 2349endfunction 2350 2351" s:NetrwMethod: determine method of transfer {{{2 2352" Input: 2353" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file] 2354" Output: 2355" b:netrw_method= 1: rcp 2356" 2: ftp + <.netrc> 2357" 3: ftp + machine, id, password, and [path]filename 2358" 4: scp 2359" 5: http[s] (wget) 2360" 6: dav 2361" 7: rsync 2362" 8: fetch 2363" 9: sftp 2364" 10: file 2365" g:netrw_machine= hostname 2366" b:netrw_fname = filename 2367" g:netrw_port = optional port number (for ftp) 2368" g:netrw_choice = copy of input url (choice) 2369function s: NetrwMethod ( choice ) 2370 2371" sanity check: choice should have at least three slashes in it 2372if strlen ( substitute ( a: choice , '[^/]' , '' , 'g' )) < 3 2373call netrw#msg#Notify ( 'ERROR' , 'not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])' ) 2374let b: netrw_method = -1 2375return 2376endif 2377 2378" record current g:netrw_machine, if any 2379" curmachine used if protocol == ftp and no .netrc 2380if exists ( "g:netrw_machine" ) 2381let curmachine = g: netrw_machine 2382else 2383let curmachine = "N O T A HOST" 2384endif 2385if exists ( "g:netrw_port" ) 2386let netrw_port = g: netrw_port 2387endif 2388 2389" insure that netrw_ftp_cmd starts off every method determination 2390" with the current g:netrw_ftp_cmd 2391let s: netrw_ftp_cmd = g: netrw_ftp_cmd 2392 2393" initialization 2394let b: netrw_method = 0 2395let g: netrw_machine = "" 2396let b: netrw_fname = "" 2397let g: netrw_port = "" 2398let g: netrw_choice = a: choice 2399 2400" Patterns: 2401" mipf : a:machine a:id password filename Use ftp 2402" mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd 2403" ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd 2404" rcpurm : rcp://[user@]host/filename Use rcp 2405" rcphf : [user@]host:filename Use rcp 2406" scpurm : scp://[user@]host[[#:]port]/filename Use scp 2407" httpurm : http[s]://[user@]host/filename Use wget 2408" davurm : dav[s]://host[:port]/path Use cadaver/curl 2409" rsyncurm : rsync://host[:port]/path Use rsync 2410" fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) 2411" sftpurm : sftp://[user@]host/filename Use scp 2412" fileurm : file://[user@]host/filename Use elinks or links 2413let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' 2414let mf = '^\(\S\+\)\s\+\(\S\+\)$' 2415let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' 2416let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$' 2417let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' 2418let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$' 2419let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$' 2420let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$' 2421let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' 2422let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' 2423let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' 2424let fileurm = '^file\=://\(.*\)$' 2425 2426" Determine Method 2427" Method#1: rcp://user@hostname/...path-to-file {{{3 2428if match ( a: choice , rcpurm ) == 0 2429let b: netrw_method = 1 2430let userid = substitute ( a: choice , rcpurm , '\1' , "" ) 2431let g: netrw_machine = substitute ( a: choice , rcpurm , '\2' , "" ) 2432let b: netrw_fname = substitute ( a: choice , rcpurm , '\3' , "" ) 2433if userid != "" 2434let g: netrw_uid = userid 2435endif 2436 2437" Method#4: scp://user@hostname/...path-to-file {{{3 2438elseif match ( a: choice , scpurm ) == 0 2439let b: netrw_method = 4 2440let g: netrw_machine = substitute ( a: choice , scpurm , '\1' , "" ) 2441let g: netrw_port = substitute ( a: choice , scpurm , '\2' , "" ) 2442let b: netrw_fname = substitute ( a: choice , scpurm , '\3' , "" ) 2443 2444" Method#5: http[s]://user@hostname/...path-to-file {{{3 2445elseif match ( a: choice , httpurm ) == 0 2446let b: netrw_method = 5 2447let g: netrw_machine = substitute ( a: choice , httpurm , '\1' , "" ) 2448let b: netrw_fname = substitute ( a: choice , httpurm , '\2' , "" ) 2449let b: netrw_http = ( a: choice =~ '^https:' ) ? "https" : "http" 2450 2451" Method#6: dav://hostname[:port]/..path-to-file.. {{{3 2452elseif match ( a: choice , davurm ) == 0 2453let b: netrw_method = 6 2454if a: choice =~ 'davs:' 2455let g: netrw_machine = 'https://' . substitute ( a: choice , davurm , '\1/\2' , "" ) 2456else 2457let g: netrw_machine = 'http://' . substitute ( a: choice , davurm , '\1/\2' , "" ) 2458endif 2459let b: netrw_fname = substitute ( a: choice , davurm , '\3' , "" ) 2460 2461" Method#7: rsync://user@hostname/...path-to-file {{{3 2462elseif match ( a: choice , rsyncurm ) == 0 2463let b: netrw_method = 7 2464let g: netrw_machine = substitute ( a: choice , rsyncurm , '\1' , "" ) 2465let b: netrw_fname = substitute ( a: choice , rsyncurm , '\2' , "" ) 2466 2467" Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3 2468elseif match ( a: choice , ftpurm ) == 0 2469let userid = substitute ( a: choice , ftpurm , '\2' , "" ) 2470let g: netrw_machine = substitute ( a: choice , ftpurm , '\3' , "" ) 2471let g: netrw_port = substitute ( a: choice , ftpurm , '\4' , "" ) 2472let b: netrw_fname = substitute ( a: choice , ftpurm , '\5' , "" ) 2473if userid != "" 2474let g: netrw_uid = userid 2475endif 2476 2477if curmachine != g: netrw_machine 2478if exists ( "s:netrw_hup[" . g: netrw_machine . "]" ) 2479call netrw#NetUserPass ( "ftp:" . g: netrw_machine ) 2480elseif exists ( "s:netrw_passwd" ) 2481" if there's a change in hostname, require password re-entry 2482unlet s: netrw_passwd 2483endif 2484if exists ( "netrw_port" ) 2485unlet netrw_port 2486endif 2487endif 2488 2489if exists ( "g:netrw_uid" ) && exists ( "s:netrw_passwd" ) 2490let b: netrw_method = 3 2491else 2492let host = substitute ( g: netrw_machine , '\..*$' , '' , '' ) 2493if exists ( "s:netrw_hup[host]" ) 2494call netrw#NetUserPass ( "ftp:" . host ) 2495 2496elseif has ( "win32" ) && s: netrw_ftp_cmd =~# '-[sS]:' 2497if g: netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>' 2498let s: netrw_ftp_cmd = substitute ( g: netrw_ftp_cmd , '\<MACHINE\>' , g: netrw_machine , '' ) 2499endif 2500let b: netrw_method = 2 2501elseif s: FileReadable ( expand ( "$HOME/.netrc" )) && ! g: netrw_ignorenetrc 2502let b: netrw_method = 2 2503else 2504if ! exists ( "g:netrw_uid" ) || g: netrw_uid == "" 2505call netrw#NetUserPass () 2506elseif ! exists ( "s:netrw_passwd" ) || s: netrw_passwd == "" 2507call netrw#NetUserPass ( g: netrw_uid ) 2508" else just use current g:netrw_uid and s:netrw_passwd 2509endif 2510let b: netrw_method = 3 2511endif 2512endif 2513 2514" Method#8: fetch {{{3 2515elseif match ( a: choice , fetchurm ) == 0 2516let b: netrw_method = 8 2517let g: netrw_userid = substitute ( a: choice , fetchurm , '\2' , "" ) 2518let g: netrw_machine = substitute ( a: choice , fetchurm , '\3' , "" ) 2519let b: netrw_option = substitute ( a: choice , fetchurm , '\4' , "" ) 2520let b: netrw_fname = substitute ( a: choice , fetchurm , '\5' , "" ) 2521 2522" Method#3: Issue an ftp : "machine id password [path/]filename" {{{3 2523elseif match ( a: choice , mipf ) == 0 2524let b: netrw_method = 3 2525let g: netrw_machine = substitute ( a: choice , mipf , '\1' , "" ) 2526let g: netrw_uid = substitute ( a: choice , mipf , '\2' , "" ) 2527let s: netrw_passwd = substitute ( a: choice , mipf , '\3' , "" ) 2528let b: netrw_fname = substitute ( a: choice , mipf , '\4' , "" ) 2529call netrw#NetUserPass ( g: netrw_machine , g: netrw_uid , s: netrw_passwd ) 2530 2531" Method#3: Issue an ftp: "hostname [path/]filename" {{{3 2532elseif match ( a: choice , mf ) == 0 2533if exists ( "g:netrw_uid" ) && exists ( "s:netrw_passwd" ) 2534let b: netrw_method = 3 2535let g: netrw_machine = substitute ( a: choice , mf , '\1' , "" ) 2536let b: netrw_fname = substitute ( a: choice , mf , '\2' , "" ) 2537 2538elseif s: FileReadable ( expand ( "$HOME/.netrc" )) 2539let b: netrw_method = 2 2540let g: netrw_machine = substitute ( a: choice , mf , '\1' , "" ) 2541let b: netrw_fname = substitute ( a: choice , mf , '\2' , "" ) 2542endif 2543 2544" Method#9: sftp://user@hostname/...path-to-file {{{3 2545elseif match ( a: choice , sftpurm ) == 0 2546let b: netrw_method = 9 2547let g: netrw_machine = substitute ( a: choice , sftpurm , '\1' , "" ) 2548let b: netrw_fname = substitute ( a: choice , sftpurm , '\2' , "" ) 2549 2550" Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3 2551elseif match ( a: choice , rcphf ) == 0 2552let b: netrw_method = 1 2553let userid = substitute ( a: choice , rcphf , '\2' , "" ) 2554let g: netrw_machine = substitute ( a: choice , rcphf , '\3' , "" ) 2555let b: netrw_fname = substitute ( a: choice , rcphf , '\4' , "" ) 2556if userid != "" 2557let g: netrw_uid = userid 2558endif 2559 2560" Method#10: file://user@hostname/...path-to-file {{{3 2561elseif match ( a: choice , fileurm ) == 0 && exists ( "g:netrw_file_cmd" ) 2562let b: netrw_method = 10 2563let b: netrw_fname = substitute ( a: choice , fileurm , '\1' , "" ) 2564 2565" Cannot Determine Method {{{3 2566else 2567call netrw#msg#Notify ( 'WARNING' , 'cannot determine method (format: protocol://[user@]hostname[:port]/[path])' ) 2568let b: netrw_method = -1 2569endif 2570"}}}3 2571 2572if g: netrw_port != "" 2573" remove any leading [:#] from port number 2574let g: netrw_port = substitute ( g: netrw_port , '[#:]\+' , '' , '' ) 2575elseif exists ( "netrw_port" ) 2576" retain port number as implicit for subsequent ftp operations 2577let g: netrw_port = netrw_port 2578endif 2579 2580endfunction 2581 2582" s:NetrwValidateHostname: Validate that the hostname is valid {{{2 2583" Input: 2584" hostname, may include an optional username and port number, e.g. 2585" user@hostname:port 2586" allow a alphanumeric hostname or an IPv(4/6) address 2587" Output: 2588" true if g:netrw_machine is valid according to RFC1123 #Section 2 2589function s: NetrwValidateHostname ( hostname ) 2590" Username: 2591let user_pat = '\%([a-zA-Z0-9._-]\+@\)\?' 2592" Hostname: 1-64 chars, alphanumeric/dots/hyphens. 2593" No leading/trailing dots/hyphens. 2594let host_pat = '[a-zA-Z0-9_]\%([-a-zA-Z0-9._]\{0,62}[a-zA-Z0-9_]\)\?' 2595" Port: 16 bit unsigned integer 2596let port_pat = '\%(:\d\{1,5\}\)\?$' 2597 2598" IPv4: 1-3 digits separated by dots 2599let ipv4_pat = '\%(\d\{1,3}\.\)\{3\}\d\{1,3\}' 2600 2601" IPv6: Hex, colons, and optional brackets 2602let ipv6_pat = '\[\?\%([a-fA-F0-9:]\{2,}\)\+\]\?' 2603 2604return a: hostname =~? '^' . user_pat . host_pat . port_pat || 2605 \a: hostname =~? '^' . user_pat . ipv4_pat . port_pat || 2606 \a: hostname =~? '^' . user_pat . ipv6_pat . port_pat 2607endfunction 2608 2609" NetUserPass: set username and password for subsequent ftp transfer {{{2 2610" Usage: :call netrw#NetUserPass() -- will prompt for userid and password 2611" :call netrw#NetUserPass("uid") -- will prompt for password 2612" :call netrw#NetUserPass("uid","password") -- sets global userid and password 2613" :call netrw#NetUserPass("ftp:host") -- looks up userid and password using hup dictionary 2614" :call netrw#NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password 2615function netrw#NetUserPass (...) 2616 2617 2618if ! exists ( 's:netrw_hup' ) 2619let s: netrw_hup = {} 2620endif 2621 2622if a: 0 == 0 2623" case: no input arguments 2624 2625" change host and username if not previously entered; get new password 2626if ! exists ( "g:netrw_machine" ) 2627let g: netrw_machine = input ( 'Enter hostname: ' ) 2628endif 2629if ! exists ( "g:netrw_uid" ) || g: netrw_uid == "" 2630" get username (user-id) via prompt 2631let g: netrw_uid = input ( 'Enter username: ' ) 2632endif 2633" get password via prompting 2634let s: netrw_passwd = inputsecret ( "Enter Password: " ) 2635 2636" set up hup database 2637let host = substitute ( g: netrw_machine , '\..*$' , '' , '' ) 2638if ! exists ( 's:netrw_hup[host]' ) 2639let s: netrw_hup [ host ] = {} 2640endif 2641let s: netrw_hup [ host ]. uid = g: netrw_uid 2642let s: netrw_hup [ host ]. passwd = s: netrw_passwd 2643 2644elseif a: 0 == 1 2645" case: one input argument 2646 2647if a: 1 =~ '^ftp:' 2648" get host from ftp:... url 2649" access userid and password from hup (host-user-passwd) dictionary 2650let host = substitute ( a: 1 , '^ftp:' , '' , '' ) 2651let host = substitute ( host , '\..*' , '' , '' ) 2652if exists ( "s:netrw_hup[host]" ) 2653let g: netrw_uid = s: netrw_hup [ host ]. uid 2654let s: netrw_passwd = s: netrw_hup [ host ]. passwd 2655else 2656let g: netrw_uid = input ( "Enter UserId: " ) 2657let s: netrw_passwd = inputsecret ( "Enter Password: " ) 2658endif 2659 2660else 2661" case: one input argument, not an url. Using it as a new user-id. 2662if exists ( "g:netrw_machine" ) 2663if g: netrw_machine =~ '[0-9.]\+' 2664let host = g: netrw_machine 2665else 2666let host = substitute ( g: netrw_machine , '\..*$' , '' , '' ) 2667endif 2668else 2669let g: netrw_machine = input ( 'Enter hostname: ' ) 2670endif 2671let g: netrw_uid = a: 1 2672if exists ( "g:netrw_passwd" ) 2673" ask for password if one not previously entered 2674let s: netrw_passwd = g: netrw_passwd 2675else 2676let s: netrw_passwd = inputsecret ( "Enter Password: " ) 2677endif 2678endif 2679 2680if exists ( "host" ) 2681if ! exists ( 's:netrw_hup[host]' ) 2682let s: netrw_hup [ host ] = {} 2683endif 2684let s: netrw_hup [ host ]. uid = g: netrw_uid 2685let s: netrw_hup [ host ]. passwd = s: netrw_passwd 2686endif 2687 2688elseif a: 0 == 2 2689let g: netrw_uid = a: 1 2690let s: netrw_passwd = a: 2 2691 2692elseif a: 0 == 3 2693" enter hostname, user-id, and password into the hup dictionary 2694let host = substitute ( a: 1 , '^\a\+:' , '' , '' ) 2695let host = substitute ( host , '\..*$' , '' , '' ) 2696if ! exists ( 's:netrw_hup[host]' ) 2697let s: netrw_hup [ host ] = {} 2698endif 2699let s: netrw_hup [ host ]. uid = a: 2 2700let s: netrw_hup [ host ]. passwd = a: 3 2701let g: netrw_uid = s: netrw_hup [ host ]. uid 2702let s: netrw_passwd = s: netrw_hup [ host ]. passwd 2703endif 2704 2705endfunction 2706 2707" Shared Browsing Support: {{{1 2708 2709" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2 2710function s: ExplorePatHls ( pattern ) 2711let repat = substitute ( a: pattern , '^**/\{1,2}' , '' , '' ) 2712let repat = escape ( repat , '][.\' ) 2713let repat = '\<' . substitute ( repat , '\*' , '\\(\\S\\+ \\)*\\S\\+' , 'g' ) . '\>' 2714return repat 2715endfunction 2716 2717" s:NetrwBookHistHandler: {{{2 2718" 0: (user: <mb>) bookmark current directory 2719" 1: (user: <gb>) change to the bookmarked path 2720" 2: (user: <qb>) list bookmarks 2721" 3: (browsing) records current directory history 2722" 4: (user: <u>) go up (previous) directory, using history 2723" 5: (user: <U>) go down (next) directory, using history 2724" 6: (user: <mB>) delete bookmark 2725function s: NetrwBookHistHandler ( chg , curdir ) 2726if ! exists ( "g:netrw_dirhistmax" ) || g: netrw_dirhistmax <= 0 2727return 2728endif 2729 2730let ykeep = @@ 2731let curbufnr = bufnr ( "%" ) 2732 2733if a: chg == 0 2734" bookmark the current directory 2735if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 2736call s: NetrwBookmark ( 0 ) 2737echo "bookmarked marked files" 2738else 2739call s: MakeBookmark ( a: curdir ) 2740echo "bookmarked the current directory" 2741endif 2742 2743try 2744call s: NetrwBookHistSave () 2745catch 2746endtry 2747 2748elseif a: chg == 1 2749" change to bookmarked path 2750if exists ( "g:netrw_bookmarklist" ) && ! empty ( g: netrw_bookmarklist ) 2751let len_bookmarklist = len ( g: netrw_bookmarklist ) 2752let bookmark_num = v: count 2753 2754" v:count value is set to zero if no count (prefix) is given to the `gb` map 2755if bookmark_num == 0 2756" list bookmarks and prompt for a bookmark number 2757let goto_list = [ " # | Goto Bookmark:" ] 2758let i = 0 2759while i < len_bookmarklist 2760call add ( goto_list , printf ( "%3d| %s" , i + 1 , g: netrw_bookmarklist [ i ])) 2761let i += 1 2762endwhile 2763let bookmark_num = inputlist ( goto_list ) 2764endif 2765 2766if bookmark_num > 0 2767if bookmark_num <= len_bookmarklist 2768exe "NetrwKeepj e " . fnameescape ( g: netrw_bookmarklist [ bookmark_num - 1 ]) 2769else 2770echomsg "Sorry, bookmark#" . bookmark_num . " doesn't exist!" 2771endif 2772endif 2773" Exit silently if user cancels with `q` or empty after inputlist() 2774else 2775echo "Bookmark list is empty." 2776endif 2777 2778elseif a: chg == 2 2779" redraw! 2780let didwork = 0 2781" list user's bookmarks 2782if exists ( "g:netrw_bookmarklist" ) 2783let cnt = 1 2784for bmd in g: netrw_bookmarklist 2785echo printf ( "Netrw Bookmark#%-2d: %s" , cnt , g: netrw_bookmarklist [ cnt - 1 ]) 2786let didwork = 1 2787let cnt = cnt + 1 2788endfor 2789endif 2790 2791" list directory history 2792" Note: history is saved only when PerformListing is done; 2793" ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history. 2794let cnt = g: netrw_dirhistcnt 2795let first = 1 2796let histcnt = 0 2797if g: netrw_dirhistmax > 0 2798while ( first || cnt != g: netrw_dirhistcnt ) 2799if exists ( "g:netrw_dirhist_{cnt}" ) 2800echo printf ( "Netrw History#%-2d: %s" , histcnt , g: netrw_dirhist_ { cnt }) 2801let didwork = 1 2802endif 2803let histcnt = histcnt + 1 2804let first = 0 2805let cnt = ( cnt - 1 ) % g: netrw_dirhistmax 2806if cnt < 0 2807let cnt = cnt + g: netrw_dirhistmax 2808endif 2809endwhile 2810else 2811let g: netrw_dirhistcnt = 0 2812endif 2813if didwork 2814call inputsave () |call input ( "Press <cr> to continue" ) |call inputrestore () 2815endif 2816 2817elseif a: chg == 3 2818" saves most recently visited directories (when they differ) 2819if ! exists ( "g:netrw_dirhistcnt" ) || ! exists ( "g:netrw_dirhist_{g:netrw_dirhistcnt}" ) || g: netrw_dirhist_ { g: netrw_dirhistcnt } != a: curdir 2820if g: netrw_dirhistmax > 0 2821let g: netrw_dirhistcnt = ( g: netrw_dirhistcnt + 1 ) % g: netrw_dirhistmax 2822let g: netrw_dirhist_ { g: netrw_dirhistcnt } = a: curdir 2823endif 2824endif 2825 2826elseif a: chg == 4 2827" u: change to the previous directory stored on the history list 2828if g: netrw_dirhistmax > 0 2829let g: netrw_dirhistcnt = ( g: netrw_dirhistcnt - v: count1 ) % g: netrw_dirhistmax 2830if g: netrw_dirhistcnt < 0 2831let g: netrw_dirhistcnt = g: netrw_dirhistcnt + g: netrw_dirhistmax 2832endif 2833else 2834let g: netrw_dirhistcnt = 0 2835endif 2836if exists ( "g:netrw_dirhist_{g:netrw_dirhistcnt}" ) 2837if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "b:netrw_curdir" ) 2838setl ma noro 2839sil ! NetrwKeepj %d _ 2840setl nomod 2841endif 2842exe "NetrwKeepj e! " . fnameescape ( g: netrw_dirhist_ { g: netrw_dirhistcnt }) 2843else 2844if g: netrw_dirhistmax > 0 2845let g: netrw_dirhistcnt = ( g: netrw_dirhistcnt + v: count1 ) % g: netrw_dirhistmax 2846else 2847let g: netrw_dirhistcnt = 0 2848endif 2849echo "Sorry, no predecessor directory exists yet" 2850endif 2851 2852elseif a: chg == 5 2853" U: change to the subsequent directory stored on the history list 2854if g: netrw_dirhistmax > 0 2855let g: netrw_dirhistcnt = ( g: netrw_dirhistcnt + 1 ) % g: netrw_dirhistmax 2856if exists ( "g:netrw_dirhist_{g:netrw_dirhistcnt}" ) 2857if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "b:netrw_curdir" ) 2858setl ma noro 2859sil ! NetrwKeepj %d _ 2860setl nomod 2861endif 2862exe "NetrwKeepj e! " . fnameescape ( g: netrw_dirhist_ { g: netrw_dirhistcnt }) 2863else 2864let g: netrw_dirhistcnt = ( g: netrw_dirhistcnt - 1 ) % g: netrw_dirhistmax 2865if g: netrw_dirhistcnt < 0 2866let g: netrw_dirhistcnt = g: netrw_dirhistcnt + g: netrw_dirhistmax 2867endif 2868echo "Sorry, no successor directory exists yet" 2869endif 2870else 2871let g: netrw_dirhistcnt = 0 2872echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is " . g: netrw_dirhistmax . ")" 2873endif 2874 2875elseif a: chg == 6 2876if exists ( "s:netrwmarkfilelist_{curbufnr}" ) && ! empty ( s: netrwmarkfilelist_ { curbufnr }) 2877call s: NetrwBookmark ( 1 ) 2878echo "removed marked files from bookmarks" 2879elseif exists ( "g:netrw_bookmarklist" ) && ! empty ( g: netrw_bookmarklist ) 2880let len_bookmarklist = len ( g: netrw_bookmarklist ) 2881let bookmark_num = v: count 2882 2883" v:count value is set to zero if no count (prefix) is given to the `gb` map 2884if bookmark_num == 0 2885" list bookmarks and prompt for a bookmark number 2886let goto_list = [ " # | Delete Bookmark:" ] 2887let i = 0 2888while i < len_bookmarklist 2889call add ( goto_list , printf ( "%3d| %s" , i + 1 , g: netrw_bookmarklist [ i ])) 2890let i += 1 2891endwhile 2892let bookmark_num = inputlist ( goto_list ) 2893endif 2894 2895if bookmark_num > 0 2896if bookmark_num <= len_bookmarklist 2897let bookmark_path = g: netrw_bookmarklist [ bookmark_num - 1 ] 2898call s: MergeBookmarks () 2899NetrwKeepj call remove(g:netrw_bookmarklist, bookmark_num - 1) 2900echo "removed " . bookmark_path . " from g:netrw_bookmarklist." 2901else 2902echomsg "Sorry, bookmark#" . bookmark_num . " doesn't exist!" 2903endif 2904endif 2905" Exit silently if user cancels with `q` or empty after inputlist() 2906else 2907echo "Bookmark list is empty." 2908endif 2909 2910try 2911call s: NetrwBookHistSave () 2912catch 2913endtry 2914endif 2915call s: NetrwBookmarkMenu () 2916call s: NetrwTgtMenu () 2917let @@= ykeep 2918endfunction 2919 2920" s:NetrwBookHistRead: this function reads bookmarks and history {{{2 2921" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0. 2922" Sister function: s:NetrwBookHistSave() 2923function s: NetrwBookHistRead () 2924if ! exists ( "g:netrw_dirhistmax" ) || g: netrw_dirhistmax <= 0 2925return 2926endif 2927let ykeep = @@ 2928 2929" read bookmarks 2930if ! exists ( "s:netrw_initbookhist" ) 2931let home = s: NetrwHome () 2932let savefile = home . "/.netrwbook" 2933if filereadable ( s: NetrwFile ( savefile )) 2934exe "keepalt NetrwKeepj so " . savefile 2935endif 2936 2937" read history 2938if g: netrw_dirhistmax > 0 2939let savefile = home . "/.netrwhist" 2940if filereadable ( s: NetrwFile ( savefile )) 2941exe "keepalt NetrwKeepj so " . savefile 2942endif 2943let s: netrw_initbookhist = 1 2944au VimLeave * call s: NetrwBookHistSave () 2945endif 2946endif 2947 2948let @@= ykeep 2949endfunction 2950 2951" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2 2952" Sister function: s:NetrwBookHistRead() 2953" I used to do this via viminfo but that appears to 2954" be unreliable for long-term storage 2955" If g:netrw_dirhistmax is <= 0, no history or bookmarks 2956" will be saved. 2957" (s:NetrwBookHistHandler(3,...) used to record history) 2958function s: NetrwBookHistSave () 2959if ! exists ( "g:netrw_dirhistmax" ) || g: netrw_dirhistmax <= 0 2960return 2961endif 2962 2963let savefile = s: NetrwHome () . "/.netrwhist" 29641 split 2965 2966" setting up a new buffer which will become .netrwhist 2967call s: NetrwEnew () 2968if g: netrw_use_noswf 2969setl cino = com = cpo -= acpo -= Afo = nroql2tw = 0 report = 10000 noswf 2970else 2971setl cino = com = cpo -= acpo -= Afo = nroql2tw = 0 report = 10000 2972endif 2973setl nocin noai noci magic nospell nohid wig = noaw 2974setl ma noro write 2975if exists ( "+acd" ) |setl noacd |endif 2976sil ! NetrwKeepj keepalt %d _ 2977 2978" rename enew'd file: .netrwhist -- no attempt to merge 2979" record dirhistmax and current dirhistcnt 2980" save history 2981sil ! keepalt file .netrwhist 2982call setline ( 1 , "let g:netrw_dirhistmax =" . g: netrw_dirhistmax ) 2983call setline ( 2 , "let g:netrw_dirhistcnt =" . g: netrw_dirhistcnt ) 2984if g: netrw_dirhistmax > 0 2985let lastline = line ( "$" ) 2986let cnt = g: netrw_dirhistcnt 2987let first = 1 2988while ( first || cnt != g: netrw_dirhistcnt ) 2989let lastline = lastline + 1 2990if exists ( "g:netrw_dirhist_{cnt}" ) 2991call setline ( lastline , 'let g:netrw_dirhist_' . cnt . '=' . string ( g: netrw_dirhist_ { cnt })) 2992endif 2993let first = 0 2994let cnt = ( cnt - 1 ) % g: netrw_dirhistmax 2995if cnt < 0 2996let cnt = cnt + g: netrw_dirhistmax 2997endif 2998endwhile 2999exe "sil! w! " . savefile 3000endif 3001 3002" save bookmarks 3003sil NetrwKeepj %d _ 3004if exists ( "g:netrw_bookmarklist" ) && g: netrw_bookmarklist != [] 3005" merge and write .netrwbook 3006let savefile = s: NetrwHome () . "/.netrwbook" 3007 3008if filereadable ( s: NetrwFile ( savefile )) 3009let booklist = deepcopy ( g: netrw_bookmarklist ) 3010exe "sil NetrwKeepj keepalt so " . savefile 3011for bdm in booklist 3012if index ( g: netrw_bookmarklist , bdm ) == -1 3013call add ( g: netrw_bookmarklist , bdm ) 3014endif 3015endfor 3016call sort ( g: netrw_bookmarklist ) 3017endif 3018 3019" construct and save .netrwbook 3020call setline ( 1 , "let g:netrw_bookmarklist= " . string ( g: netrw_bookmarklist )) 3021exe "sil! w! " . savefile 3022endif 3023 3024" cleanup -- remove buffer used to construct history 3025let bgone = bufnr ( "%" ) 3026q ! 3027exe "keepalt " . bgone . "bwipe!" 3028 3029endfunction 3030 3031" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2 3032" list of the contents of a local or remote directory. It is assumed that the 3033" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted 3034" with the requested remote hostname first. 3035" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse() 3036function s: NetrwBrowse ( islocal , dirname ) 3037if ! exists ( "w:netrw_liststyle" ) |let w: netrw_liststyle = g: netrw_liststyle |endif 3038 3039" save alternate-file's filename if w:netrw_rexlocal doesn't exist 3040" This is useful when one edits a local file, then :e ., then :Rex 3041if a: islocal && ! exists ( "w:netrw_rexfile" ) && bufname ( "#" ) != "" 3042let w: netrw_rexfile = bufname ( "#" ) 3043endif 3044 3045" s:NetrwBrowse : initialize history {{{3 3046if ! exists ( "s:netrw_initbookhist" ) 3047NetrwKeepj call s:NetrwBookHistRead() 3048endif 3049 3050" s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3 3051if a: dirname !~ '^\a\{3,}://' 3052let dirname = simplify ( a: dirname ) 3053else 3054let dirname = a: dirname 3055endif 3056 3057" repoint t:netrw_lexbufnr if appropriate 3058if exists ( "t:netrw_lexbufnr" ) && bufnr ( "%" ) == t: netrw_lexbufnr 3059let repointlexbufnr = 1 3060endif 3061 3062" s:NetrwBrowse : sanity checks: {{{3 3063if exists ( "s:netrw_skipbrowse" ) 3064unlet s: netrw_skipbrowse 3065return 3066endif 3067if ! exists ( "*shellescape" ) 3068call netrw#msg#Notify ( 'ERROR' , "netrw can't run -- your vim is missing shellescape()" ) 3069return 3070endif 3071if ! exists ( "*fnameescape" ) 3072call netrw#msg#Notify ( 'ERROR' , "netrw can't run -- your vim is missing fnameescape()" ) 3073return 3074endif 3075 3076" s:NetrwBrowse : save options: {{{3 3077call s: NetrwOptionsSave ( "w:" ) 3078 3079" s:NetrwBrowse : re-instate any marked files {{{3 3080if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 3081if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 3082exe "2match netrwMarkFile /" . s: netrwmarkfilemtch_ { bufnr ( "%" )} . "/" 3083endif 3084endif 3085 3086if a: islocal && exists ( "w:netrw_acdkeep" ) && w: netrw_acdkeep 3087" s:NetrwBrowse : set up "safe" options for local directory/file {{{3 3088if s: NetrwLcd ( dirname ) 3089return 3090endif 3091 3092elseif ! a: islocal && dirname !~ '[\/]$' && dirname !~ '^"' 3093" s:NetrwBrowse : remote regular file handler {{{3 3094if bufname ( dirname ) != "" 3095exe "NetrwKeepj b " . fnameescape ( bufname ( dirname )) 3096else 3097" attempt transfer of remote regular file 3098 3099" remove any filetype indicator from end of dirname, except for the 3100" "this is a directory" indicator (/). 3101" There shouldn't be one of those here, anyway. 3102let path = substitute ( dirname , '[*=@|]\r\=$' , '' , 'e' ) 3103call s: RemotePathAnalysis ( dirname ) 3104 3105" s:NetrwBrowse : remote-read the requested file into current buffer {{{3 3106call s: NetrwEnew ( dirname ) 3107call s: NetrwOptionsSafe ( a: islocal ) 3108setl ma noro 3109let b: netrw_curdir = dirname 3110let url = s: method . "://" . (( s: user == "" ) ? "" : s: user . "@" ) . s: machine . ( s: port ? ":" . s: port : "" ) . "/" . s: path 3111call s: NetrwBufRename ( url ) 3112exe "sil! NetrwKeepj keepalt doau BufReadPre " . fnameescape ( s: fname ) 3113sil call netrw#NetRead ( 2 , url ) 3114" netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error 3115if s: path =~ '\.bz2$' 3116exe "sil NetrwKeepj keepalt doau BufReadPost " . fnameescape ( substitute ( s: fname , '\.bz2$' , '' , '' )) 3117elseif s: path =~ '\.gz$' 3118exe "sil NetrwKeepj keepalt doau BufReadPost " . fnameescape ( substitute ( s: fname , '\.gz$' , '' , '' )) 3119elseif s: path =~ '\.xz$' 3120exe "sil NetrwKeepj keepalt doau BufReadPost " . fnameescape ( substitute ( s: fname , '\.xz$' , '' , '' )) 3121else 3122exe "sil NetrwKeepj keepalt doau BufReadPost " . fnameescape ( s: fname ) 3123endif 3124endif 3125 3126" s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3 3127call s: SetBufWinVars () 3128call s: NetrwOptionsRestore ( "w:" ) 3129setl ma nomod noro 3130return 3131endif 3132 3133" use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3 3134call s: UseBufWinVars () 3135 3136" set up some variables {{{3 3137let b: netrw_browser_active = 1 3138let dirname = dirname 3139let s: last_sort_by = g: netrw_sort_by 3140 3141" set up menu {{{3 3142NetrwKeepj call s:NetrwMenu(1) 3143 3144" get/set-up buffer {{{3 3145let svpos = winsaveview () 3146 3147" NetrwGetBuffer might change buffers but s:rexposn_X was set for the 3148" previous buffer 3149let prevbufnr = bufnr ( '%' ) 3150let reusing = s: NetrwGetBuffer ( a: islocal , dirname ) 3151if exists ( "s:rexposn_" . prevbufnr ) && exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3152let s: rexposn_ { bufnr ( '%' )} = s: rexposn_ { prevbufnr } 3153endif 3154 3155" maintain markfile highlighting 3156if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 3157if exists ( "s:netrwmarkfilemtch_{bufnr('%')}" ) && s: netrwmarkfilemtch_ { bufnr ( "%" )} != "" 3158exe "2match netrwMarkFile /" . s: netrwmarkfilemtch_ { bufnr ( "%" )} . "/" 3159else 31602 match none 3161endif 3162endif 3163if reusing && line ( "$" ) > 1 3164call s: NetrwOptionsRestore ( "w:" ) 3165setl noma nomod nowrap 3166return 3167endif 3168 3169" set b:netrw_curdir to the new directory name {{{3 3170let b: netrw_curdir = dirname 3171if b: netrw_curdir =~ '[/\\]$' 3172let b: netrw_curdir = substitute ( b: netrw_curdir , '[/\\]$' , '' , 'e' ) 3173endif 3174if b: netrw_curdir =~ '\a:$' && has ( "win32" ) 3175let b: netrw_curdir = b: netrw_curdir . "/" 3176endif 3177if b: netrw_curdir == '' 3178if has ( "amiga" ) 3179" On the Amiga, the empty string connotes the current directory 3180let b: netrw_curdir = getcwd () 3181else 3182" under unix, when the root directory is encountered, the result 3183" from the preceding substitute is an empty string. 3184let b: netrw_curdir = '/' 3185endif 3186endif 3187if ! a: islocal && b: netrw_curdir !~ '/$' 3188let b: netrw_curdir = b: netrw_curdir . '/' 3189endif 3190 3191" ------------ 3192" (local only) {{{3 3193" ------------ 3194if a: islocal 3195" Set up ShellCmdPost handling. Append current buffer to browselist 3196call s: LocalFastBrowser () 3197 3198" handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3 3199if ! g: netrw_keepdir 3200if ! exists ( "&l:acd" ) || !& l: acd 3201if s: NetrwLcd ( b: netrw_curdir ) 3202return 3203endif 3204endif 3205endif 3206 3207" -------------------------------- 3208" remote handling: {{{3 3209" -------------------------------- 3210else 3211 3212" analyze dirname and g:netrw_list_cmd {{{3 3213if dirname =~# "^NetrwTreeListing\>" 3214let dirname = b: netrw_curdir 3215elseif exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "b:netrw_curdir" ) 3216let dirname = substitute ( b: netrw_curdir , '\\' , '/' , 'g' ) 3217if dirname !~ '/$' 3218let dirname = dirname . '/' 3219endif 3220let b: netrw_curdir = dirname 3221else 3222let dirname = substitute ( dirname , '\\' , '/' , 'g' ) 3223endif 3224 3225let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' 3226if dirname !~ dirpat 3227call netrw#msg#Notify ( 'ERROR' , printf ( "netrw doesn't understand your dirname<%s>" , dirname )) 3228NetrwKeepj call s:NetrwOptionsRestore("w:") 3229setl noma nomod nowrap 3230return 3231endif 3232let b: netrw_curdir = dirname 3233endif " (additional remote handling) 3234 3235" ------------------------------- 3236" Perform Directory Listing: {{{3 3237" ------------------------------- 3238NetrwKeepj call s:NetrwMaps(a:islocal) 3239NetrwKeepj call s:NetrwCommands(a:islocal) 3240NetrwKeepj call s:PerformListing(a:islocal) 3241 3242" restore option(s) 3243call s: NetrwOptionsRestore ( "w:" ) 3244 3245" If there is a rexposn: restore position with rexposn 3246" Otherwise : set rexposn 3247if exists ( "s:rexposn_" . bufnr ( "%" )) 3248NetrwKeepj call winrestview(s:rexposn_{bufnr('%')}) 3249if exists ( "w:netrw_bannercnt" ) && line ( "." ) < w: netrw_bannercnt 3250NetrwKeepj exe w:netrw_bannercnt 3251endif 3252else 3253NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir) 3254endif 3255 3256" repoint t:netrw_lexbufnr if appropriate 3257if exists ( "repointlexbufnr" ) 3258let t: netrw_lexbufnr = bufnr ( "%" ) 3259endif 3260 3261" restore position 3262if reusing 3263call winrestview ( svpos ) 3264endif 3265 3266" The s:LocalBrowseRefresh() function is called by an autocmd 3267" installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed). 3268" However, s:NetrwBrowse() causes the FocusGained event to fire the first time. 3269return 3270endfunction 3271 3272" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2 3273" may not apply correctly; ie. netrw's idea of the current directory may 3274" differ from vim's. This function insures that netrw's idea of the current 3275" directory is used. 3276" Returns a path to the file specified by a:fname 3277function s: NetrwFile ( fname ) 3278 3279" clean up any leading treedepthstring 3280if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3281let fname = substitute ( a: fname , '^' . s: treedepthstring . '\+' , '' , '' ) 3282else 3283let fname = a: fname 3284endif 3285 3286if g: netrw_keepdir 3287" vim's idea of the current directory possibly may differ from netrw's 3288if ! exists ( "b:netrw_curdir" ) 3289let b: netrw_curdir = getcwd () 3290endif 3291 3292if ! g: netrw_cygwin && has ( "win32" ) 3293if isabsolutepath ( fname ) 3294" windows, but full path given 3295let ret = fname 3296else 3297" windows, relative path given 3298let ret = netrw#fs#ComposePath ( b: netrw_curdir , fname ) 3299endif 3300 3301elseif fname =~ '^/' 3302" not windows, full path given 3303let ret = fname 3304else 3305" not windows, relative path given 3306let ret = netrw#fs#ComposePath ( b: netrw_curdir , fname ) 3307endif 3308else 3309" vim and netrw agree on the current directory 3310let ret = fname 3311endif 3312 3313return ret 3314endfunction 3315 3316" s:NetrwFileInfo: supports qf (query for file information) {{{2 3317function s: NetrwFileInfo ( islocal , fname ) 3318let ykeep = @@ 3319if a: islocal 3320let lsopt = "-lsad" 3321if g: netrw_sizestyle =~# 'H' 3322let lsopt = "-lsadh" 3323elseif g: netrw_sizestyle =~# 'h' 3324let lsopt = "-lsadh --si" 3325endif 3326if ( has ( "unix" ) || has ( "macunix" )) && executable ( "/bin/ls" ) 3327 3328if getline ( "." ) == "../" 3329echo system ( "/bin/ls " . lsopt . " " . netrw#os#Escape ( ".." )) 3330 3331elseif w: netrw_liststyle == s: TREELIST && getline ( "." ) !~ '^' . s: treedepthstring 3332echo system ( "/bin/ls " . lsopt . " " . netrw#os#Escape ( b: netrw_curdir )) 3333 3334elseif exists ( "b:netrw_curdir" ) 3335echo system ( "/bin/ls " . lsopt . " " . netrw#os#Escape ( netrw#fs#ComposePath ( b: netrw_curdir , a: fname ))) 3336 3337else 3338echo system ( "/bin/ls " . lsopt . " " . netrw#os#Escape ( s: NetrwFile ( a: fname ))) 3339endif 3340else 3341" use vim functions to return information about file below cursor 3342if ! isdirectory ( s: NetrwFile ( a: fname )) && ! filereadable ( s: NetrwFile ( a: fname )) && a: fname =~ '[*@/]' 3343let fname = substitute ( a: fname , ".$" , "" , "" ) 3344else 3345let fname = a: fname 3346endif 3347let t = getftime ( s: NetrwFile ( fname )) 3348let sz = getfsize ( s: NetrwFile ( fname )) 3349if g: netrw_sizestyle =~# "[hH]" 3350let sz = s: NetrwHumanReadable ( sz ) 3351endif 3352echo a: fname . ": " . sz . " " . strftime ( g: netrw_timefmt , getftime ( s: NetrwFile ( fname ))) 3353endif 3354else 3355echo "sorry, \"qf\" not supported yet for remote files" 3356endif 3357let @@= ykeep 3358endfunction 3359 3360" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2 3361" returns 0=cleared buffer 3362" 1=re-used buffer (buffer not cleared) 3363" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix) 3364function s: NetrwGetBuffer ( islocal , dirname ) 3365let dirname = a: dirname 3366 3367" re-use buffer if possible {{{3 3368if ! exists ( "s:netrwbuf" ) 3369let s: netrwbuf = {} 3370endif 3371 3372if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3373let bufnum = -1 3374 3375if ! empty ( s: netrwbuf ) && has_key ( s: netrwbuf , netrw#fs#AbsPath ( dirname )) 3376if has_key ( s: netrwbuf , "NetrwTreeListing" ) 3377let bufnum = s: netrwbuf [ "NetrwTreeListing" ] 3378else 3379let bufnum = s: netrwbuf [ netrw#fs#AbsPath ( dirname )] 3380endif 3381if ! bufexists ( bufnum ) 3382call remove ( s: netrwbuf , "NetrwTreeListing" ) 3383let bufnum = -1 3384endif 3385elseif bufnr ( "NetrwTreeListing" ) != -1 3386let bufnum = bufnr ( "NetrwTreeListing" ) 3387else 3388let bufnum = -1 3389endif 3390 3391elseif has_key ( s: netrwbuf , netrw#fs#AbsPath ( dirname )) 3392let bufnum = s: netrwbuf [ netrw#fs#AbsPath ( dirname )] 3393if ! bufexists ( bufnum ) 3394call remove ( s: netrwbuf , netrw#fs#AbsPath ( dirname )) 3395let bufnum = -1 3396endif 3397 3398else 3399let bufnum = -1 3400endif 3401 3402" highjack the current buffer 3403" IF the buffer already has the desired name 3404" AND it is empty 3405let curbuf = bufname ( "%" ) 3406if curbuf == '.' 3407let curbuf = getcwd () 3408endif 3409if dirname == curbuf && line ( "$" ) == 1 && getline ( "%" ) == "" 3410return 0 3411else " DEBUG 3412endif 3413" Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems 3414 3415" get enew buffer and name it -or- re-use buffer {{{3 3416if bufnum < 0 " get enew buffer and name it 3417call s: NetrwEnew ( dirname ) 3418" name the buffer 3419if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3420" Got enew buffer; transform into a NetrwTreeListing 3421let w: netrw_treebufnr = bufnr ( "%" ) 3422call s: NetrwBufRename ( "NetrwTreeListing" ) 3423if g: netrw_use_noswf 3424setl nobl bt = nofilenoswf 3425else 3426setl nobl bt = nofile 3427endif 3428nnoremap <silent> <buffer> [[ :sil call< SID > TreeListMove('[[')< cr > 3429nnoremap <silent> <buffer> ]] :sil call< SID > TreeListMove(']]')< cr > 3430nnoremap <silent> <buffer> [] :sil call< SID > TreeListMove('[]')< cr > 3431nnoremap <silent> <buffer> ][ :sil call< SID > TreeListMove('][')< cr > 3432else 3433call s: NetrwBufRename ( dirname ) 3434" enter the new buffer into the s:netrwbuf dictionary 3435let s: netrwbuf [ netrw#fs#AbsPath ( dirname )] = bufnr ( "%" ) 3436endif 3437 3438else " Re-use the buffer 3439" ignore all events 3440let eikeep = & ei 3441setl ei = all 3442 3443if & ft == "netrw" 3444exe "sil! NetrwKeepj noswapfile b " . bufnum 3445else 3446call s: NetrwEditBuf ( bufnum ) 3447endif 3448if bufname ( "%" ) == '.' 3449call s: NetrwBufRename ( getcwd ()) 3450endif 3451 3452" restore ei 3453let & ei = eikeep 3454 3455if line ( "$" ) <= 1 && getline ( 1 ) == "" 3456" empty buffer 3457NetrwKeepj call s:NetrwListSettings(a:islocal) 3458return 0 3459 3460elseif g: netrw_fastbrowse == 0 || ( a: islocal && g: netrw_fastbrowse == 1 ) 3461NetrwKeepj call s:NetrwListSettings(a:islocal) 3462sil NetrwKeepj %d _ 3463return 0 3464 3465elseif exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3466setl ma 3467sil NetrwKeepj %d _ 3468NetrwKeepj call s:NetrwListSettings(a:islocal) 3469return 0 3470 3471else 3472return 1 3473endif 3474endif 3475 3476" do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3 3477" fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) 3478" slow 0 D D Deleting a buffer implies it will not be re-used (slow) 3479" med 1 D H 3480" fast 2 H H 3481let fname = expand ( "%" ) 3482NetrwKeepj call s:NetrwListSettings(a:islocal) 3483call s: NetrwBufRename ( fname ) 3484 3485" delete all lines from buffer {{{3 3486sil ! keepalt NetrwKeepj %d _ 3487 3488return 0 3489endfunction 3490 3491" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2 3492function s: NetrwGetWord () 3493let keepsol = & l: sol 3494setl nosol 3495 3496call s: UseBufWinVars () 3497 3498" insure that w:netrw_liststyle is set up 3499if ! exists ( "w:netrw_liststyle" ) 3500if exists ( "g:netrw_liststyle" ) 3501let w: netrw_liststyle = g: netrw_liststyle 3502else 3503let w: netrw_liststyle = s: THINLIST 3504endif 3505endif 3506 3507if exists ( "w:netrw_bannercnt" ) && line ( "." ) < w: netrw_bannercnt 3508" Active Banner support 3509NetrwKeepj norm! 0 3510let dirname = "./" 3511let curline = getline ( '.' ) 3512 3513if curline =~# '"\s*Sorted by\s' 3514NetrwKeepj norm! "_s 3515let s: netrw_skipbrowse = 1 3516echo 'Pressing "s" also works' 3517 3518elseif curline =~# '"\s*Sort sequence:' 3519let s: netrw_skipbrowse = 1 3520echo 'Press "S" to edit sorting sequence' 3521 3522elseif curline =~# '"\s*Quick Help:' 3523NetrwKeepj norm! ? 3524let s: netrw_skipbrowse = 1 3525 3526elseif curline =~# '"\s*\%(Hiding\|Showing\):' 3527NetrwKeepj norm! a 3528let s: netrw_skipbrowse = 1 3529echo 'Pressing "a" also works' 3530 3531elseif line ( "$" ) > w: netrw_bannercnt 3532exe 'sil NetrwKeepj ' . w: netrw_bannercnt 3533endif 3534 3535elseif w: netrw_liststyle == s: THINLIST 3536NetrwKeepj norm! 0 3537let dirname = substitute ( getline ( '.' ), '\t -->.*$' , '' , '' ) 3538 3539elseif w: netrw_liststyle == s: LONGLIST 3540NetrwKeepj norm! 0 3541let dirname = substitute ( getline ( '.' ), '^\(\%(\S\+ \)*\S\+\).\{-}$' , '\1' , 'e' ) 3542 3543elseif exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3544let dirname = substitute ( getline ( '.' ), '^\(' . s: treedepthstring . '\)*' , '' , 'e' ) 3545let dirname = substitute ( dirname , '\t -->.*$' , '' , '' ) 3546 3547else 3548let dirname = getline ( '.' ) 3549 3550if ! exists ( "b:netrw_cpf" ) 3551let b: netrw_cpf = 0 3552exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' 3553call histdel ( "/" , -1 ) 3554endif 3555 3556let filestart = ( virtcol ( "." ) / b: netrw_cpf ) * b: netrw_cpf 3557if filestart == 0 3558NetrwKeepj norm! 0ma 3559else 3560call cursor ( line ( "." ), filestart + 1 ) 3561NetrwKeepj norm! ma 3562endif 3563 3564let dict = {} 3565" save the unnamed register and register 0-9 and a 3566let dict . a = [ getreg ( 'a' ), getregtype ( 'a' )] 3567for i in range ( 0 , 9 ) 3568let dict [ i ] = [ getreg ( i ), getregtype ( i )] 3569endfor 3570let dict . unnamed = [ getreg ( '' ), getregtype ( '' )] 3571 3572let eofname = filestart + b: netrw_cpf + 1 3573if eofname <= col ( "$" ) 3574call cursor ( line ( "." ), filestart + b: netrw_cpf + 1 ) 3575NetrwKeepj norm! "ay`a 3576else 3577NetrwKeepj norm! "ay$ 3578endif 3579 3580let dirname = @a 3581call s: RestoreRegister ( dict ) 3582 3583let dirname = substitute ( dirname , '\s\+$' , '' , 'e' ) 3584endif 3585 3586" symlinks are indicated by a trailing "@". Remove it before further processing. 3587let dirname = substitute ( dirname , "@$" , "" , "" ) 3588 3589" executables are indicated by a trailing "*". Remove it before further processing. 3590let dirname = substitute ( dirname , "\*$" , "" , "" ) 3591 3592let & l: sol = keepsol 3593 3594return dirname 3595endfunction 3596 3597" s:NetrwListSettings: make standard settings for making a netrw listing {{{2 3598" g:netrw_bufsettings will be used after the listing is produced. 3599" Called by s:NetrwGetBuffer() 3600function s: NetrwListSettings ( islocal ) 3601let fname = bufname ( "%" ) 3602" nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings) 3603setl bt = nofile nobl ma nonu nowrap noro nornu 3604call s: NetrwBufRename ( fname ) 3605if g: netrw_use_noswf 3606setl noswf 3607endif 3608exe "setl ts=" . ( g: netrw_maxfilenamelen + 1 ) 3609setl isk += .,~,- 3610if g: netrw_fastbrowse > a: islocal 3611setl bh = hide 3612else 3613setl bh = delete 3614endif 3615endfunction 3616 3617" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2 3618" islocal=0: remote browsing 3619" =1: local browsing 3620function s: NetrwListStyle ( islocal ) 3621let ykeep = @@ 3622let fname = s: NetrwGetWord () 3623if ! exists ( "w:netrw_liststyle" ) | let w: netrw_liststyle = g: netrw_liststyle | endif 3624let svpos = winsaveview () 3625let w: netrw_liststyle = ( w: netrw_liststyle + 1 ) % s: MAXLIST 3626 3627" repoint t:netrw_lexbufnr if appropriate 3628if exists ( "t:netrw_lexbufnr" ) && bufnr ( "%" ) == t: netrw_lexbufnr 3629let repointlexbufnr = 1 3630endif 3631 3632if w: netrw_liststyle == s: THINLIST 3633" use one column listing 3634let g: netrw_list_cmd = substitute ( g: netrw_list_cmd , ' -l' , '' , 'ge' ) 3635 3636elseif w: netrw_liststyle == s: LONGLIST 3637" use long list 3638let g: netrw_list_cmd = g: netrw_list_cmd . " -l" 3639 3640elseif w: netrw_liststyle == s: WIDELIST 3641" give wide list 3642let g: netrw_list_cmd = substitute ( g: netrw_list_cmd , ' -l' , '' , 'ge' ) 3643 3644elseif exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 3645let g: netrw_list_cmd = substitute ( g: netrw_list_cmd , ' -l' , '' , 'ge' ) 3646 3647else 3648call netrw#msg#Notify ( 'WARNING' , printf ( 'bad value for g:netrw_liststyle (=%s)' , w: netrw_liststyle )) 3649let g: netrw_liststyle = s: THINLIST 3650let w: netrw_liststyle = g: netrw_liststyle 3651let g: netrw_list_cmd = substitute ( g: netrw_list_cmd , ' -l' , '' , 'ge' ) 3652endif 3653setl ma noro 3654 3655" clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh 3656sil ! NetrwKeepj %d _ 3657" following prevents tree listing buffer from being marked "modified" 3658setl nomod 3659 3660" refresh the listing 3661NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 3662NetrwKeepj call s:NetrwCursor(0) 3663 3664" repoint t:netrw_lexbufnr if appropriate 3665if exists ( "repointlexbufnr" ) 3666let t: netrw_lexbufnr = bufnr ( "%" ) 3667endif 3668 3669" restore position; keep cursor on the filename 3670NetrwKeepj call winrestview(svpos) 3671let @@ = ykeep 3672 3673endfunction 3674 3675" s:NetrwBannerCtrl: toggles the display of the banner {{{2 3676function s: NetrwBannerCtrl ( islocal ) 3677let ykeep = @@ 3678" toggle the banner (enable/suppress) 3679let g: netrw_banner = ! g: netrw_banner 3680 3681" refresh the listing 3682let svpos = winsaveview () 3683call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 3684 3685" keep cursor on the filename 3686if g: netrw_banner && exists ( "w:netrw_bannercnt" ) && line ( "." ) >= w: netrw_bannercnt 3687let fname = s: NetrwGetWord () 3688sil NetrwKeepj $ 3689let result = search ( '\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs' . escape ( fname , '.\[]*$^' ) . '\%(\s\{2,}\|$\)' , 'bc' ) 3690if result <= 0 && exists ( "w:netrw_bannercnt" ) 3691exe "NetrwKeepj " . w: netrw_bannercnt 3692endif 3693endif 3694let @@ = ykeep 3695endfunction 3696 3697" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2 3698" 3699" No bang: enters files/directories into Netrw's bookmark system 3700" No argument and in netrw buffer: 3701" if there are marked files: bookmark marked files 3702" otherwise : bookmark file/directory under cursor 3703" No argument and not in netrw buffer: bookmarks current open file 3704" Has arguments: globs them individually and bookmarks them 3705" 3706" With bang: deletes files/directories from Netrw's bookmark system 3707function s: NetrwBookmark ( del ,...) 3708if a: 0 == 0 3709if & ft == "netrw" 3710let curbufnr = bufnr ( "%" ) 3711 3712if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 3713" for every filename in the marked list 3714let svpos = winsaveview () 3715let islocal = expand ( "%" ) !~ '^\a\{3,}://' 3716for fname in s: netrwmarkfilelist_ { curbufnr } 3717if a: del | call s: DeleteBookmark ( fname ) | else | call s: MakeBookmark ( fname ) | endif 3718endfor 3719let curdir = exists ( "b:netrw_curdir" ) ? b: netrw_curdir : getcwd () 3720call s: NetrwUnmarkList ( curbufnr , curdir ) 3721NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0)) 3722NetrwKeepj call winrestview(svpos) 3723else 3724let fname = s: NetrwGetWord () 3725if a: del | call s: DeleteBookmark ( fname ) | else | call s: MakeBookmark ( fname ) | endif 3726endif 3727 3728else 3729" bookmark currently open file 3730let fname = expand ( "%" ) 3731if a: del | call s: DeleteBookmark ( fname ) | else | call s: MakeBookmark ( fname ) | endif 3732endif 3733 3734else 3735" bookmark specified files 3736" attempts to infer if working remote or local 3737" by deciding if the current file begins with an url 3738" Globbing cannot be done remotely. 3739let islocal = expand ( "%" ) !~ '^\a\{3,}://' 3740let i = 1 3741while i <= a: 0 3742if islocal 3743let mbfiles = glob ( fnameescape ( a: {i}), 0, 1, 1) 3744else 3745let mbfiles = [ a: {i}] 3746endif 3747for mbfile in mbfiles 3748if a: del 3749call s: DeleteBookmark ( mbfile ) 3750else 3751call s: MakeBookmark ( mbfile ) 3752endif 3753endfor 3754let i = i + 1 3755endwhile 3756endif 3757 3758" update the menu 3759call s: NetrwBookmarkMenu () 3760endfunction 3761 3762" s:NetrwBookmarkMenu: Uses menu priorities {{{2 3763" .2.[cnt] for bookmarks, and 3764" .3.[cnt] for history 3765" (see s:NetrwMenu()) 3766function s: NetrwBookmarkMenu () 3767if ! exists ( "s:netrw_menucnt" ) 3768return 3769endif 3770 3771" the following test assures that gvim is running, has menus available, and has menus enabled. 3772if has ( "gui" ) && has ( "menu" ) && has ( "gui_running" ) && & go =~# 'm' && g: netrw_menu 3773if exists ( "g:NetrwTopLvlMenu" ) 3774exe 'sil! unmenu ' . g: NetrwTopLvlMenu . 'Bookmarks' 3775exe 'sil! unmenu ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.Bookmark\ Delete' 3776endif 3777if ! exists ( "s:netrw_initbookhist" ) 3778call s: NetrwBookHistRead () 3779endif 3780 3781" show bookmarked places 3782if exists ( "g:netrw_bookmarklist" ) && g: netrw_bookmarklist != [] && g: netrw_dirhistmax > 0 3783let cnt = 1 3784for bmd in g: netrw_bookmarklist 3785let ebmd = escape ( bmd , g: netrw_menu_escape ) 3786let fbmd = escape ( fnameescape ( bmd ), '|' ) 3787 3788" show bookmarks for goto menu 3789exe 'sil! menu ' . g: NetrwMenuPriority . ".2." . cnt . " " . g: NetrwTopLvlMenu . 'Bookmarks.' . ebmd . ' :e ' . fbmd . "\<cr>" 3790 3791" show bookmarks for deletion menu 3792exe 'sil! menu ' . g: NetrwMenuPriority . ".8.2." . cnt . " " . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.Bookmark\ Delete.' . ebmd . ' ' . cnt . "mB" 3793let cnt = cnt + 1 3794endfor 3795 3796endif 3797 3798" show directory browsing history 3799if g: netrw_dirhistmax > 0 3800let cnt = g: netrw_dirhistcnt 3801let first = 1 3802let histcnt = 0 3803while ( first || cnt != g: netrw_dirhistcnt ) 3804let histcnt = histcnt + 1 3805let priority = g: netrw_dirhistcnt + histcnt 3806if exists ( "g:netrw_dirhist_{cnt}" ) 3807let histdir = escape ( g: netrw_dirhist_ { cnt }, g: netrw_menu_escape ) 3808let ehistdir = escape ( fnameescape ( g: netrw_dirhist_ { cnt }), '|' ) 3809exe 'sil! menu ' . g: NetrwMenuPriority . ".3." . priority . " " . g: NetrwTopLvlMenu . 'History.' . histdir . ' :e ' . ehistdir . "\<cr>" 3810endif 3811let first = 0 3812let cnt = ( cnt - 1 ) % g: netrw_dirhistmax 3813if cnt < 0 3814let cnt = cnt + g: netrw_dirhistmax 3815endif 3816endwhile 3817endif 3818 3819endif 3820endfunction 3821 3822" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2 3823" directory and a new directory name. Also, if the 3824" "new directory name" is actually a file, 3825" NetrwBrowseChgDir() edits the file. 3826" cursor=0: newdir is relative to b:netrw_curdir 3827" =1: newdir is relative to the path to the word under the cursor in 3828" tree view 3829function s: NetrwBrowseChgDir ( islocal , newdir , cursor , ...) 3830let ykeep = @@ 3831if ! exists ( "b:netrw_curdir" ) 3832let @@ = ykeep 3833return 3834endif 3835 3836" NetrwBrowseChgDir; save options and initialize {{{3 3837call s: SavePosn ( s: netrw_posn ) 3838NetrwKeepj call s:NetrwOptionsSave("s:") 3839NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 3840 3841let newdir = a: newdir 3842let dirname = b: netrw_curdir 3843 3844if a: cursor && w: netrw_liststyle == s: TREELIST 3845" dirname is the path to the word under the cursor 3846let dirname = s: NetrwTreePath ( w: netrw_treetop ) 3847" If the word under the cursor is a directory (except for ../), NetrwTreePath 3848" returns the full path, including the word under the cursor, remove it 3849if newdir != "../" 3850let dirname = fnamemodify ( dirname , ":h" ) 3851endif 3852endif 3853 3854if has ( "win32" ) 3855let dirname = substitute ( dirname , '\\' , '/' , 'ge' ) 3856endif 3857 3858let dolockout = 0 3859let dorestore = 1 3860 3861" ignore <cr>s when done in the banner 3862if g: netrw_banner 3863if exists ( "w:netrw_bannercnt" ) && line ( "." ) < w: netrw_bannercnt && line ( "$" ) >= w: netrw_bannercnt 3864if getline ( "." ) =~# 'Quick Help' 3865let g: netrw_quickhelp = ( g: netrw_quickhelp + 1 ) % len ( s: QuickHelp ) 3866setl ma noro nowrap 3867NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp]) 3868setl noma nomod nowrap 3869NetrwKeepj call s:NetrwOptionsRestore("s:") 3870endif 3871endif 3872endif 3873 3874" set up o/s-dependent directory recognition pattern 3875let dirpat = has ( "amiga" ) || has ( 'win32' ) ? '[\/:]$' : '/$' 3876 3877if newdir !~ dirpat && ! ( a: islocal && isdirectory ( s: NetrwFile ( netrw#fs#ComposePath ( dirname , newdir )))) 3878" ------------------------------ 3879" NetrwBrowseChgDir: edit a file {{{3 3880" ------------------------------ 3881 3882" save position for benefit of Rexplore 3883let s: rexposn_ { bufnr ( "%" )} = winsaveview () 3884 3885let dirname = isabsolutepath ( newdir ) 3886\ ? netrw#fs#AbsPath ( newdir ) 3887\ : netrw#fs#ComposePath ( dirname , newdir ) 3888 3889" this lets netrw#BrowseX avoid the edit 3890if a: 0 < 1 3891NetrwKeepj call s:NetrwOptionsRestore("s:") 3892let curdir = b: netrw_curdir 3893if ! exists ( "s:didsplit" ) 3894if type ( g: netrw_browse_split ) == 3 3895" open file in server 3896" Note that g:netrw_browse_split is a List: [servername,tabnr,winnr] 3897call s: NetrwServerEdit ( a: islocal , dirname ) 3898return 3899 3900elseif g: netrw_browse_split == 1 3901" horizontally splitting the window first 3902let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winheight ( 0 )) / 100 : - g: netrw_winsize 3903exe "keepalt " . ( g: netrw_alto ? "bel " : "abo " ). winsz . "wincmd s" 3904if !& ea 3905keepalt wincmd _ 3906else 3907exe "keepalt wincmd =" 3908endif 3909call s: SetRexDir ( a: islocal , curdir ) 3910 3911elseif g: netrw_browse_split == 2 3912" vertically splitting the window first 3913let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize 3914exe "keepalt " . ( g: netrw_alto ? "top " : "bot " ) . "vert " . winsz . "wincmd s" 3915if !& ea 3916keepalt wincmd | 3917else 3918exe "keepalt wincmd =" 3919endif 3920call s: SetRexDir ( a: islocal , curdir ) 3921 3922elseif g: netrw_browse_split == 3 3923" open file in new tab 3924keepalt tabnew 3925if ! exists ( "b:netrw_curdir" ) 3926let b: netrw_curdir = getcwd () 3927endif 3928call s: SetRexDir ( a: islocal , curdir ) 3929 3930elseif g: netrw_browse_split == 4 3931" act like "P" (ie. open previous window) 3932if s: NetrwPrevWinOpen ( 2 ) == 3 3933let @@ = ykeep 3934return 3935endif 3936call s: SetRexDir ( a: islocal , curdir ) 3937 3938else 3939" handling a file, didn't split, so remove menu 3940call s: NetrwMenu ( 0 ) 3941" optional change to window 3942if g: netrw_chgwin >= 1 3943if winnr ( "$" ) + 1 == g: netrw_chgwin 3944" if g:netrw_chgwin is set to one more than the last window, then 3945" vertically split the last window to make that window available. 3946let curwin = winnr () 3947exe "NetrwKeepj keepalt " . winnr ( "$" ) . "wincmd w" 3948vs 3949exe "NetrwKeepj keepalt " . curwin . "wincmd w" 3950endif 3951exe "NetrwKeepj keepalt " . g: netrw_chgwin . "wincmd w" 3952endif 3953call s: SetRexDir ( a: islocal , curdir ) 3954endif 3955 3956endif 3957 3958" the point where netrw actually edits the (local) file 3959" if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will 3960" use keepalt to support :e # to return to a directory listing 3961if !& mod 3962" if e the new file would fail due to &mod, then don't change any of the flags 3963let dolockout = 1 3964endif 3965 3966if a: islocal 3967" some like c-^ to return to the last edited file 3968" others like c-^ to return to the netrw buffer 3969" Apr 30, 2020: used to have e! here. That can cause loss of a modified file, 3970" so emit error E37 instead. 3971call s: NetrwEditFile ( "e" , "" , dirname ) 3972call s: NetrwCursor ( 1 ) 3973if & hidden || & bufhidden == "hide" 3974" file came from vim's hidden storage. Don't "restore" options with it. 3975let dorestore = 0 3976endif 3977endif 3978 3979" handle g:Netrw_funcref -- call external-to-netrw functions 3980" This code will handle g:Netrw_funcref as an individual function reference 3981" or as a list of function references. It will ignore anything that's not 3982" a function reference. See :help Funcref for information about function references. 3983if exists ( "g:Netrw_funcref" ) 3984if type ( g: Netrw_funcref ) == 2 3985NetrwKeepj call g:Netrw_funcref() 3986elseif type ( g: Netrw_funcref ) == 3 3987for Fncref in g: Netrw_funcref 3988if type ( Fncref ) == 2 3989NetrwKeepj call Fncref() 3990endif 3991endfor 3992endif 3993endif 3994endif 3995 3996elseif newdir =~ '^/' 3997" ---------------------------------------------------- 3998" NetrwBrowseChgDir: just go to the new directory spec {{{3 3999" ---------------------------------------------------- 4000let dirname = newdir 4001NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4002NetrwKeepj call s:NetrwOptionsRestore("s:") 4003norm ! m` 4004 4005elseif newdir == './' 4006" --------------------------------------------- 4007" NetrwBrowseChgDir: refresh the directory list {{{3 4008" --------------------------------------------- 4009NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4010norm ! m` 4011 4012elseif newdir == '../' 4013" -------------------------------------- 4014" NetrwBrowseChgDir: go up one directory {{{3 4015" -------------------------------------- 4016 4017" The following regexps expect '/' as path separator 4018let dirname = substitute ( netrw#fs#AbsPath ( dirname ), '\\' , '/' , 'ge' ) . '/' 4019 4020if w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treedict" ) 4021" force a refresh 4022setl noro ma 4023NetrwKeepj %d _ 4024endif 4025 4026if has ( "amiga" ) 4027" amiga 4028if a: islocal 4029let dirname = substitute ( dirname , '^\(.*[/:]\)\([^/]\+$\)' , '\1' , '' ) 4030let dirname = substitute ( dirname , '/$' , '' , '' ) 4031else 4032let dirname = substitute ( dirname , '^\(.*[/:]\)\([^/]\+/$\)' , '\1' , '' ) 4033endif 4034 4035elseif ! g: netrw_cygwin && has ( "win32" ) 4036" windows 4037if a: islocal 4038let dirname = substitute ( dirname , '^\(.*\)/\([^/]\+\)/$' , '\1' , '' ) 4039if dirname == "" 4040let dirname = '/' 4041endif 4042else 4043let dirname = substitute ( dirname , '^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$' , '\1\2' , '' ) 4044endif 4045if dirname =~ '^\a:$' 4046let dirname = dirname . '/' 4047endif 4048 4049else 4050" unix or cygwin 4051if a: islocal 4052let dirname = substitute ( dirname , '^\(.*\)/\([^/]\+\)/$' , '\1' , '' ) 4053if dirname == "" 4054let dirname = '/' 4055endif 4056else 4057let dirname = substitute ( dirname , '^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$' , '\1\2' , '' ) 4058endif 4059endif 4060NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4061norm ! m` 4062 4063elseif exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treedict" ) 4064" -------------------------------------- 4065" NetrwBrowseChgDir: Handle Tree Listing {{{3 4066" -------------------------------------- 4067" force a refresh (for TREELIST, NetrwTreeDir() will force the refresh) 4068setl noro ma 4069if ! ( exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "b:netrw_curdir" )) 4070NetrwKeepj %d _ 4071endif 4072let treedir = s: NetrwTreeDir ( a: islocal ) 4073let s: treecurpos = winsaveview () 4074let haskey = 0 4075 4076" search treedict for tree dir as-is 4077if has_key ( w: netrw_treedict , treedir ) 4078let haskey = 1 4079else 4080endif 4081 4082" search treedict for treedir with a [/@] appended 4083if ! haskey && treedir !~ '[/@]$' 4084if has_key ( w: netrw_treedict , treedir . "/" ) 4085let treedir = treedir . "/" 4086let haskey = 1 4087else 4088endif 4089endif 4090 4091" search treedict for treedir with any trailing / elided 4092if ! haskey && treedir =~ '/$' 4093let treedir = substitute ( treedir , '/$' , '' , '' ) 4094if has_key ( w: netrw_treedict , treedir ) 4095let haskey = 1 4096else 4097endif 4098endif 4099 4100if haskey 4101" close tree listing for selected subdirectory 4102call remove ( w: netrw_treedict , treedir ) 4103let dirname = w: netrw_treetop 4104else 4105" go down one directory 4106let dirname = substitute ( treedir , '/*$' , '/' , '' ) 4107endif 4108NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4109let s: treeforceredraw = 1 4110 4111else 4112" ---------------------------------------- 4113" NetrwBrowseChgDir: Go down one directory {{{3 4114" ---------------------------------------- 4115let dirname = netrw#fs#ComposePath ( dirname , newdir ) 4116NetrwKeepj call s:SetRexDir(a:islocal,dirname) 4117norm ! m` 4118endif 4119 4120" -------------------------------------- 4121" NetrwBrowseChgDir: Restore and Cleanup {{{3 4122" -------------------------------------- 4123if dorestore 4124" dorestore is zero'd when a local file was hidden or bufhidden; 4125" in such a case, we want to keep whatever settings it may have. 4126NetrwKeepj call s:NetrwOptionsRestore("s:") 4127endif 4128if dolockout && dorestore 4129if filewritable ( dirname ) 4130setl ma noro nomod 4131else 4132setl ma ro nomod 4133endif 4134endif 4135call s: RestorePosn ( s: netrw_posn ) 4136let @@ = ykeep 4137 4138return dirname 4139endfunction 4140 4141" s:NetrwBrowseUpDir: implements the "-" mappings {{{2 4142" for thin, long, and wide: cursor placed just after banner 4143" for tree, keeps cursor on current filename 4144function s: NetrwBrowseUpDir ( islocal ) 4145if exists ( "w:netrw_bannercnt" ) && line ( "." ) < w: netrw_bannercnt - 1 4146" this test needed because occasionally this function seems to be incorrectly called 4147" when multiple leftmouse clicks are taken when atop the one line help in the banner. 4148" I'm allowing the very bottom line to permit a "-" exit so that one may escape empty 4149" directories. 4150return 4151endif 4152 4153norm ! 0 4154if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treedict" ) 4155let curline = getline ( "." ) 4156let swwline = winline () - 1 4157if exists ( "w:netrw_treetop" ) 4158let b: netrw_curdir = w: netrw_treetop 4159elseif exists ( "b:netrw_curdir" ) 4160let w: netrw_treetop = b: netrw_curdir 4161else 4162let w: netrw_treetop = getcwd () 4163let b: netrw_curdir = w: netrw_treetop 4164endif 4165let curfile = getline ( "." ) 4166let curpath = s: NetrwTreePath ( w: netrw_treetop ) 4167if a: islocal 4168call netrw#LocalBrowseCheck ( s: NetrwBrowseChgDir ( 1 , '../' , 0 )) 4169else 4170call s: NetrwBrowse ( 0 , s: NetrwBrowseChgDir ( 0 , '../' , 0 )) 4171endif 4172if w: netrw_treetop == '/' 4173keepj call search('^\M'.curfile,"w") 4174elseif curfile == '../' 4175keepj call search('^\M'.curfile,"wb") 4176else 4177while 1 4178keepj call search('^\M'.s:treedepthstring.curfile,"wb") 4179let treepath = s: NetrwTreePath ( w: netrw_treetop ) 4180if treepath == curpath 4181break 4182endif 4183endwhile 4184endif 4185 4186else 4187call s: SavePosn ( s: netrw_posn ) 4188if exists ( "b:netrw_curdir" ) 4189let curdir = b: netrw_curdir 4190else 4191let curdir = expand ( getcwd ()) 4192endif 4193if a: islocal 4194call netrw#LocalBrowseCheck ( s: NetrwBrowseChgDir ( 1 , '../' , 0 )) 4195else 4196call s: NetrwBrowse ( 0 , s: NetrwBrowseChgDir ( 0 , '../' , 0 )) 4197endif 4198call s: RestorePosn ( s: netrw_posn ) 4199let curdir = substitute ( curdir , '^.*[\/]' , '' , '' ) 4200let curdir = '\<' . escape ( curdir , '~' ) . '/' 4201call search ( curdir , 'wc' ) 4202endif 4203endfunction 4204 4205" netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2 4206" given filename; typically this means given their extension. 4207function netrw#BrowseX ( fname ) 4208" special core dump handler 4209if a: fname =~ '/core\(\.\d\+\)\=$' && exists ( "g:Netrw_corehandler" ) 4210if type ( g: Netrw_corehandler ) == v: t_func 4211" g:Netrw_corehandler is a function reference (see :help Funcref) 4212call g: Netrw_corehandler ( s: NetrwFile ( a: fname )) 4213elseif type ( g: Netrw_corehandler ) == v: t_list 4214" g:Netrw_corehandler is a List of function references (see :help Funcref) 4215for Fncref in g: Netrw_corehandler 4216if type ( Fncref ) == v: t_func 4217call Fncref ( a: fname ) 4218endif 4219endfor 4220endif 4221return 4222endif 4223 4224let fname = a: fname 4225" special ~ handler for local 4226if fname =~ '^\~' && expand ( "$HOME" ) != "" 4227let fname = substitute ( fname , '^\~' , expand ( "$HOME" ), '' ) 4228endif 4229 4230if fname =~ '^[a-z]\+://' 4231" open a remote file 4232call netrw#os#Open ( fname ) 4233else 4234call netrw#os#Open ( s: NetrwFile ( fname )) 4235endif 4236endfunction 4237 4238" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2 4239" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer 4240" to become an unlisted buffer, so in that case don't bwipe it. 4241function s: NetrwBufRename ( newname ) 4242let oldbufname = bufname ( bufnr ( "%" )) 4243 4244if oldbufname != a: newname 4245let b: junk = 1 4246exe 'sil! keepj keepalt file ' . fnameescape ( a: newname ) 4247let oldbufnr = bufnr ( oldbufname ) 4248if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr ( "%" ) 4249exe "bwipe! " . oldbufnr 4250endif 4251endif 4252 4253endfunction 4254 4255" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2 4256function netrw#CheckIfRemote (...) 4257if a: 0 > 0 4258let curfile = a: 1 4259else 4260let curfile = expand ( "%" ) 4261endif 4262" Ignore terminal buffers 4263if & buftype ==# 'terminal' 4264return 0 4265endif 4266if curfile =~ '^\a\{3,}://' 4267return 1 4268else 4269return 0 4270endif 4271endfunction 4272 4273" s:NetrwChgPerm: (implements "gp") change file permission {{{2 4274function s: NetrwChgPerm ( islocal , curdir ) 4275let ykeep = @@ 4276call inputsave () 4277let newperm = input ( "Enter new permission: " ) 4278call inputrestore () 4279let fullpath = fnamemodify ( netrw#fs#PathJoin ( a: curdir , expand ( "<cfile>" )), ':p' ) 4280let chgperm = substitute ( g: netrw_chgperm , '\<FILENAME\>' , netrw#os#Escape ( fullpath ), '' ) 4281let chgperm = substitute ( chgperm , '\<PERM\>' , netrw#os#Escape ( newperm ), '' ) 4282call system ( chgperm ) 4283if v: shell_error != 0 4284NetrwKeepj call netrw#msg#Notify('WARNING', printf('changing permission on file<%s> seems to have failed', fullpath)) 4285endif 4286if a: islocal 4287NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4288endif 4289let @@ = ykeep 4290endfunction 4291 4292" s:NetrwClearExplore: clear explore variables (if any) {{{2 4293function s: NetrwClearExplore () 42942 match none 4295if exists ( "s:explore_match" ) | unlet s: explore_match | endif 4296if exists ( "s:explore_indx" ) | unlet s: explore_indx | endif 4297if exists ( "s:netrw_explore_prvdir" ) | unlet s: netrw_explore_prvdir | endif 4298if exists ( "s:dirstarstar" ) | unlet s: dirstarstar | endif 4299if exists ( "s:explore_prvdir" ) | unlet s: explore_prvdir | endif 4300if exists ( "w:netrw_explore_indx" ) | unlet w: netrw_explore_indx | endif 4301if exists ( "w:netrw_explore_listlen" ) | unlet w: netrw_explore_listlen | endif 4302if exists ( "w:netrw_explore_list" ) | unlet w: netrw_explore_list | endif 4303if exists ( "w:netrw_explore_bufnr" ) | unlet w: netrw_explore_bufnr | endif 4304" redraw! 4305endfunction 4306 4307" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2 4308function s: NetrwEditBuf ( bufnum ) 4309if exists ( "g:netrw_altfile" ) && g: netrw_altfile && & ft == "netrw" 4310exe "sil! NetrwKeepj keepalt noswapfile b " . fnameescape ( a: bufnum ) 4311else 4312exe "sil! NetrwKeepj noswapfile b " . fnameescape ( a: bufnum ) 4313endif 4314endfunction 4315 4316" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2 4317" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME> 4318function s: NetrwEditFile ( cmd , opt , fname ) 4319if exists ( "g:netrw_altfile" ) && g: netrw_altfile && & ft == "netrw" 4320exe "NetrwKeepj noswapfile keepalt " . a: opt . " " . a: cmd . " " . fnameescape ( a: fname ) 4321else 4322if a: cmd =~# 'e\%[new]!' && !& hidden && getbufvar ( bufname ( '%' ), '&modified' , 0 ) 4323call setbufvar ( bufname ( '%' ), '&bufhidden' , 'hide' ) 4324endif 4325exe "NetrwKeepj noswapfile " . a: opt . " " . a: cmd . " " . fnameescape ( a: fname ) 4326endif 4327endfunction 4328 4329" s:NetrwExploreListUniq: {{{2 4330function s: NetrwExploreListUniq ( explist ) 4331" this assumes that the list is already sorted 4332let newexplist = [] 4333for member in a: explist 4334if ! exists ( "uniqmember" ) || member != uniqmember 4335let uniqmember = member 4336let newexplist = newexplist + [ member ] 4337endif 4338endfor 4339return newexplist 4340endfunction 4341 4342" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2 4343function s: NetrwForceChgDir ( islocal , newdir ) 4344let ykeep = @@ 4345if a: newdir !~ '/$' 4346" ok, looks like force is needed to get directory-style treatment 4347if a: newdir =~ '@$' 4348let newdir = substitute ( a: newdir , '@$' , '/' , '' ) 4349elseif a: newdir =~ '[*=|\\]$' 4350let newdir = substitute ( a: newdir , '.$' , '/' , '' ) 4351else 4352let newdir = a: newdir . '/' 4353endif 4354else 4355" should already be getting treatment as a directory 4356let newdir = a: newdir 4357endif 4358let newdir = s: NetrwBrowseChgDir ( a: islocal , newdir , 0 ) 4359call s: NetrwBrowse ( a: islocal , newdir ) 4360let @@ = ykeep 4361endfunction 4362 4363" s:NetrwForceFile: (gf support) Force treatment as a file {{{2 4364function s: NetrwForceFile ( islocal , newfile ) 4365if a: newfile =~ '[/@*=|\\]$' 4366let newfile = substitute ( a: newfile , '.$' , '' , '' ) 4367else 4368let newfile = a: newfile 4369endif 4370if a: islocal 4371call s: NetrwBrowseChgDir ( a: islocal , newfile , 0 ) 4372else 4373call s: NetrwBrowse ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , newfile , 0 )) 4374endif 4375endfunction 4376 4377" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2 4378" and switches the hiding mode. The actual hiding is done by 4379" s:NetrwListHide(). 4380" g:netrw_hide= 0: show all 4381" 1: show not-hidden files 4382" 2: show hidden files only 4383function s: NetrwHide ( islocal ) 4384let ykeep = @@ 4385let svpos = winsaveview () 4386 4387if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 4388 4389" hide the files in the markfile list 4390for fname in s: netrwmarkfilelist_ { bufnr ( "%" )} 4391if match ( g: netrw_list_hide , '\<' . fname . '\>' ) != -1 4392" remove fname from hiding list 4393let g: netrw_list_hide = substitute ( g: netrw_list_hide , '..\<' . escape ( fname , g: netrw_fname_escape ) . '\>..' , '' , '' ) 4394let g: netrw_list_hide = substitute ( g: netrw_list_hide , ',,' , ',' , 'g' ) 4395let g: netrw_list_hide = substitute ( g: netrw_list_hide , '^,\|,$' , '' , '' ) 4396else 4397" append fname to hiding list 4398if exists ( "g:netrw_list_hide" ) && g: netrw_list_hide != "" 4399let g: netrw_list_hide = g: netrw_list_hide . ',\<' . escape ( fname , g: netrw_fname_escape ) . '\>' 4400else 4401let g: netrw_list_hide = '\<' . escape ( fname , g: netrw_fname_escape ) . '\>' 4402endif 4403endif 4404endfor 4405NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir) 4406let g: netrw_hide = 1 4407 4408else 4409 4410" switch between show-all/show-not-hidden/show-hidden 4411let g: netrw_hide = ( g: netrw_hide + 1 ) % 3 4412exe "NetrwKeepj norm! 0" 4413if g: netrw_hide && g: netrw_list_hide == "" 4414call netrw#msg#Notify ( 'WARNING' , 'your hiding list is empty!' ) 4415let @@ = ykeep 4416return 4417endif 4418endif 4419 4420NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4421NetrwKeepj call winrestview(svpos) 4422let @@ = ykeep 4423endfunction 4424 4425" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2 4426function s: NetrwHideEdit ( islocal ) 4427let ykeep = @@ 4428" save current cursor position 4429let svpos = winsaveview () 4430 4431" get new hiding list from user 4432call inputsave () 4433let newhide = input ( "Edit Hiding List: " , g: netrw_list_hide ) 4434call inputrestore () 4435let g: netrw_list_hide = newhide 4436 4437" refresh the listing 4438sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0)) 4439 4440" restore cursor position 4441call winrestview ( svpos ) 4442let @@ = ykeep 4443endfunction 4444 4445" s:NetrwHidden: invoked by "gh" {{{2 4446function s: NetrwHidden ( islocal ) 4447let ykeep = @@ 4448" save current position 4449let svpos = winsaveview () 4450 4451if g: netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+' 4452" remove .file pattern from hiding list 4453let g: netrw_list_hide = substitute ( g: netrw_list_hide , '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+' , '' , '' ) 4454elseif strdisplaywidth ( g: netrw_list_hide ) >= 1 4455let g: netrw_list_hide = g: netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+' 4456else 4457let g: netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+' 4458endif 4459if g: netrw_list_hide =~ '^,' 4460let g: netrw_list_hide = strpart ( g: netrw_list_hide , 1 ) 4461endif 4462 4463" refresh screen and return to saved position 4464NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 4465NetrwKeepj call winrestview(svpos) 4466let @@ = ykeep 4467endfunction 4468 4469" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2 4470function s: NetrwHome () 4471if exists ( 'g:netrw_home' ) 4472let home = expand ( g: netrw_home ) 4473elseif has ( 'nvim' ) 4474let home = netrw#fs#PathJoin ( stdpath ( 'state' ), 'netrw' ) 4475elseif exists ( '$MYVIMDIR' ) 4476let home = expand ( '$MYVIMDIR' ) -> substitute ( '/$' , '' , '' ) 4477else 4478" Pick the first redable directory in 'runtimepath' 4479for path in split ( & rtp , ',' ) 4480if isdirectory ( s: NetrwFile ( path )) && filewritable ( s: NetrwFile ( path )) 4481let home = path 4482break 4483endif 4484endfor 4485 4486if empty ( path ) 4487" just pick the first directory 4488let home = substitute ( & rtp , ',.*$' , '' , '' ) 4489endif 4490endif 4491 4492" insure that the home directory exists 4493if g: netrw_dirhistmax > 0 && ! isdirectory ( s: NetrwFile ( home )) 4494if exists ( "g:netrw_mkdir" ) 4495call system ( g: netrw_mkdir . " " . s: ShellEscape ( s: NetrwFile ( home ))) 4496else 4497call mkdir ( home , 'p' ) 4498endif 4499endif 4500 4501" Normalize directory if on Windows 4502if has ( "win32" ) 4503let home = substitute ( home , '/' , '\\' , 'g' ) 4504endif 4505 4506let g: netrw_home = home 4507return home 4508endfunction 4509 4510" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2 4511function s: NetrwLeftmouse ( islocal ) 4512if exists ( "s:netrwdrag" ) 4513return 4514endif 4515if & ft != "netrw" 4516return 4517endif 4518 4519let ykeep = @@ 4520" check if the status bar was clicked on instead of a file/directory name 4521while getchar ( 0 ) != 0 4522"clear the input stream 4523endwhile 4524call feedkeys ( "\<LeftMouse>" ) 4525let c = getchar () 4526let mouse_lnum = v: mouse_lnum 4527let wlastline = line ( 'w$' ) 4528let lastline = line ( '$' ) 4529if mouse_lnum >= wlastline + 1 || v: mouse_win != winnr () 4530" appears to be a status bar leftmouse click 4531let @@ = ykeep 4532return 4533endif 4534" Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode 4535" Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar 4536" without this test when its disabled. 4537" May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop. 4538if v: mouse_col > virtcol ( '.' ) 4539let @@ = ykeep 4540return 4541endif 4542 4543if a: islocal 4544if exists ( "b:netrw_curdir" ) 4545NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 4546endif 4547else 4548if exists ( "b:netrw_curdir" ) 4549NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 4550endif 4551endif 4552let @@ = ykeep 4553endfunction 4554 4555" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2 4556function s: NetrwCLeftmouse ( islocal ) 4557if & ft != "netrw" 4558return 4559endif 4560call s: NetrwMarkFileTgt ( a: islocal ) 4561endfunction 4562 4563" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2 4564" a:islocal=0 : <c-r> not used, remote 4565" a:islocal=1 : <c-r> not used, local 4566" a:islocal=2 : <c-r> used, remote 4567" a:islocal=3 : <c-r> used, local 4568function s: NetrwServerEdit ( islocal , fname ) 4569let islocal = a: islocal % 2 " =0: remote =1: local 4570let ctrlr = a: islocal >= 2 " =0: <c-r> not used =1: <c-r> used 4571 4572if ( islocal && isdirectory ( s: NetrwFile ( a: fname ))) || ( ! islocal && a: fname =~ '/$' ) 4573" handle directories in the local window -- not in the remote vim server 4574" user must have closed the NETRWSERVER window. Treat as normal editing from netrw. 4575let g: netrw_browse_split = 0 4576if exists ( "s:netrw_browse_split" ) && exists ( "s:netrw_browse_split_" . winnr ()) 4577let g: netrw_browse_split = s: netrw_browse_split_ { winnr ()} 4578unlet s: netrw_browse_split_ { winnr ()} 4579endif 4580call s: NetrwBrowse ( islocal , s: NetrwBrowseChgDir ( islocal , a: fname , 0 )) 4581return 4582endif 4583 4584if has ( "clientserver" ) && executable ( "gvim" ) 4585 4586if exists ( "g:netrw_browse_split" ) && type ( g: netrw_browse_split ) == 3 4587let srvrname = g: netrw_browse_split [ 0 ] 4588let tabnum = g: netrw_browse_split [ 1 ] 4589let winnum = g: netrw_browse_split [ 2 ] 4590 4591if serverlist () !~ '\<' . srvrname . '\>' 4592if ! ctrlr 4593" user must have closed the server window and the user did not use <c-r>, but 4594" used something like <cr>. 4595if exists ( "g:netrw_browse_split" ) 4596unlet g: netrw_browse_split 4597endif 4598let g: netrw_browse_split = 0 4599if exists ( "s:netrw_browse_split_" . winnr ()) 4600let g: netrw_browse_split = s: netrw_browse_split_ { winnr ()} 4601endif 4602call s: NetrwBrowseChgDir ( islocal , a: fname , 0 ) 4603return 4604 4605elseif has ( "win32" ) && executable ( "start" ) 4606" start up remote netrw server under windows 4607call system ( "start gvim --servername " . srvrname ) 4608 4609else 4610" start up remote netrw server under linux 4611call system ( "gvim --servername " . srvrname ) 4612endif 4613endif 4614 4615call remote_send ( srvrname , ":tabn " . tabnum . "\<cr>" ) 4616call remote_send ( srvrname , ":" . winnum . "wincmd w\<cr>" ) 4617call remote_send ( srvrname , ":e " . fnameescape ( s: NetrwFile ( a: fname )) . "\<cr>" ) 4618else 4619 4620if serverlist () !~ '\<' . g: netrw_servername . '\>' 4621 4622if ! ctrlr 4623if exists ( "g:netrw_browse_split" ) 4624unlet g: netrw_browse_split 4625endif 4626let g: netrw_browse_split = 0 4627call s: NetrwBrowse ( islocal , s: NetrwBrowseChgDir ( islocal , a: fname , 0 )) 4628return 4629 4630else 4631if has ( "win32" ) && executable ( "start" ) 4632" start up remote netrw server under windows 4633call system ( "start gvim --servername " . g: netrw_servername ) 4634else 4635" start up remote netrw server under linux 4636call system ( "gvim --servername " . g: netrw_servername ) 4637endif 4638endif 4639endif 4640 4641while 1 4642try 4643call remote_send ( g: netrw_servername , ":e " . fnameescape ( s: NetrwFile ( a: fname )) . "\<cr>" ) 4644break 4645catch /^Vim\%((\a\+)\)\=:E241/ 4646sleep 200m 4647endtry 4648endwhile 4649 4650if exists ( "g:netrw_browse_split" ) 4651if type ( g: netrw_browse_split ) != 3 4652let s: netrw_browse_split_ { winnr ()} = g: netrw_browse_split 4653endif 4654unlet g: netrw_browse_split 4655endif 4656let g: netrw_browse_split = [ g: netrw_servername , 1 , 1 ] 4657endif 4658 4659else 4660call netrw#msg#Notify ( 'ERROR' , 'you need a gui-capable vim and client-server to use <ctrl-r>' ) 4661endif 4662 4663endfunction 4664 4665" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2 4666function s: NetrwSLeftmouse ( islocal ) 4667if & ft != "netrw" 4668return 4669endif 4670 4671let s: ngw = s: NetrwGetWord () 4672call s: NetrwMarkFile ( a: islocal , s: ngw ) 4673 4674endfunction 4675 4676" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2 4677" Used to mark multiple files. 4678function s: NetrwSLeftdrag ( islocal ) 4679if ! exists ( "s:netrwdrag" ) 4680let s: netrwdrag = winnr () 4681if a: islocal 4682nno <silent> < s-leftrelease> <leftmouse>:<c-u > call < SID > NetrwSLeftrelease(1) < cr > 4683else 4684nno <silent> < s-leftrelease> <leftmouse>:<c-u > call < SID > NetrwSLeftrelease(0) < cr > 4685endif 4686endif 4687let ngw = s: NetrwGetWord () 4688if ! exists ( "s:ngw" ) || s: ngw != ngw 4689call s: NetrwMarkFile ( a: islocal , ngw ) 4690endif 4691let s: ngw = ngw 4692endfunction 4693 4694" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2 4695function s: NetrwSLeftrelease ( islocal ) 4696if exists ( "s:netrwdrag" ) 4697nunmap <s-leftrelease> 4698let ngw = s: NetrwGetWord () 4699if ! exists ( "s:ngw" ) || s: ngw != ngw 4700call s: NetrwMarkFile ( a: islocal , ngw ) 4701endif 4702if exists ( "s:ngw" ) 4703unlet s: ngw 4704endif 4705unlet s: netrwdrag 4706endif 4707endfunction 4708 4709" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2 4710" comma-separated patterns given in g:netrw_list_hide 4711function s: NetrwListHide () 4712let ykeep = @@ 4713 4714" find a character not in the "hide" string to use as a separator for :g and :v commands 4715" How-it-works: take the hiding command, convert it into a range. 4716" Duplicate characters don't matter. 4717" Remove all such characters from the '/~@#...890' string. 4718" Use the first character left as a separator character. 4719let listhide = g: netrw_list_hide 4720let sep = strpart ( substitute ( '~@#$%^&*{};:,<.>?|1234567890' , '[' . escape ( listhide , '-]^\' ) . ']' , '' , 'ge' ), 1 , 1 ) 4721 4722while listhide != "" 4723if listhide =~ ',' 4724let hide = substitute ( listhide , ',.*$' , '' , 'e' ) 4725let listhide = substitute ( listhide , '^.\{-},\(.*\)$' , '\1' , 'e' ) 4726else 4727let hide = listhide 4728let listhide = "" 4729endif 4730if g: netrw_sort_by =~ '^[ts]' 4731if hide =~ '^\^' 4732let hide = substitute ( hide , '^\^' , '^\(\\d\\+/\)' , '' ) 4733elseif hide =~ '^\\(\^' 4734let hide = substitute ( hide , '^\\(\^' , '\\(^\\(\\d\\+/\\)' , '' ) 4735endif 4736endif 4737 4738" Prune the list by hiding any files which match 4739if g: netrw_hide == 1 4740exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$g' . sep . hide . sep . 'd' 4741elseif g: netrw_hide == 2 4742exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$g' . sep . hide . sep . 's@^@ /-KEEP-/ @' 4743endif 4744endwhile 4745 4746if g: netrw_hide == 2 4747exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$v@^ /-KEEP-/ @d' 4748exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s@^\%( /-KEEP-/ \)\+@@e' 4749endif 4750 4751" remove any blank lines that have somehow remained. 4752" This seems to happen under Windows. 4753exe 'sil! NetrwKeepj 1,$g@^\s*$@d' 4754 4755let @@ = ykeep 4756endfunction 4757 4758" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2 4759" implements the "d" mapping. 4760function s: NetrwMakeDir ( usrhost ) 4761 4762let ykeep = @@ 4763" get name of new directory from user. A bare <CR> will skip. 4764" if its currently a directory, also request will be skipped, but with 4765" a message. 4766call inputsave () 4767let newdirname = input ( "Please give directory name: " ) 4768call inputrestore () 4769 4770if newdirname == "" 4771let @@ = ykeep 4772return 4773endif 4774 4775if a: usrhost == "" 4776 4777" Local mkdir: 4778" sanity checks 4779let fullnewdir = b: netrw_curdir . '/' . newdirname 4780if isdirectory ( s: NetrwFile ( fullnewdir )) 4781call netrw#msg#Notify ( 'WARNING' , printf ( '<%s> is already a directory!' , newdirname )) 4782let @@ = ykeep 4783return 4784endif 4785if s: FileReadable ( fullnewdir ) 4786call netrw#msg#Notify ( 'WARNING' , printf ( '<%s> is already a file!' , newdirname )) 4787let @@ = ykeep 4788return 4789endif 4790 4791" requested new local directory is neither a pre-existing file or 4792" directory, so make it! 4793if has ( "unix" ) 4794call mkdir ( fullnewdir , "p" , xor ( 0777 , system ( "umask" ))) 4795else 4796call mkdir ( fullnewdir , "p" ) 4797endif 4798 4799" on success refresh listing 4800let svpos = winsaveview () 4801call s: NetrwRefresh ( 1 , s: NetrwBrowseChgDir ( 1 , './' , 0 )) 4802call winrestview ( svpos ) 4803 4804elseif ! exists ( "b:netrw_method" ) || b: netrw_method == 4 4805" Remote mkdir: using ssh 4806let mkdircmd = s: MakeSshCmd ( g: netrw_mkdir_cmd ) 4807let newdirname = substitute ( b: netrw_curdir , '^\%(.\{-}/\)\{3}\(.*\)$' , '\1' , '' ). newdirname 4808call netrw#os#Execute ( "sil! !" . mkdircmd . " " . netrw#os#Escape ( newdirname , 1 )) 4809if v: shell_error == 0 4810" refresh listing 4811let svpos = winsaveview () 4812NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4813NetrwKeepj call winrestview(svpos) 4814else 4815call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to make directory<%s>' , newdirname )) 4816endif 4817 4818elseif b: netrw_method == 2 4819" Remote mkdir: using ftp+.netrc 4820let svpos = winsaveview () 4821if exists ( "b:netrw_fname" ) 4822let remotepath = b: netrw_fname 4823else 4824let remotepath = "" 4825endif 4826call s: NetrwRemoteFtpCmd ( remotepath , g: netrw_remote_mkdir . ' "' . newdirname . '"' ) 4827NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4828NetrwKeepj call winrestview(svpos) 4829 4830elseif b: netrw_method == 3 4831" Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc) 4832let svpos = winsaveview () 4833if exists ( "b:netrw_fname" ) 4834let remotepath = b: netrw_fname 4835else 4836let remotepath = "" 4837endif 4838call s: NetrwRemoteFtpCmd ( remotepath , g: netrw_remote_mkdir . ' "' . newdirname . '"' ) 4839NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 4840NetrwKeepj call winrestview(svpos) 4841endif 4842 4843let @@ = ykeep 4844endfunction 4845 4846" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2 4847function s: TreeSqueezeDir ( islocal ) 4848if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treedict" ) 4849" its a tree-listing style 4850let curdepth = substitute ( getline ( '.' ), '^\(\%(' . s: treedepthstring . '\)*\)[^' . s: treedepthstring . '].\{-}$' , '\1' , 'e' ) 4851let stopline = ( exists ( "w:netrw_bannercnt" ) ? ( w: netrw_bannercnt + 1 ) : 1 ) 4852let depth = strchars ( substitute ( curdepth , ' ' , '' , 'g' )) 4853let srch = -1 4854if depth >= 2 4855NetrwKeepj norm! 0 4856let curdepthm1 = substitute ( curdepth , '^' . s: treedepthstring , '' , '' ) 4857let srch = search ( '^' . curdepthm1 . '\%(' . s: treedepthstring . '\)\@!' , 'bW' , stopline ) 4858elseif depth == 1 4859NetrwKeepj norm! 0 4860let treedepthchr = substitute ( s: treedepthstring , ' ' , '' , '' ) 4861let srch = search ( '^[^' . treedepthchr . ']' , 'bW' , stopline ) 4862endif 4863if srch > 0 4864call s: NetrwBrowse ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , s: NetrwGetWord (), 1 )) 4865exe srch 4866endif 4867endif 4868endfunction 4869 4870" s:NetrwMaps: {{{2 4871function s: NetrwMaps ( islocal ) 4872" remove B flag from 'cpo' so that \<CR>, \<Bar>, etc. inside 4873" interpolated path names play back as literal text rather than 4874" the actual key — without this, a crafted directory name can 4875" inject keystrokes into the cmdline the mapping is typing 4876let _cpo = & cpo 4877set cpo -= B 4878 4879" mouse <Plug> maps: {{{3 4880if g: netrw_mousemaps && g: netrw_retmap 4881if ! hasmapto ( "<Plug>NetrwReturn" ) 4882if maparg ( "<2-leftmouse>" , "n" ) == "" || maparg ( "<2-leftmouse>" , "n" ) =~ '^-$' 4883nmap <unique> <silent> < 2-leftmouse> < Plug > NetrwReturn 4884elseif maparg ( "<c-leftmouse>" , "n" ) == "" 4885nmap <unique> <silent> < c-leftmouse > < Plug > NetrwReturn 4886endif 4887endif 4888nno <silent> < Plug > NetrwReturn :Rexplore < cr > 4889endif 4890 4891" generate default <Plug> maps {{{3 4892if ! hasmapto ( '<Plug>NetrwHide' ) | nmap <buffer> <silent> <nowait> a < Plug > NetrwHide_a| endif 4893if ! hasmapto ( '<Plug>NetrwBrowseUpDir' ) | nmap <buffer> <silent> <nowait> - < Plug > NetrwBrowseUpDir| endif 4894if ! hasmapto ( '<Plug>NetrwOpenFile' ) | nmap <buffer> <silent> <nowait> % < Plug > NetrwOpenFile| endif 4895if ! hasmapto ( '<Plug>NetrwBadd_cb' ) | nmap <buffer> <silent> <nowait> cb < Plug > NetrwBadd_cb| endif 4896if ! hasmapto ( '<Plug>NetrwBadd_cB' ) | nmap <buffer> <silent> <nowait> cB < Plug > NetrwBadd_cB| endif 4897if ! hasmapto ( '<Plug>NetrwLcd' ) | nmap <buffer> <silent> <nowait> cd < Plug > NetrwLcd| endif 4898if ! hasmapto ( '<Plug>NetrwSetChgwin' ) | nmap <buffer> <silent> <nowait> C < Plug > NetrwSetChgwin| endif 4899if ! hasmapto ( '<Plug>NetrwRefresh' ) | nmap <buffer> <silent> <nowait> < c-l > < Plug > NetrwRefresh| endif 4900if ! hasmapto ( '<Plug>NetrwLocalBrowseCheck' ) | nmap <buffer> <silent> <nowait> < cr > < Plug > NetrwLocalBrowseCheck| endif 4901if ! hasmapto ( '<Plug>NetrwServerEdit' ) | nmap <buffer> <silent> <nowait> < c-r > < Plug > NetrwServerEdit| endif 4902if ! hasmapto ( '<Plug>NetrwMakeDir' ) | nmap <buffer> <silent> <nowait> d < Plug > NetrwMakeDir| endif 4903if ! hasmapto ( '<Plug>NetrwBookHistHandler_gb' ) | nmap <buffer> <silent> <nowait> gb < Plug > NetrwBookHistHandler_gb| endif 4904 4905if a: islocal 4906" local normal-mode maps {{{3 4907nnoremap <buffer> <silent> < Plug > NetrwHide_a : < c-u > call < SID > NetrwHide(1) < cr > 4908nnoremap <buffer> <silent> < Plug > NetrwBrowseUpDir : < c-u > call < SID > NetrwBrowseUpDir(1) < cr > 4909nnoremap <buffer> <silent> < Plug > NetrwOpenFile : < c-u > call < SID > NetrwOpenFile(1) < cr > 4910nnoremap <buffer> <silent> < Plug > NetrwBadd_cb : < c-u > call < SID > NetrwBadd(1,0) < cr > 4911nnoremap <buffer> <silent> < Plug > NetrwBadd_cB : < c-u > call < SID > NetrwBadd(1,1) < cr > 4912nnoremap <buffer> <silent> < Plug > NetrwLcd : < c-u > call < SID > NetrwLcd(b:netrw_curdir) < cr > 4913nnoremap <buffer> <silent> < Plug > NetrwSetChgwin : < c-u > call < SID > NetrwSetChgwin() < cr > 4914nnoremap <buffer> <silent> < Plug > NetrwLocalBrowseCheck : < c-u > call netrw#LocalBrowseCheck( < SID > NetrwBrowseChgDir(1, < SID > NetrwGetWord(),1)) < cr > 4915nnoremap <buffer> <silent> < Plug > NetrwServerEdit : < c-u > call < SID > NetrwServerEdit(3, < SID > NetrwGetWord()) < cr > 4916nnoremap <buffer> <silent> < Plug > NetrwMakeDir : < c-u > call < SID > NetrwMakeDir("") < cr > 4917nnoremap <buffer> <silent> < Plug > NetrwBookHistHandler_gb : < c-u > call < SID > NetrwBookHistHandler(1,b:netrw_curdir) < cr > 4918" --------------------------------------------------------------------- 4919nnoremap <buffer> <silent> <nowait> gd : < c-u > call < SID > NetrwForceChgDir(1, < SID > NetrwGetWord()) < cr > 4920nnoremap <buffer> <silent> <nowait> gf : < c-u > call < SID > NetrwForceFile(1, < SID > NetrwGetWord()) < cr > 4921nnoremap <buffer> <silent> <nowait> gh : < c-u > call < SID > NetrwHidden(1) < cr > 4922nnoremap <buffer> <silent> <nowait> gn : < c-u > call netrw#SetTreetop(0, < SID > NetrwGetWord()) < cr > 4923nnoremap <buffer> <silent> <nowait> gp : < c-u > call < SID > NetrwChgPerm(1,b:netrw_curdir) < cr > 4924nnoremap <buffer> <silent> <nowait> I : < c-u > call < SID > NetrwBannerCtrl(1) < cr > 4925nnoremap <buffer> <silent> <nowait> i : < c-u > call < SID > NetrwListStyle(1) < cr > 4926nnoremap <buffer> <silent> <nowait> ma : < c-u > call < SID > NetrwMarkFileArgList(1,0) < cr > 4927nnoremap <buffer> <silent> <nowait> mA : < c-u > call < SID > NetrwMarkFileArgList(1,1) < cr > 4928nnoremap <buffer> <silent> <nowait> mb : < c-u > call < SID > NetrwBookHistHandler(0,b:netrw_curdir) < cr > 4929nnoremap <buffer> <silent> <nowait> mB : < c-u > call < SID > NetrwBookHistHandler(6,b:netrw_curdir) < cr > 4930nnoremap <buffer> <silent> <nowait> mc : < c-u > call < SID > NetrwMarkFileCopy(1) < cr > 4931nnoremap <buffer> <silent> <nowait> md : < c-u > call < SID > NetrwMarkFileDiff(1) < cr > 4932nnoremap <buffer> <silent> <nowait> me : < c-u > call < SID > NetrwMarkFileEdit(1) < cr > 4933nnoremap <buffer> <silent> <nowait> mf : < c-u > call < SID > NetrwMarkFile(1, < SID > NetrwGetWord()) < cr > 4934nnoremap <buffer> <silent> <nowait> mF : < c-u > call < SID > NetrwUnmarkList(bufnr("%"),b:netrw_curdir) < cr > 4935nnoremap <buffer> <silent> <nowait> mg : < c-u > call < SID > NetrwMarkFileGrep(1) < cr > 4936nnoremap <buffer> <silent> <nowait> mh : < c-u > call < SID > NetrwMarkHideSfx(1) < cr > 4937nnoremap <buffer> <silent> <nowait> mm : < c-u > call < SID > NetrwMarkFileMove(1) < cr > 4938nnoremap <buffer> <silent> <nowait> mr : < c-u > call < SID > NetrwMarkFileRegexp(1) < cr > 4939nnoremap <buffer> <silent> <nowait> ms : < c-u > call < SID > NetrwMarkFileSource(1) < cr > 4940nnoremap <buffer> <silent> <nowait> mT : < c-u > call < SID > NetrwMarkFileTag(1) < cr > 4941nnoremap <buffer> <silent> <nowait> mt : < c-u > call < SID > NetrwMarkFileTgt(1) < cr > 4942nnoremap <buffer> <silent> <nowait> mu : < c-u > call < SID > NetrwUnMarkFile(1) < cr > 4943nnoremap <buffer> <silent> <nowait> mv : < c-u > call < SID > NetrwMarkFileVimCmd(1) < cr > 4944nnoremap <buffer> <silent> <nowait> mx : < c-u > call < SID > NetrwMarkFileExe(1,0) < cr > 4945nnoremap <buffer> <silent> <nowait> mX : < c-u > call < SID > NetrwMarkFileExe(1,1) < cr > 4946nnoremap <buffer> <silent> <nowait> mz : < c-u > call < SID > NetrwMarkFileCompress(1) < cr > 4947nnoremap <buffer> <silent> <nowait> O : < c-u > call < SID > NetrwObtain(1) < cr > 4948nnoremap <buffer> <silent> <nowait> o :call < SID > NetrwSplit(3) < cr > 4949nnoremap <buffer> <silent> <nowait> p : < c-u > call < SID > NetrwPreview( < SID > NetrwBrowseChgDir(1, < SID > NetrwGetWord(),1,1)) < cr > 4950nnoremap <buffer> <silent> <nowait> P : < c-u > call < SID > NetrwPrevWinOpen(1) < cr > 4951nnoremap <buffer> <silent> <nowait> qb : < c-u > call < SID > NetrwBookHistHandler(2,b:netrw_curdir) < cr > 4952nnoremap <buffer> <silent> <nowait> qf : < c-u > call < SID > NetrwFileInfo(1, < SID > NetrwGetWord()) < cr > 4953nnoremap <buffer> <silent> <nowait> qF : < c-u > call < SID > NetrwMarkFileQFEL(1,getqflist()) < cr > 4954nnoremap <buffer> <silent> <nowait> qL : < c-u > call < SID > NetrwMarkFileQFEL(1,getloclist(v:count)) < cr > 4955nnoremap <buffer> <silent> <nowait> s :call < SID > NetrwSortStyle(1) < cr > 4956nnoremap <buffer> <silent> <nowait> S : < c-u > call < SID > NetSortSequence(1) < cr > 4957nnoremap <buffer> <silent> <nowait> Tb : < c-u > call < SID > NetrwSetTgt(1,'b',v:count1) < cr > 4958nnoremap <buffer> <silent> <nowait> t :call < SID > NetrwSplit(4) < cr > 4959nnoremap <buffer> <silent> <nowait> Th : < c-u > call < SID > NetrwSetTgt(1,'h',v:count) < cr > 4960nnoremap <buffer> <silent> <nowait> u : < c-u > call < SID > NetrwBookHistHandler(4,expand("%")) < cr > 4961nnoremap <buffer> <silent> <nowait> U : < c-u > call < SID > NetrwBookHistHandler(5,expand("%")) < cr > 4962nnoremap <buffer> <silent> <nowait> v :call < SID > NetrwSplit(5) < cr > 4963nnoremap <buffer> <silent> <nowait> x : < c-u > call netrw#BrowseX( < SID > NetrwBrowseChgDir(1, < SID > NetrwGetWord(),1,0))" < cr > 4964nnoremap <buffer> <silent> <nowait> X : < c-u > call < SID > NetrwLocalExecute(expand(" < cword>"))" < cr > 4965 4966nnoremap <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 > 4967if ! hasmapto ( '<Plug>NetrwHideEdit' ) 4968nmap <buffer> <unique> < c-h > < Plug > NetrwHideEdit 4969endif 4970nnoremap <buffer> <silent> < Plug > NetrwHideEdit :call < SID > NetrwHideEdit(1) < cr > 4971if ! hasmapto ( '<Plug>NetrwRefresh' ) 4972nmap <buffer> <unique> < c-l > < Plug > NetrwRefresh 4973endif 4974nnoremap <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 > 4975if s: didstarstar || ! mapcheck ( "<s-down>" , "n" ) 4976nnoremap <buffer> <silent> < s-down > :Nexplore < cr > 4977endif 4978if s: didstarstar || ! mapcheck ( "<s-up>" , "n" ) 4979nnoremap <buffer> <silent> < s-up > :Pexplore < cr > 4980endif 4981if ! hasmapto ( '<Plug>NetrwTreeSqueeze' ) 4982nmap <buffer> <silent> <nowait> < s-cr > < Plug > NetrwTreeSqueeze 4983endif 4984nnoremap <buffer> <silent> < Plug > NetrwTreeSqueeze :call < SID > TreeSqueezeDir(1) < cr > 4985let mapsafecurdir = escape ( b: netrw_curdir , s: netrw_map_escape ) 4986if g: netrw_mousemaps == 1 4987nmap <buffer> < leftmouse > < Plug > NetrwLeftmouse 4988nmap <buffer> < c-leftmouse > < Plug > NetrwCLeftmouse 4989nmap <buffer> < middlemouse> < Plug > NetrwMiddlemouse 4990nmap <buffer> < s-leftmouse > < Plug > NetrwSLeftmouse 4991nmap <buffer> < s-leftdrag> < Plug>NetrwSLeftdrag 4992nmap <buffer> < 2-leftmouse> < Plug > Netrw2Leftmouse 4993imap <buffer> < leftmouse > < Plug > ILeftmouse 4994imap <buffer> < middlemouse> < Plug > IMiddlemouse 4995nno <buffer> <silent> < Plug > NetrwLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwLeftmouse(1) < cr > 4996nno <buffer> <silent> < Plug > NetrwCLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwCLeftmouse(1) < cr > 4997nno <buffer> <silent> < Plug > NetrwMiddlemouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwPrevWinOpen(1) < cr > 4998nno <buffer> <silent> < Plug > NetrwSLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwSLeftmouse(1) < cr > 4999nno <buffer> <silent> < Plug > NetrwSLeftdrag :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwSLeftdrag(1) < cr > 5000nmap <buffer> <silent> < Plug > Netrw2Leftmouse - 5001exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5002exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5003endif 5004exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5005exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5006exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("' . mapsafecurdir . '")<cr>' 5007exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>' 5008exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5009exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("' . mapsafecurdir . '")<cr>' 5010exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("' . mapsafecurdir . '")<cr>' 5011nnoremap <buffer> < F1 > :he netrw-quickhelp < cr > 5012 5013" support user-specified maps 5014call netrw#UserMaps ( 1 ) 5015 5016else 5017" remote normal-mode maps {{{3 5018call s: RemotePathAnalysis ( b: netrw_curdir ) 5019nnoremap <buffer> <silent> < Plug > NetrwHide_a : < c-u > call < SID > NetrwHide(0) < cr > 5020nnoremap <buffer> <silent> < Plug > NetrwBrowseUpDir : < c-u > call < SID > NetrwBrowseUpDir(0) < cr > 5021nnoremap <buffer> <silent> < Plug > NetrwOpenFile : < c-u > call < SID > NetrwOpenFile(0) < cr > 5022nnoremap <buffer> <silent> < Plug > NetrwBadd_cb : < c-u > call < SID > NetrwBadd(0,0) < cr > 5023nnoremap <buffer> <silent> < Plug > NetrwBadd_cB : < c-u > call < SID > NetrwBadd(0,1) < cr > 5024nnoremap <buffer> <silent> < Plug > NetrwLcd : < c-u > call < SID > NetrwLcd(b:netrw_curdir) < cr > 5025nnoremap <buffer> <silent> < Plug > NetrwSetChgwin : < c-u > call < SID > NetrwSetChgwin() < cr > 5026nnoremap <buffer> <silent> < Plug > NetrwRefresh : < c-u > call < SID > NetrwRefresh(0, < SID > NetrwBrowseChgDir(0,'./',0)) < cr > 5027nnoremap <buffer> <silent> < Plug > NetrwLocalBrowseCheck : < c-u > call < SID > NetrwBrowse(0, < SID > NetrwBrowseChgDir(0, < SID > NetrwGetWord(),1)) < cr > 5028nnoremap <buffer> <silent> < Plug > NetrwServerEdit : < c-u > call < SID > NetrwServerEdit(2, < SID > NetrwGetWord()) < cr > 5029nnoremap <buffer> <silent> < Plug > NetrwBookHistHandler_gb : < c-u > call < SID > NetrwBookHistHandler(1,b:netrw_curdir) < cr > 5030" --------------------------------------------------------------------- 5031nnoremap <buffer> <silent> <nowait> gd : < c-u > call < SID > NetrwForceChgDir(0, < SID > NetrwGetWord()) < cr > 5032nnoremap <buffer> <silent> <nowait> gf : < c-u > call < SID > NetrwForceFile(0, < SID > NetrwGetWord()) < cr > 5033nnoremap <buffer> <silent> <nowait> gh : < c-u > call < SID > NetrwHidden(0) < cr > 5034nnoremap <buffer> <silent> <nowait> gp : < c-u > call < SID > NetrwChgPerm(0,b:netrw_curdir) < cr > 5035nnoremap <buffer> <silent> <nowait> I : < c-u > call < SID > NetrwBannerCtrl(1) < cr > 5036nnoremap <buffer> <silent> <nowait> i : < c-u > call < SID > NetrwListStyle(0) < cr > 5037nnoremap <buffer> <silent> <nowait> ma : < c-u > call < SID > NetrwMarkFileArgList(0,0) < cr > 5038nnoremap <buffer> <silent> <nowait> mA : < c-u > call < SID > NetrwMarkFileArgList(0,1) < cr > 5039nnoremap <buffer> <silent> <nowait> mb : < c-u > call < SID > NetrwBookHistHandler(0,b:netrw_curdir) < cr > 5040nnoremap <buffer> <silent> <nowait> mB : < c-u > call < SID > NetrwBookHistHandler(6,b:netrw_curdir) < cr > 5041nnoremap <buffer> <silent> <nowait> mc : < c-u > call < SID > NetrwMarkFileCopy(0) < cr > 5042nnoremap <buffer> <silent> <nowait> md : < c-u > call < SID > NetrwMarkFileDiff(0) < cr > 5043nnoremap <buffer> <silent> <nowait> me : < c-u > call < SID > NetrwMarkFileEdit(0) < cr > 5044nnoremap <buffer> <silent> <nowait> mf : < c-u > call < SID > NetrwMarkFile(0, < SID > NetrwGetWord()) < cr > 5045nnoremap <buffer> <silent> <nowait> mF : < c-u > call < SID > NetrwUnmarkList(bufnr("%"),b:netrw_curdir) < cr > 5046nnoremap <buffer> <silent> <nowait> mg : < c-u > call < SID > NetrwMarkFileGrep(0) < cr > 5047nnoremap <buffer> <silent> <nowait> mh : < c-u > call < SID > NetrwMarkHideSfx(0) < cr > 5048nnoremap <buffer> <silent> <nowait> mm : < c-u > call < SID > NetrwMarkFileMove(0) < cr > 5049nnoremap <buffer> <silent> <nowait> mr : < c-u > call < SID > NetrwMarkFileRegexp(0) < cr > 5050nnoremap <buffer> <silent> <nowait> ms : < c-u > call < SID > NetrwMarkFileSource(0) < cr > 5051nnoremap <buffer> <silent> <nowait> mT : < c-u > call < SID > NetrwMarkFileTag(0) < cr > 5052nnoremap <buffer> <silent> <nowait> mt : < c-u > call < SID > NetrwMarkFileTgt(0) < cr > 5053nnoremap <buffer> <silent> <nowait> mu : < c-u > call < SID > NetrwUnMarkFile(0) < cr > 5054nnoremap <buffer> <silent> <nowait> mv : < c-u > call < SID > NetrwMarkFileVimCmd(0) < cr > 5055nnoremap <buffer> <silent> <nowait> mx : < c-u > call < SID > NetrwMarkFileExe(0,0) < cr > 5056nnoremap <buffer> <silent> <nowait> mX : < c-u > call < SID > NetrwMarkFileExe(0,1) < cr > 5057nnoremap <buffer> <silent> <nowait> mz : < c-u > call < SID > NetrwMarkFileCompress(0) < cr > 5058nnoremap <buffer> <silent> <nowait> O : < c-u > call < SID > NetrwObtain(0) < cr > 5059nnoremap <buffer> <silent> <nowait> o :call < SID > NetrwSplit(0) < cr > 5060nnoremap <buffer> <silent> <nowait> p : < c-u > call < SID > NetrwPreview( < SID > NetrwBrowseChgDir(1, < SID > NetrwGetWord(),1,1)) < cr > 5061nnoremap <buffer> <silent> <nowait> P : < c-u > call < SID > NetrwPrevWinOpen(0) < cr > 5062nnoremap <buffer> <silent> <nowait> qb : < c-u > call < SID > NetrwBookHistHandler(2,b:netrw_curdir) < cr > 5063nnoremap <buffer> <silent> <nowait> qf : < c-u > call < SID > NetrwFileInfo(0, < SID > NetrwGetWord()) < cr > 5064nnoremap <buffer> <silent> <nowait> qF : < c-u > call < SID > NetrwMarkFileQFEL(0,getqflist()) < cr > 5065nnoremap <buffer> <silent> <nowait> qL : < c-u > call < SID > NetrwMarkFileQFEL(0,getloclist(v:count)) < cr > 5066nnoremap <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 > 5067nnoremap <buffer> <silent> <nowait> s :call < SID > NetrwSortStyle(0) < cr > 5068nnoremap <buffer> <silent> <nowait> S : < c-u > call < SID > NetSortSequence(0) < cr > 5069nnoremap <buffer> <silent> <nowait> Tb : < c-u > call < SID > NetrwSetTgt(0,'b',v:count1) < cr > 5070nnoremap <buffer> <silent> <nowait> t :call < SID > NetrwSplit(1) < cr > 5071nnoremap <buffer> <silent> <nowait> Th : < c-u > call < SID > NetrwSetTgt(0,'h',v:count) < cr > 5072nnoremap <buffer> <silent> <nowait> u : < c-u > call < SID > NetrwBookHistHandler(4,b:netrw_curdir) < cr > 5073nnoremap <buffer> <silent> <nowait> U : < c-u > call < SID > NetrwBookHistHandler(5,b:netrw_curdir) < cr > 5074nnoremap <buffer> <silent> <nowait> v :call < SID > NetrwSplit(2) < cr > 5075if ! hasmapto ( '<Plug>NetrwHideEdit' ) 5076nmap <buffer> < c-h > < Plug > NetrwHideEdit 5077endif 5078nnoremap <buffer> <silent> < Plug > NetrwHideEdit :call < SID > NetrwHideEdit(0) < cr > 5079if ! hasmapto ( '<Plug>NetrwRefresh' ) 5080nmap <buffer> < c-l > < Plug > NetrwRefresh 5081endif 5082if ! hasmapto ( '<Plug>NetrwTreeSqueeze' ) 5083nmap <buffer> <silent> <nowait> < s-cr > < Plug > NetrwTreeSqueeze 5084endif 5085nnoremap <buffer> <silent> < Plug > NetrwTreeSqueeze :call < SID > TreeSqueezeDir(0) < cr > 5086 5087let mapsafepath = escape ( s: path , s: netrw_map_escape ) 5088let mapsafeusermach = escape ((( s: user == "" ) ? "" : s: user . "@" ) . s: machine , s: netrw_map_escape ) 5089 5090nnoremap <buffer> <silent> < Plug > NetrwRefresh :call < SID > NetrwRefresh(0, < SID > NetrwBrowseChgDir(0,'./',0)) < cr > 5091if g: netrw_mousemaps == 1 5092nmap <buffer> < leftmouse > < Plug > NetrwLeftmouse 5093nno <buffer> <silent> < Plug > NetrwLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwLeftmouse(0) < cr > 5094nmap <buffer> < c-leftmouse > < Plug > NetrwCLeftmouse 5095nno <buffer> <silent> < Plug > NetrwCLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwCLeftmouse(0) < cr > 5096nmap <buffer> < s-leftmouse > < Plug > NetrwSLeftmouse 5097nno <buffer> <silent> < Plug > NetrwSLeftmouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwSLeftmouse(0) < cr > 5098nmap <buffer> < s-leftdrag> < Plug>NetrwSLeftdrag 5099nno <buffer> <silent> < Plug > NetrwSLeftdrag :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwSLeftdrag(0) < cr > 5100nmap < middlemouse> < Plug > NetrwMiddlemouse 5101nno <buffer> <silent> < middlemouse> < Plug > NetrwMiddlemouse :exec "norm! \<lt>leftmouse>" < bar > call < SID > NetrwPrevWinOpen(0) < cr > 5102nmap <buffer> < 2-leftmouse> < Plug > Netrw2Leftmouse 5103nmap <buffer> <silent> < Plug > Netrw2Leftmouse - 5104imap <buffer> < leftmouse > < Plug > ILeftmouse 5105imap <buffer> < middlemouse> < Plug > IMiddlemouse 5106imap <buffer> < s-leftmouse > < Plug > ISLeftmouse 5107exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5108exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5109endif 5110exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5111exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("' . mapsafeusermach . '")<cr>' 5112exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5113exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5114exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5115exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5116exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("' . mapsafeusermach . '","' . mapsafepath . '")<cr>' 5117nnoremap <buffer> < F1 > :he netrw-quickhelp < cr > 5118 5119" support user-specified maps 5120call netrw#UserMaps ( 0 ) 5121endif " }}}3 5122let & cpo = _cpo 5123endfunction 5124 5125" s:NetrwCommands: set up commands {{{2 5126" If -buffer, the command is only available from within netrw buffers 5127" Otherwise, the command is available from any window, so long as netrw 5128" has been used at least once in the session. 5129function s: NetrwCommands ( islocal ) 5130 5131com ! -nargs = * -complete = file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>) 5132com ! -nargs = * NetrwC call s:NetrwSetChgwin(<q-args>) 5133com ! 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 5134if a: islocal 5135com ! -buffer -nargs = + -complete = file MF call s:NetrwMarkFiles(1,<f-args>) 5136else 5137com ! -buffer -nargs = + -complete = file MF call s:NetrwMarkFiles(0,<f-args>) 5138endif 5139com ! -buffer -nargs = ? -complete = file MT call s:NetrwMarkTarget(<q-args>) 5140 5141endfunction 5142 5143" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2 5144" glob()ing only works with local files 5145function s: NetrwMarkFiles ( islocal ,...) 5146let curdir = s: NetrwGetCurdir ( a: islocal ) 5147let i = 1 5148while i <= a: 0 5149if a: islocal 5150let mffiles = glob ( a: {i}, 0, 1, 1) 5151else 5152let mffiles = [ a: {i}] 5153endif 5154for mffile in mffiles 5155call s: NetrwMarkFile ( a: islocal , mffile ) 5156endfor 5157let i = i + 1 5158endwhile 5159endfunction 5160 5161" s:NetrwMarkTarget: implements :MT (mark target) {{{2 5162function s: NetrwMarkTarget (...) 5163if a: 0 == 0 || ( a: 0 == 1 && a: 1 == "" ) 5164let curdir = s: NetrwGetCurdir ( 1 ) 5165let tgt = b: netrw_curdir 5166else 5167let curdir = s: NetrwGetCurdir (( a: 1 =~ '^\a\{3,}://' ) ? 0 : 1 ) 5168let tgt = a: 1 5169endif 5170let s: netrwmftgt = tgt 5171let s: netrwmftgt_islocal = tgt !~ '^\a\{3,}://' 5172let curislocal = b: netrw_curdir !~ '^\a\{3,}://' 5173let svpos = winsaveview () 5174call s: NetrwRefresh ( curislocal , s: NetrwBrowseChgDir ( curislocal , './' , 0 )) 5175call winrestview ( svpos ) 5176endfunction 5177 5178" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2 5179" mark and unmark files. If a markfile list exists, 5180" then the rename and delete functions will use it instead 5181" of whatever may happen to be under the cursor at that 5182" moment. When the mouse and gui are available, 5183" shift-leftmouse may also be used to mark files. 5184" 5185" Creates two lists 5186" s:netrwmarkfilelist -- holds complete paths to all marked files 5187" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr()) 5188" 5189" Creates a marked file match string 5190" s:netrwmarkfilemtch_# -- used with 2match to display marked files 5191" 5192" Creates a buffer version of islocal 5193" b:netrw_islocal 5194function s: NetrwMarkFile ( islocal , fname ) 5195 5196" sanity check 5197if empty ( a: fname ) 5198return 5199endif 5200let curdir = s: NetrwGetCurdir ( a: islocal ) 5201 5202let ykeep = @@ 5203let curbufnr = bufnr ( "%" ) 5204let leader = '\%(^\|\s\)\zs' 5205let word_boundary_trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)' 5206let fallback_trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)' 5207let trailer = ( a: fname =~ '\a$' ) ? word_boundary_trailer : fallback_trailer 5208 5209if exists ( "s:netrwmarkfilelist_" . curbufnr ) 5210" markfile list pre-exists 5211let b: netrw_islocal = a: islocal 5212 5213if index ( s: netrwmarkfilelist_ { curbufnr }, a: fname ) == -1 5214" append filename to buffer's markfilelist 5215call add ( s: netrwmarkfilelist_ { curbufnr }, substitute ( a: fname , '[|@]$' , '' , '' )) 5216let s: netrwmarkfilemtch_ { curbufnr } = s: netrwmarkfilemtch_ { curbufnr } . '\|' . leader . escape ( a: fname , g: netrw_markfileesc ). trailer 5217 5218else 5219" remove filename from buffer's markfilelist 5220call filter ( s: netrwmarkfilelist_ { curbufnr }, { _ , v -> v !=# a: fname }) 5221if s: netrwmarkfilelist_ { curbufnr } == [] 5222" local markfilelist is empty; remove it entirely 5223call s: NetrwUnmarkList ( curbufnr , curdir ) 5224else 5225" rebuild match list to display markings correctly 5226let s: netrwmarkfilemtch_ { curbufnr } = "" 5227let first = 1 5228for fname in s: netrwmarkfilelist_ { curbufnr } 5229let curtrailer = ( fname =~ '\a$' ) ? word_boundary_trailer : fallback_trailer 5230 5231let match_str = leader . escape ( fname , g: netrw_markfileesc ). curtrailer 5232if first 5233let s: netrwmarkfilemtch_ { curbufnr } = match_str 5234else 5235let s: netrwmarkfilemtch_ { curbufnr } = s: netrwmarkfilemtch_ { curbufnr } . '\|' . match_str 5236endif 5237let first = 0 5238endfor 5239endif 5240endif 5241 5242else 5243" initialize new markfilelist 5244let s: netrwmarkfilelist_ { curbufnr } = [] 5245call add ( s: netrwmarkfilelist_ { curbufnr }, substitute ( a: fname , '[|@]$' , '' , '' )) 5246 5247" build initial markfile matching pattern 5248let s: netrwmarkfilemtch_ { curbufnr } = leader . escape ( a: fname , g: netrw_markfileesc ). trailer 5249endif 5250 5251" handle global markfilelist 5252if exists ( "s:netrwmarkfilelist" ) 5253let dname = netrw#fs#ComposePath ( b: netrw_curdir , a: fname ) 5254if index ( s: netrwmarkfilelist , dname ) == -1 5255" append new filename to global markfilelist 5256call add ( s: netrwmarkfilelist , netrw#fs#ComposePath ( b: netrw_curdir , a: fname )) 5257else 5258" remove new filename from global markfilelist 5259call filter ( s: netrwmarkfilelist , { _ , v -> v !=# dname }) 5260if s: netrwmarkfilelist == [] 5261unlet s: netrwmarkfilelist 5262endif 5263endif 5264else 5265" initialize new global-directory markfilelist 5266let s: netrwmarkfilelist = [] 5267call add ( s: netrwmarkfilelist , netrw#fs#ComposePath ( b: netrw_curdir , a: fname )) 5268endif 5269 5270" set up 2match'ing to netrwmarkfilemtch_# list 5271if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 5272if exists ( "s:netrwmarkfilemtch_{curbufnr}" ) && s: netrwmarkfilemtch_ { curbufnr } != "" 5273if exists ( "g:did_drchip_netrwlist_syntax" ) 5274exe "2match netrwMarkFile /" . s: netrwmarkfilemtch_ { curbufnr } . "/" 5275endif 5276else 52772 match none 5278endif 5279endif 5280let @@ = ykeep 5281endfunction 5282 5283" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2 5284" mA: move the argument list to marked file list (tomflist=1) 5285" Uses the global marked file list 5286function s: NetrwMarkFileArgList ( islocal , tomflist ) 5287let svpos = winsaveview () 5288let curdir = s: NetrwGetCurdir ( a: islocal ) 5289let curbufnr = bufnr ( "%" ) 5290 5291if a: tomflist 5292" mA: move argument list to marked file list 5293while argc () 5294let fname = argv ( 0 ) 5295exe "argdel " . fnameescape ( fname ) 5296call s: NetrwMarkFile ( a: islocal , fname ) 5297endwhile 5298 5299else 5300" ma: move marked file list to argument list 5301if exists ( "s:netrwmarkfilelist" ) 5302 5303" for every filename in the marked list 5304for fname in s: netrwmarkfilelist 5305exe "argadd " . fnameescape ( fname ) 5306endfor " for every file in the marked list 5307 5308" unmark list and refresh 5309call s: NetrwUnmarkList ( curbufnr , curdir ) 5310NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5311NetrwKeepj call winrestview(svpos) 5312endif 5313endif 5314endfunction 5315 5316" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2 5317" compress/decompress files using the programs 5318" in g:netrw_compress and g:netrw_uncompress, 5319" using g:netrw_compress_suffix to know which to 5320" do. By default: 5321" g:netrw_compress = "gzip" 5322" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"} 5323function s: NetrwMarkFileCompress ( islocal ) 5324let svpos = winsaveview () 5325let curdir = s: NetrwGetCurdir ( a: islocal ) 5326let curbufnr = bufnr ( "%" ) 5327 5328" sanity check 5329if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5330call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5331return 5332endif 5333 5334if exists ( "s:netrwmarkfilelist_{curbufnr}" ) && exists ( "g:netrw_compress" ) && exists ( "g:netrw_decompress" ) 5335 5336" for every filename in the marked list 5337for fname in s: netrwmarkfilelist_ { curbufnr } 5338let sfx = substitute ( fname , '^.\{-}\(\.[[:alnum:]]\+\)$' , '\1' , '' ) 5339if exists ( "g:netrw_decompress['" . sfx . "']" ) 5340" fname has a suffix indicating that its compressed; apply associated decompression routine 5341let exe = g: netrw_decompress [ sfx ] 5342let exe = netrw#fs#WinPath ( exe ) 5343if a: islocal 5344if g: netrw_keepdir 5345let fname = netrw#os#Escape ( netrw#fs#ComposePath ( curdir , fname )) 5346else 5347let fname = netrw#os#Escape ( fname ) 5348endif 5349call system ( exe . " " . fname ) 5350if v: shell_error 5351call netrw#msg#Notify ( 'WARNING' , printf ( 'unable to apply<%s> to file<%s>' , exe , fname )) 5352endif 5353else 5354let fname = netrw#os#Escape ( b: netrw_curdir . fname , 1 ) 5355NetrwKeepj call s:RemoteSystem(exe." ".fname) 5356endif 5357 5358endif 5359unlet sfx 5360 5361if exists ( "exe" ) 5362unlet exe 5363elseif a: islocal 5364" fname not a compressed file, so compress it 5365call system ( netrw#fs#WinPath ( g: netrw_compress ) . " " . netrw#os#Escape ( netrw#fs#ComposePath ( b: netrw_curdir , fname ))) 5366if v: shell_error 5367call netrw#msg#Notify ( 'WARNING' , printf ( 'consider setting g:netrw_compress<%s> to something that works' , g: netrw_compress )) 5368endif 5369else 5370" fname not a compressed file, so compress it 5371NetrwKeepj call s:RemoteSystem(netrw#fs#WinPath(g:netrw_compress)." ".netrw#os#Escape(fname)) 5372endif 5373endfor " for every file in the marked list 5374 5375call s: NetrwUnmarkList ( curbufnr , curdir ) 5376NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5377NetrwKeepj call winrestview(svpos) 5378endif 5379endfunction 5380 5381" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2 5382" If no marked files, then set up directory as the 5383" target. Currently does not support copying entire 5384" directories. Uses the local-buffer marked file list. 5385" Returns 1=success (used by NetrwMarkFileMove()) 5386" 0=failure 5387function s: NetrwMarkFileCopy ( islocal ,...) 5388 5389let curdir = s: NetrwGetCurdir ( a: islocal ) 5390let curbufnr = bufnr ( "%" ) 5391if ! exists ( "b:netrw_curdir" ) 5392let b: netrw_curdir = curdir 5393endif 5394 5395" sanity check 5396if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5397call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5398return 0 5399endif 5400 5401if ! exists ( "s:netrwmftgt" ) 5402call netrw#msg#Notify ( 'ERROR' , 'your marked file target is empty! (:help netrw-mt)' ) 5403return 0 5404endif 5405 5406if a: islocal && s: netrwmftgt_islocal 5407" Copy marked files, local directory to local directory 5408if ! executable ( g: netrw_localcopycmd ) 5409call netrw#msg#Notify ( 'ERROR' , printf ( 'g:netrw_localcopycmd<%s> not executable on your system, aborting' , g: netrw_localcopycmd )) 5410return 5411endif 5412 5413" copy marked files while within the same directory (ie. allow renaming) 5414if simplify ( s: netrwmftgt . "/" ) ==# simplify ( b: netrw_curdir . "/" ) 5415" copy multiple marked files inside the same directory 5416for oldname in s: netrwmarkfilelist_ { curbufnr } 5417call inputsave () 5418let newname = input ( printf ( "Copy %s to: " , oldname ), oldname , 'file' ) 5419call inputrestore () 5420 5421if empty ( newname ) 5422return 0 5423endif 5424 5425let tgt = netrw#fs#ComposePath ( s: netrwmftgt , newname ) 5426let oldname = netrw#fs#ComposePath ( b: netrw_curdir , oldname ) 5427if tgt ==# oldname 5428continue 5429endif 5430 5431let ret = filecopy ( oldname , tgt ) 5432if ret == v: false 5433call netrw#msg#Notify ( 'ERROR' , $ 'copy failed, unable to filecopy() <{oldname}> to <{tgt}>') 5434break 5435endif 5436endfor 5437call s: NetrwUnmarkList ( curbufnr , curdir ) 5438NetrwKeepj call s:NetrwRefreshDir(a:islocal, b:netrw_curdir) 5439return ret 5440else 5441let args = [] 5442for arg in s: netrwmarkfilelist_ { curbufnr } 5443call add ( args , netrw#fs#ComposePath ( b: netrw_curdir , arg )) 5444endfor 5445let tgt = s: netrwmftgt 5446endif 5447 5448let copycmd = g: netrw_localcopycmd 5449let copycmdopt = g: netrw_localcopycmdopt 5450 5451" on Windows, no builtin command supports copying multiple files at once 5452" (powershell's Copy-Item cmdlet does but requires , as file separator) 5453if len ( s: netrwmarkfilelist_ { curbufnr }) > 1 && has ( "win32" ) && ! g: netrw_cygwin 5454" copy multiple marked files 5455for file in args 5456let dest = netrw#fs#ComposePath ( tgt , fnamemodify ( file , ':t' )) 5457let ret = filecopy ( file , dest ) 5458if ret == v: false 5459call netrw#msg#Notify ( 'ERROR' , $ 'copy failed, unable to filecopy() <{file}> to <{dest}>') 5460break 5461endif 5462endfor 5463call s: NetrwUnmarkList ( curbufnr , curdir ) 5464NetrwKeepj call s:NetrwRefreshDir(a:islocal, b:netrw_curdir) 5465return ret 5466endif 5467 5468if len ( args ) == 1 && isdirectory ( s: NetrwFile ( args [ 0 ])) 5469let copycmd = g: netrw_localcopydircmd 5470let copycmdopt = g: netrw_localcopydircmdopt 5471if has ( 'win32' ) && g: netrw_localcopydircmd == "xcopy" 5472" window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's 5473" contents to a target. One must append the source directory name to the target to get xcopy to 5474" do the right thing. 5475let tgt = netrw#fs#ComposePath ( tgt , fnamemodify ( simplify ( netrw#fs#PathJoin ( args [ 0 ], "." )), ":t" )) 5476endif 5477endif 5478 5479" prepare arguments for shell call 5480let args = join ( map ( args , 'netrw#os#Escape(v:val)' )) 5481let tgt = netrw#os#Escape ( tgt ) 5482 5483" enforce noshellslash for system calls 5484if exists ( '+shellslash' ) && & shellslash 5485for var in [ 'copycmd' , 'args' , 'tgt' ] 5486let { var } = substitute ( {var }, '/' , '\' , 'g' ) 5487endfor 5488endif 5489 5490" shell call 5491let shell_cmd = printf ( "%s %s %s %s" , copycmd , copycmdopt , args , tgt ) 5492call system ( shell_cmd ) 5493if v: shell_error != 0 5494if exists ( "b:netrw_curdir" ) && b: netrw_curdir != getcwd () && g: netrw_keepdir 5495call 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 )) 5496else 5497call netrw#msg#Notify ( 'ERROR' , printf ( "tried using g:netrw_localcopycmd<%s>; it doesn't work!" , g: netrw_localcopycmd )) 5498endif 5499return 0 5500endif 5501 5502elseif a: islocal && ! s: netrwmftgt_islocal 5503" Copy marked files, local directory to remote directory 5504NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{curbufnr},s:netrwmftgt) 5505 5506elseif ! a: islocal && s: netrwmftgt_islocal 5507" Copy marked files, remote directory to local directory 5508NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{curbufnr},s:netrwmftgt) 5509 5510elseif ! a: islocal && ! s: netrwmftgt_islocal 5511" Copy marked files, remote directory to remote directory 5512let curdir = getcwd () 5513let tmpdir = s: GetTempfile ( "" ) 5514if tmpdir !~ '/' 5515let tmpdir = curdir . "/" . tmpdir 5516endif 5517call mkdir ( tmpdir ) 5518if isdirectory ( s: NetrwFile ( tmpdir )) 5519if s: NetrwLcd ( tmpdir ) 5520return 5521endif 5522NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{curbufnr},tmpdir) 5523let localfiles = map ( deepcopy ( s: netrwmarkfilelist_ { curbufnr }), 'substitute(v:val,"^.*/","","")' ) 5524NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt) 5525if getcwd () == tmpdir 5526for fname in s: netrwmarkfilelist_ { curbufnr } 5527call netrw#fs#Remove ( fname ) 5528endfor 5529if s: NetrwLcd ( curdir ) 5530return 5531endif 5532if delete ( tmpdir , "d" ) 5533call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to delete directory <%s>!' , tmpdir )) 5534endif 5535else 5536if s: NetrwLcd ( curdir ) 5537return 5538endif 5539endif 5540endif 5541endif 5542 5543" ------- 5544" cleanup 5545" ------- 5546" remove markings from local buffer 5547call s: NetrwUnmarkList ( curbufnr , curdir ) " remove markings from local buffer 5548" see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium) 5549if g: netrw_fastbrowse <= 1 5550NetrwKeepj call s:LocalBrowseRefresh() 5551else 5552" refresh local and targets for fast browsing 5553" remove markings from local buffer 5554NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir) 5555 5556" refresh buffers 5557if s: netrwmftgt_islocal 5558NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) 5559endif 5560if a: islocal && s: netrwmftgt != curdir 5561NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir) 5562endif 5563endif 5564 5565return 1 5566endfunction 5567 5568" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2 5569" invoke vim's diff mode on the marked files. 5570" Either two or three files can be so handled. 5571" Uses the global marked file list. 5572function s: NetrwMarkFileDiff ( islocal ) 5573let curbufnr = bufnr ( "%" ) 5574 5575" sanity check 5576if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5577call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5578return 5579endif 5580let curdir = s: NetrwGetCurdir ( a: islocal ) 5581 5582if exists ( "s:netrwmarkfilelist_{" . curbufnr . "}" ) 5583let cnt = 0 5584for fname in s: netrwmarkfilelist 5585let cnt = cnt + 1 5586if cnt == 1 5587exe "NetrwKeepj e " . fnameescape ( fname ) 5588diffthis 5589elseif cnt == 2 || cnt == 3 5590below vsplit 5591exe "NetrwKeepj e " . fnameescape ( fname ) 5592diffthis 5593else 5594break 5595endif 5596endfor 5597call s: NetrwUnmarkList ( curbufnr , curdir ) 5598endif 5599 5600endfunction 5601 5602" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2 5603" Uses global markfilelist 5604function s: NetrwMarkFileEdit ( islocal ) 5605 5606let curdir = s: NetrwGetCurdir ( a: islocal ) 5607let curbufnr = bufnr ( "%" ) 5608 5609" sanity check 5610if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5611call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5612return 5613endif 5614 5615if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 5616call s: SetRexDir ( a: islocal , curdir ) 5617let flist = join ( map ( deepcopy ( s: netrwmarkfilelist ), "fnameescape(v:val)" )) 5618" unmark markedfile list 5619" call s:NetrwUnmarkList(curbufnr,curdir) 5620call s: NetrwUnmarkAll () 5621exe "sil args " . flist 5622endif 5623echo "(use :bn, :bp to navigate files; :Rex to return)" 5624 5625endfunction 5626 5627" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2 5628function s: NetrwMarkFileQFEL ( islocal , qfel ) 5629call s: NetrwUnmarkAll () 5630let curbufnr = bufnr ( "%" ) 5631 5632if ! empty ( a: qfel ) 5633for entry in a: qfel 5634let bufnmbr = entry [ "bufnr" ] 5635if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) 5636call s: NetrwMarkFile ( a: islocal , bufname ( bufnmbr )) 5637elseif index ( s: netrwmarkfilelist_ { curbufnr }, bufname ( bufnmbr )) == -1 5638" s:NetrwMarkFile will remove duplicate entries from the marked file list. 5639" So, this test lets two or more hits on the same pattern to be ignored. 5640call s: NetrwMarkFile ( a: islocal , bufname ( bufnmbr )) 5641else 5642endif 5643endfor 5644echo "(use me to edit marked files)" 5645else 5646call netrw#msg#Notify ( 'WARNING' , "can't convert quickfix error list; its empty!" ) 5647endif 5648 5649endfunction 5650 5651" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2 5652" mx enbloc=0: Uses the local marked-file list, applies command to each file individually 5653" mX enbloc=1: Uses the global marked-file list, applies command to entire list 5654function s: NetrwMarkFileExe ( islocal , enbloc ) 5655let svpos = winsaveview () 5656let curdir = s: NetrwGetCurdir ( a: islocal ) 5657let curbufnr = bufnr ( "%" ) 5658 5659if a: enbloc == 0 5660" individually apply command to files, one at a time 5661" sanity check 5662if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5663call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5664return 5665endif 5666 5667if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 5668" get the command 5669call inputsave () 5670let cmd = input ( "Enter command: " , "" , "file" ) 5671call inputrestore () 5672if cmd == "" 5673return 5674endif 5675 5676" apply command to marked files, individually. Substitute: filename -> % 5677" If no %, then append a space and the filename to the command 5678for fname in s: netrwmarkfilelist_ { curbufnr } 5679if a: islocal 5680if g: netrw_keepdir 5681let fname = netrw#os#Escape ( netrw#fs#WinPath ( netrw#fs#ComposePath ( curdir , fname ))) 5682else 5683let fname = netrw#os#Escape ( netrw#fs#WinPath ( fname )) 5684endif 5685else 5686let fname = netrw#os#Escape ( netrw#fs#WinPath ( b: netrw_curdir . fname )) 5687endif 5688if cmd =~ '%' 5689let xcmd = substitute ( cmd , '%' , fname , 'g' ) 5690else 5691let xcmd = cmd . ' ' . fname 5692endif 5693if a: islocal 5694let ret = system ( xcmd ) 5695else 5696let ret = s: RemoteSystem ( xcmd ) 5697endif 5698if v: shell_error < 0 5699call netrw#msg#Notify ( 'ERROR' , printf ( 'command<%s> failed, aborting' , xcmd )) 5700break 5701else 5702if ret !=# '' 5703echo "\n" 5704" skip trailing new line 5705echo ret [ 0 : -2 ] 5706else 5707echo ret 5708endif 5709endif 5710endfor 5711 5712" unmark marked file list 5713call s: NetrwUnmarkList ( curbufnr , curdir ) 5714 5715" refresh the listing 5716NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5717NetrwKeepj call winrestview(svpos) 5718else 5719call netrw#msg#Notify ( 'ERROR' , 'no files marked!' ) 5720endif 5721 5722else " apply command to global list of files, en bloc 5723 5724call inputsave () 5725let cmd = input ( "Enter command: " , "" , "file" ) 5726call inputrestore () 5727if cmd == "" 5728return 5729endif 5730if cmd =~ '%' 5731let cmd = substitute ( cmd , '%' , join ( map ( s: netrwmarkfilelist , 'netrw#os#Escape(v:val)' ), ' ' ), 'g' ) 5732else 5733let cmd = cmd . ' ' . join ( map ( s: netrwmarkfilelist , 'netrw#os#Escape(v:val)' ), ' ' ) 5734endif 5735if a: islocal 5736call system ( cmd ) 5737if v: shell_error < 0 5738call netrw#msg#Notify ( 'ERROR' , printf ( 'command<%s> failed, aborting' , xcmd )) 5739endif 5740else 5741let ret = s: RemoteSystem ( cmd ) 5742endif 5743call s: NetrwUnmarkAll () 5744 5745" refresh the listing 5746NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5747NetrwKeepj call winrestview(svpos) 5748 5749endif 5750endfunction 5751 5752" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix 5753" as the marked file(s) (toggles suffix presence) 5754" Uses the local marked file list. 5755function s: NetrwMarkHideSfx ( islocal ) 5756let svpos = winsaveview () 5757let curbufnr = bufnr ( "%" ) 5758 5759" s:netrwmarkfilelist_{curbufnr}: the List of marked files 5760if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 5761 5762for fname in s: netrwmarkfilelist_ { curbufnr } 5763" construct suffix pattern 5764if fname =~ '\.' 5765let sfxpat = "^.*" . substitute ( fname , '^.*\(\.[^. ]\+\)$' , '\1' , '' ) 5766else 5767let sfxpat = '^\%(\%(\.\)\@!.\)*$' 5768endif 5769" determine if its in the hiding list or not 5770let inhidelist = 0 5771if g: netrw_list_hide != "" 5772let itemnum = 0 5773let hidelist = split ( g: netrw_list_hide , ',' ) 5774for hidepat in hidelist 5775if sfxpat == hidepat 5776let inhidelist = 1 5777break 5778endif 5779let itemnum = itemnum + 1 5780endfor 5781endif 5782if inhidelist 5783" remove sfxpat from list 5784call remove ( hidelist , itemnum ) 5785let g: netrw_list_hide = join ( hidelist , "," ) 5786elseif g: netrw_list_hide != "" 5787" append sfxpat to non-empty list 5788let g: netrw_list_hide = g: netrw_list_hide . "," . sfxpat 5789else 5790" set hiding list to sfxpat 5791let g: netrw_list_hide = sfxpat 5792endif 5793endfor 5794 5795" refresh the listing 5796NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5797NetrwKeepj call winrestview(svpos) 5798else 5799call netrw#msg#Notify ( 'ERROR' , 'no files marked!' ) 5800endif 5801endfunction 5802 5803" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2 5804" Uses the local marked-file list. 5805function s: NetrwMarkFileVimCmd ( islocal ) 5806let svpos = winsaveview () 5807let curdir = s: NetrwGetCurdir ( a: islocal ) 5808let curbufnr = bufnr ( "%" ) 5809 5810" sanity check 5811if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5812call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5813return 5814endif 5815 5816if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 5817" get the command 5818call inputsave () 5819let cmd = input ( "Enter vim command: " , "" , "file" ) 5820call inputrestore () 5821if cmd == "" 5822return 5823endif 5824 5825" apply command to marked files. Substitute: filename -> % 5826" If no %, then append a space and the filename to the command 5827for fname in s: netrwmarkfilelist_ { curbufnr } 5828if a: islocal 58291 split 5830exe "sil! NetrwKeepj keepalt e " . fnameescape ( fname ) 5831exe cmd 5832exe "sil! keepalt wq!" 5833else 5834echo "sorry, \"mv\" not supported yet for remote files" 5835endif 5836endfor 5837 5838" unmark marked file list 5839call s: NetrwUnmarkList ( curbufnr , curdir ) 5840 5841" refresh the listing 5842NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 5843NetrwKeepj call winrestview(svpos) 5844else 5845call netrw#msg#Notify ( 'ERROR' , 'no files marked!' ) 5846endif 5847endfunction 5848 5849" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2 5850" Uses the global markfilelist 5851function s: NetrwMarkFileGrep ( islocal ) 5852let svpos = winsaveview () 5853let curbufnr = bufnr ( "%" ) 5854let curdir = s: NetrwGetCurdir ( a: islocal ) 5855 5856if exists ( "s:netrwmarkfilelist" ) 5857let netrwmarkfilelist = join ( map ( deepcopy ( s: netrwmarkfilelist ), "fnameescape(v:val)" )) 5858call s: NetrwUnmarkAll () 5859else 5860let netrwmarkfilelist = "*" 5861endif 5862 5863" ask user for pattern 5864call inputsave () 5865let pat = input ( "Enter pattern: " , "" ) 5866call inputrestore () 5867let patbang = "" 5868if pat =~ '^!' 5869let patbang = "!" 5870let pat = strpart ( pat , 2 ) 5871endif 5872if pat =~ '^\i' 5873let pat = escape ( pat , '/' ) 5874let pat = '/' . pat . '/' 5875else 5876let nonisi = pat [ 0 ] 5877endif 5878 5879" use vimgrep for both local and remote 5880try 5881exe "NetrwKeepj noautocmd vimgrep" . patbang . " " . pat . " " . netrwmarkfilelist 5882catch /^Vim\%((\a\+)\)\=:E480/ 5883call netrw#msg#Notify ( 'WARNING' , printf ( 'no match with pattern<%s>' , pat )) 5884return 5885endtry 5886echo "(use :cn, :cp to navigate, :Rex to return)" 5887 58882 match none 5889NetrwKeepj call winrestview(svpos) 5890 5891if exists ( "nonisi" ) 5892" original, user-supplied pattern did not begin with a character from isident 5893if pat =~# nonisi . 'j$\|' . nonisi . 'gj$\|' . nonisi . 'jg$' 5894call s: NetrwMarkFileQFEL ( a: islocal , getqflist ()) 5895endif 5896endif 5897 5898endfunction 5899 5900" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2 5901" uses the global marked file list 5902" s:netrwmfloc= 0: target directory is remote 5903" = 1: target directory is local 5904function s: NetrwMarkFileMove ( islocal ) 5905let curdir = s: NetrwGetCurdir ( a: islocal ) 5906let curbufnr = bufnr ( "%" ) 5907 5908" sanity check 5909if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 5910call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 5911return 5912endif 5913 5914if ! exists ( "s:netrwmftgt" ) 5915call netrw#msg#Notify ( 'ERROR' , 'your marked file target is empty! (:help netrw-mt)' ) 5916return 0 5917endif 5918 5919if a: islocal && s: netrwmftgt_islocal 5920" move: local -> local 5921if ! executable ( g: netrw_localmovecmd ) 5922call netrw#msg#Notify ( 'ERROR' , printf ( 'g:netrw_localmovecmd<%s> not executable on your system, aborting' , g: netrw_localmovecmd )) 5923return 5924endif 5925 5926let tgt = netrw#os#Escape ( s: netrwmftgt ) 5927if has ( "win32" ) && ! g: netrw_cygwin && g: netrw_localmovecmd =~ '\s' && g: netrw_localmovecmdopt == "" 5928let movecmd = substitute ( g: netrw_localmovecmd , '\s.*$' , '' , '' ) 5929let movecmdargs = substitute ( g: netrw_localmovecmd , '^.\{-}\(\s.*\)$' , '\1' , '' ) 5930else 5931let movecmd = g: netrw_localmovecmd 5932let movecmdargs = g: netrw_localmovecmdopt 5933endif 5934 5935" build args list 5936let args = [] 5937for fname in s: netrwmarkfilelist_ { curbufnr } 5938if g: netrw_keepdir 5939" Jul 19, 2022: fixing file move when g:netrw_keepdir is 1 5940let fname = netrw#fs#ComposePath ( b: netrw_curdir , fname ) 5941endif 5942call add ( args , netrw#os#Escape ( fname )) 5943endfor 5944 5945" enforce noshellslash for system calls 5946if exists ( '+shellslash' ) && & shellslash 5947let tgt = substitute ( tgt , '/' , '\' , 'g' ) 5948call map ( args , "substitute(v:val, '/', '\\', 'g')" ) 5949endif 5950 5951for fname in args 5952let shell_cmd = printf ( "%s %s %s %s" , movecmd , movecmdargs , fname , tgt ) 5953let ret = system ( shell_cmd ) 5954if v: shell_error != 0 5955if exists ( "b:netrw_curdir" ) && b: netrw_curdir != getcwd () && ! g: netrw_keepdir 5956call 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 )) 5957else 5958call netrw#msg#Notify ( 'ERROR' , printf ( "tried using g:netrw_localmovecmd<%s>; it doesn't work!" , g: netrw_localmovecmd )) 5959endif 5960break 5961endif 5962endfor 5963 5964elseif a: islocal && ! s: netrwmftgt_islocal 5965" move: local -> remote 5966let mflist = s: netrwmarkfilelist_ { curbufnr } 5967NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5968for fname in mflist 5969let barefname = substitute ( fname , '^\(.*/\)\(.\{-}\)$' , '\2' , '' ) 5970let ok = s: NetrwLocalRmFile ( b: netrw_curdir , barefname , 1 ) 5971endfor 5972unlet mflist 5973 5974elseif ! a: islocal && s: netrwmftgt_islocal 5975" move: remote -> local 5976let mflist = s: netrwmarkfilelist_ { curbufnr } 5977NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5978for fname in mflist 5979let barefname = substitute ( fname , '^\(.*/\)\(.\{-}\)$' , '\2' , '' ) 5980let ok = s: NetrwRemoteRmFile ( b: netrw_curdir , barefname , 1 ) 5981endfor 5982unlet mflist 5983 5984elseif ! a: islocal && ! s: netrwmftgt_islocal 5985" move: remote -> remote 5986let mflist = s: netrwmarkfilelist_ { curbufnr } 5987NetrwKeepj call s:NetrwMarkFileCopy(a:islocal) 5988for fname in mflist 5989let barefname = substitute ( fname , '^\(.*/\)\(.\{-}\)$' , '\2' , '' ) 5990let ok = s: NetrwRemoteRmFile ( b: netrw_curdir , barefname , 1 ) 5991endfor 5992unlet mflist 5993endif 5994 5995" ------- 5996" cleanup 5997" ------- 5998 5999" remove markings from local buffer 6000call s: NetrwUnmarkList ( curbufnr , curdir ) " remove markings from local buffer 6001 6002" refresh buffers 6003if ! s: netrwmftgt_islocal 6004NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt) 6005endif 6006if a: islocal 6007NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir) 6008endif 6009if g: netrw_fastbrowse <= 1 6010NetrwKeepj call s:LocalBrowseRefresh() 6011endif 6012 6013endfunction 6014 6015" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2 6016" files when given a regexp (for which a prompt is 6017" issued) (matches to name of files). 6018function s: NetrwMarkFileRegexp ( islocal ) 6019 6020" get the regular expression 6021call inputsave () 6022let regexp = input ( "Enter regexp: " , "" , "file" ) 6023call inputrestore () 6024 6025if a: islocal 6026let curdir = s: NetrwGetCurdir ( a: islocal ) 6027" get the matching list of files using local glob() 6028let dirname = escape ( b: netrw_curdir , g: netrw_glob_escape ) 6029let filelist = glob ( netrw#fs#ComposePath ( dirname , regexp ), 0 , 1 , 1 ) 6030 6031" mark the list of files 6032for fname in filelist 6033if fname =~ '^' . fnameescape ( curdir ) 6034NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','','')) 6035else 6036NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','','')) 6037endif 6038endfor 6039 6040else 6041 6042" convert displayed listing into a filelist 6043let eikeep = & ei 6044let areg = @a 6045sil NetrwKeepj %y a 6046setl ei = all ma 60471 split 6048NetrwKeepj call s:NetrwEnew() 6049NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 6050sil NetrwKeepj norm! "ap 6051NetrwKeepj 2 6052let bannercnt = search ( '^" =====' , 'W' ) 6053exe "sil NetrwKeepj 1," . bannercnt . "d" 6054setl bt = nofile 6055if g: netrw_liststyle == s: LONGLIST 6056sil NetrwKeepj %s/\s\{2,}\S.*$//e 6057call histdel ( "/" , -1 ) 6058elseif g: netrw_liststyle == s: WIDELIST 6059sil NetrwKeepj %s/\s\{2,}/\r/ge 6060call histdel ( "/" , -1 ) 6061elseif g: netrw_liststyle == s: TREELIST 6062exe 'sil NetrwKeepj %s/^' . s: treedepthstring . ' //e' 6063sil ! NetrwKeepj g/^ .*$/d 6064call histdel ( "/" , -1 ) 6065call histdel ( "/" , -1 ) 6066endif 6067" convert regexp into the more usual glob-style format 6068let regexp = substitute ( regexp , '\*' , '.*' , 'g' ) 6069exe "sil! NetrwKeepj v/" . escape ( regexp , '/' ) . "/d" 6070call histdel ( "/" , -1 ) 6071let filelist = getline ( 1 , line ( "$" )) 6072q ! 6073for filename in filelist 6074NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','','')) 6075endfor 6076unlet filelist 6077let @a = areg 6078let & ei = eikeep 6079endif 6080echo " (use me to edit marked files)" 6081 6082endfunction 6083 6084" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2 6085" Uses the local marked file list. 6086function s: NetrwMarkFileSource ( islocal ) 6087let curbufnr = bufnr ( "%" ) 6088 6089" sanity check 6090if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 6091call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 6092return 6093endif 6094let curdir = s: NetrwGetCurdir ( a: islocal ) 6095 6096if exists ( "s:netrwmarkfilelist_{curbufnr}" ) 6097let netrwmarkfilelist = s: netrwmarkfilelist_ { bufnr ( "%" )} 6098call s: NetrwUnmarkList ( curbufnr , curdir ) 6099for fname in netrwmarkfilelist 6100if a: islocal 6101if g: netrw_keepdir 6102let fname = netrw#fs#ComposePath ( curdir , fname ) 6103endif 6104else 6105let fname = curdir . fname 6106endif 6107" the autocmds will handle sourcing both local and remote files 6108exe "so " . fnameescape ( fname ) 6109endfor 61102 match none 6111endif 6112endfunction 6113 6114" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2 6115" Uses the global markfilelist 6116function s: NetrwMarkFileTag ( islocal ) 6117let svpos = winsaveview () 6118let curdir = s: NetrwGetCurdir ( a: islocal ) 6119let curbufnr = bufnr ( "%" ) 6120 6121" sanity check 6122if ! exists ( "s:netrwmarkfilelist_{curbufnr}" ) || empty ( s: netrwmarkfilelist_ { curbufnr }) 6123call netrw#msg#Notify ( 'ERROR' , 'there are no marked files in this window (:help netrw-mf)' ) 6124return 6125endif 6126 6127if exists ( "s:netrwmarkfilelist" ) 6128let netrwmarkfilelist = join ( map ( deepcopy ( s: netrwmarkfilelist ), "netrw#os#Escape(v:val," .! a: islocal . ")" )) 6129call s: NetrwUnmarkAll () 6130 6131if a: islocal 6132 6133call system ( g: netrw_ctags . " " . netrwmarkfilelist ) 6134if v: shell_error 6135call netrw#msg#Notify ( 'ERROR' , printf ( 'g:netrw_ctags<%s> is not executable!' , g: netrw_ctags )) 6136endif 6137 6138else 6139let cmd = s: RemoteSystem ( g: netrw_ctags . " " . netrwmarkfilelist ) 6140call netrw#Obtain ( a: islocal , "tags" ) 6141let curdir = b: netrw_curdir 61421 split 6143NetrwKeepj e tags 6144let path = substitute ( curdir , '^\(.*\)/[^/]*$' , '\1/' , '' ) 6145exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t' . escape ( path , "/\n\r\\" ) . '\1\t/e' 6146call histdel ( "/" , -1 ) 6147wq ! 6148endif 61492 match none 6150call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 6151call winrestview ( svpos ) 6152endif 6153endfunction 6154 6155" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2 6156" Sets up two variables, 6157" s:netrwmftgt : holds the target directory 6158" s:netrwmftgt_islocal : 0=target directory is remote 6159" 1=target directory is local 6160function s: NetrwMarkFileTgt ( islocal ) 6161let svpos = winsaveview () 6162let curdir = s: NetrwGetCurdir ( a: islocal ) 6163let hadtgt = exists ( "s:netrwmftgt" ) 6164if ! exists ( "w:netrw_bannercnt" ) 6165let w: netrw_bannercnt = b: netrw_bannercnt 6166endif 6167 6168" set up target 6169if line ( "." ) < w: netrw_bannercnt 6170" if cursor in banner region, use b:netrw_curdir for the target unless its already the target 6171if exists ( "s:netrwmftgt" ) && exists ( "s:netrwmftgt_islocal" ) && s: netrwmftgt == b: netrw_curdir 6172unlet s: netrwmftgt s: netrwmftgt_islocal 6173if g: netrw_fastbrowse <= 1 6174call s: LocalBrowseRefresh () 6175endif 6176call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 6177call winrestview ( svpos ) 6178return 6179else 6180let s: netrwmftgt = b: netrw_curdir 6181endif 6182 6183else 6184" get word under cursor. 6185" * If directory, use it for the target. 6186" * If file, use b:netrw_curdir for the target 6187let curword = s: NetrwGetWord () 6188let tgtdir = netrw#fs#ComposePath ( curdir , curword ) 6189if a: islocal && isdirectory ( s: NetrwFile ( tgtdir )) 6190let s: netrwmftgt = tgtdir 6191elseif ! a: islocal && tgtdir =~ '/$' 6192let s: netrwmftgt = tgtdir 6193else 6194let s: netrwmftgt = curdir 6195endif 6196endif 6197if a: islocal 6198" simplify the target (eg. /abc/def/../ghi -> /abc/ghi) 6199let s: netrwmftgt = simplify ( s: netrwmftgt ) 6200endif 6201if g: netrw_cygwin 6202let s: netrwmftgt = substitute ( system ( "cygpath " . netrw#os#Escape ( s: netrwmftgt )), '\n$' , '' , '' ) 6203let s: netrwmftgt = substitute ( s: netrwmftgt , '\n$' , '' , '' ) 6204endif 6205let s: netrwmftgt_islocal = a: islocal 6206 6207" need to do refresh so that the banner will be updated 6208" s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing 6209if g: netrw_fastbrowse <= 1 6210call s: LocalBrowseRefresh () 6211endif 6212" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6213if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 6214call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , w: netrw_treetop , 0 )) 6215else 6216call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 6217endif 6218call winrestview ( svpos ) 6219if ! hadtgt 6220sil ! NetrwKeepj norm! j 6221endif 6222endfunction 6223 6224" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2 6225function s: NetrwGetCurdir ( islocal ) 6226 6227if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 6228let b: netrw_curdir = s: NetrwTreePath ( w: netrw_treetop ) 6229elseif ! exists ( "b:netrw_curdir" ) 6230let b: netrw_curdir = getcwd () 6231endif 6232 6233if b: netrw_curdir !~ '\<\a\{3,}://' 6234let curdir = b: netrw_curdir 6235if g: netrw_keepdir == 0 6236call s: NetrwLcd ( curdir ) 6237endif 6238endif 6239 6240return b: netrw_curdir 6241endfunction 6242 6243" s:NetrwOpenFile: query user for a filename and open it {{{2 6244function s: NetrwOpenFile ( islocal ) 6245call inputsave () 6246let fname = input ( "Enter filename: " ) 6247call inputrestore () 6248 6249if empty ( fname ) 6250return 6251endif 6252 6253" save position for benefit of Rexplore 6254let s: rexposn_ { bufnr ( "%" )} = winsaveview () 6255 6256execute "NetrwKeepj e " . fnameescape ( ! isabsolutepath ( fname ) 6257\ ? netrw#fs#ComposePath ( b: netrw_curdir , fname ) 6258\ : fname ) 6259endfunction 6260 6261" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2 6262" For the mapping to this function be made via 6263" netrwPlugin, you'll need to have had 6264" g:netrw_usetab set to non-zero. 6265function netrw#Shrink () 6266let curwin = winnr () 6267let wiwkeep = & wiw 6268set wiw = 1 6269 6270if & ft == "netrw" 6271if winwidth ( 0 ) > g: netrw_wiw 6272let t: netrw_winwidth = winwidth ( 0 ) 6273exe "vert resize " . g: netrw_wiw 6274wincmd l 6275if winnr () == curwin 6276wincmd h 6277endif 6278else 6279exe "vert resize " . t: netrw_winwidth 6280endif 6281 6282elseif exists ( "t:netrw_lexbufnr" ) 6283exe bufwinnr ( t: netrw_lexbufnr ) . "wincmd w" 6284if winwidth ( bufwinnr ( t: netrw_lexbufnr )) > g: netrw_wiw 6285let t: netrw_winwidth = winwidth ( 0 ) 6286exe "vert resize " . g: netrw_wiw 6287wincmd l 6288if winnr () == curwin 6289wincmd h 6290endif 6291elseif winwidth ( bufwinnr ( t: netrw_lexbufnr )) >= 0 6292exe "vert resize " . t: netrw_winwidth 6293else 6294call netrw#Lexplore ( 0 , 0 ) 6295endif 6296 6297else 6298call netrw#Lexplore ( 0 , 0 ) 6299endif 6300let wiw = wiwkeep 6301 6302endfunction 6303 6304" s:NetSortSequence: allows user to edit the sorting sequence {{{2 6305function s: NetSortSequence ( islocal ) 6306let ykeep = @@ 6307let svpos = winsaveview () 6308call inputsave () 6309let newsortseq = input ( "Edit Sorting Sequence: " , g: netrw_sort_sequence ) 6310call inputrestore () 6311 6312" refresh the listing 6313let g: netrw_sort_sequence = newsortseq 6314NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6315NetrwKeepj call winrestview(svpos) 6316let @@ = ykeep 6317endfunction 6318 6319" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2 6320" User access provided by the <mF> mapping. (see :help netrw-mF) 6321" Used by many MarkFile functions. 6322function s: NetrwUnmarkList ( curbufnr , curdir ) 6323 6324" remove all files in local marked-file list from global list 6325if exists ( "s:netrwmarkfilelist" ) 6326for mfile in s: netrwmarkfilelist_ { a: curbufnr } 6327let dfile = netrw#fs#ComposePath ( a: curdir , mfile ) " prepend directory to mfile 6328let idx = index ( s: netrwmarkfilelist , dfile ) " get index in list of dfile 6329call remove ( s: netrwmarkfilelist , idx ) " remove from global list 6330endfor 6331if s: netrwmarkfilelist == [] 6332unlet s: netrwmarkfilelist 6333endif 6334 6335" getting rid of the local marked-file lists is easy 6336unlet s: netrwmarkfilelist_ { a: curbufnr } 6337endif 6338if exists ( "s:netrwmarkfilemtch_{a:curbufnr}" ) 6339unlet s: netrwmarkfilemtch_ { a: curbufnr } 6340endif 63412 match none 6342endfunction 6343 6344" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2 6345function s: NetrwUnmarkAll () 6346if exists ( "s:netrwmarkfilelist" ) 6347unlet s: netrwmarkfilelist 6348endif 6349sil call s: NetrwUnmarkAll2 () 63502 match none 6351endfunction 6352 6353" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2 6354function s: NetrwUnmarkAll2 () 6355redir => netrwmarkfilelist_let 6356let 6357redir END 6358let netrwmarkfilelist_list = split ( netrwmarkfilelist_let , '\n' ) " convert let string into a let list 6359call filter ( netrwmarkfilelist_list , "v:val =~ '^s:netrwmarkfilelist_'" ) " retain only those vars that start as s:netrwmarkfilelist_ 6360call map ( netrwmarkfilelist_list , "substitute(v:val,'\\s.*$','','')" ) " remove what the entries are equal to 6361for flist in netrwmarkfilelist_list 6362let curbufnr = substitute ( flist , 's:netrwmarkfilelist_' , '' , '' ) 6363unlet s: netrwmarkfilelist_ { curbufnr } 6364unlet s: netrwmarkfilemtch_ { curbufnr } 6365endfor 6366endfunction 6367 6368" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2 6369" 6370" Marked files are in two types of lists: 6371" s:netrwmarkfilelist -- holds complete paths to all marked files 6372" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr()) 6373" 6374" Marked files suitable for use with 2match are in: 6375" s:netrwmarkfilemtch_# -- used with 2match to display marked files 6376function s: NetrwUnMarkFile ( islocal ) 6377let svpos = winsaveview () 6378let curbufnr = bufnr ( "%" ) 6379 6380" unmark marked file list 6381" (although I expect s:NetrwUpload() to do it, I'm just making sure) 6382if exists ( "s:netrwmarkfilelist" ) 6383unlet s: netrwmarkfilelist 6384endif 6385 6386let ibuf = 1 6387while ibuf <= bufnr ( "$" ) 6388if exists ( "s:netrwmarkfilelist_" . ibuf ) 6389unlet s: netrwmarkfilelist_ { ibuf } 6390unlet s: netrwmarkfilemtch_ { ibuf } 6391endif 6392let ibuf = ibuf + 1 6393endwhile 63942 match none 6395 6396" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6397call winrestview ( svpos ) 6398endfunction 6399 6400" s:NetrwMenu: generates the menu for gvim and netrw {{{2 6401function s: NetrwMenu ( domenu ) 6402 6403if ! exists ( "g:NetrwMenuPriority" ) 6404let g: NetrwMenuPriority = 80 6405endif 6406 6407if has ( "menu" ) && has ( "gui_running" ) && & go =~# 'm' && g: netrw_menu 6408 6409if ! exists ( "s:netrw_menu_enabled" ) && a: domenu 6410let s: netrw_menu_enabled = 1 6411exe 'sil! menu ' . g: NetrwMenuPriority . '.1 ' . g: NetrwTopLvlMenu . 'Help<tab><F1> <F1>' 6412exe 'sil! menu ' . g: NetrwMenuPriority . '.5 ' . g: NetrwTopLvlMenu . '-Sep1- :' 6413exe 'sil! menu ' . g: NetrwMenuPriority . '.6 ' . g: NetrwTopLvlMenu . 'Go\ Up\ Directory<tab>- -' 6414exe 'sil! menu ' . g: NetrwMenuPriority . '.7 ' . g: NetrwTopLvlMenu . 'Apply\ Special\ Viewer<tab>x x' 6415if g: netrw_dirhistmax > 0 6416exe 'sil! menu ' . g: NetrwMenuPriority . '.8.1 ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb' 6417exe 'sil! menu ' . g: NetrwMenuPriority . '.8.4 ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u' 6418exe 'sil! menu ' . g: NetrwMenuPriority . '.8.5 ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U' 6419exe 'sil! menu ' . g: NetrwMenuPriority . '.8.6 ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History.List<tab>qb qb' 6420else 6421exe 'sil! menu ' . g: NetrwMenuPriority . '.8 ' . g: NetrwTopLvlMenu . 'Bookmarks\ and\ History :echo "(disabled)"' . "\<cr>" 6422endif 6423exe 'sil! menu ' . g: NetrwMenuPriority . '.9.1 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Horizontal\ Split<tab>o o' 6424exe 'sil! menu ' . g: NetrwMenuPriority . '.9.2 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Vertical\ Split<tab>v v' 6425exe 'sil! menu ' . g: NetrwMenuPriority . '.9.3 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.New\ Tab<tab>t t' 6426exe 'sil! menu ' . g: NetrwMenuPriority . '.9.4 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Preview<tab>p p' 6427exe 'sil! menu ' . g: NetrwMenuPriority . '.9.5 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>' . " \<c-h>'" 6428exe 'sil! menu ' . g: NetrwMenuPriority . '.9.6 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S' 6429exe 'sil! menu ' . g: NetrwMenuPriority . '.9.7 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>' . "gh gh" 6430exe 'sil! menu ' . g: NetrwMenuPriority . '.9.8 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Refresh\ Listing<tab>' . "<ctrl-l> \<c-l>" 6431exe 'sil! menu ' . g: NetrwMenuPriority . '.9.9 ' . g: NetrwTopLvlMenu . 'Browsing\ Control.Settings/Options<tab>:NetrwSettings ' . ":NetrwSettings\<cr>" 6432exe 'sil! menu ' . g: NetrwMenuPriority . '.10 ' . g: NetrwTopLvlMenu . 'Delete\ File/Directory<tab>D D' 6433exe 'sil! menu ' . g: NetrwMenuPriority . '.11.1 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.Create\ New\ File<tab>% %' 6434exe 'sil! menu ' . g: NetrwMenuPriority . '.11.1 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.In\ Current\ Window<tab><cr> ' . "\<cr>" 6435exe 'sil! menu ' . g: NetrwMenuPriority . '.11.2 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.Preview\ File/Directory<tab>p p' 6436exe 'sil! menu ' . g: NetrwMenuPriority . '.11.3 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.In\ Previous\ Window<tab>P P' 6437exe 'sil! menu ' . g: NetrwMenuPriority . '.11.4 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.In\ New\ Window<tab>o o' 6438exe 'sil! menu ' . g: NetrwMenuPriority . '.11.5 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.In\ New\ Tab<tab>t t' 6439exe 'sil! menu ' . g: NetrwMenuPriority . '.11.5 ' . g: NetrwTopLvlMenu . 'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v' 6440exe 'sil! menu ' . g: NetrwMenuPriority . '.12.1 ' . g: NetrwTopLvlMenu . 'Explore.Directory\ Name :Explore ' 6441exe 'sil! menu ' . g: NetrwMenuPriority . '.12.2 ' . g: NetrwTopLvlMenu . 'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */' 6442exe 'sil! menu ' . g: NetrwMenuPriority . '.12.2 ' . g: NetrwTopLvlMenu . 'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/' 6443exe 'sil! menu ' . g: NetrwMenuPriority . '.12.3 ' . g: NetrwTopLvlMenu . 'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//' 6444exe 'sil! menu ' . g: NetrwMenuPriority . '.12.4 ' . g: NetrwTopLvlMenu . 'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//' 6445exe 'sil! menu ' . g: NetrwMenuPriority . '.12.4 ' . g: NetrwTopLvlMenu . 'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>' 6446exe 'sil! menu ' . g: NetrwMenuPriority . '.12.4 ' . g: NetrwTopLvlMenu . 'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>' 6447exe 'sil! menu ' . g: NetrwMenuPriority . '.13 ' . g: NetrwTopLvlMenu . 'Make\ Subdirectory<tab>d d' 6448exe 'sil! menu ' . g: NetrwMenuPriority . '.14.1 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Mark\ File<tab>mf mf' 6449exe 'sil! menu ' . g: NetrwMenuPriority . '.14.2 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr' 6450exe 'sil! menu ' . g: NetrwMenuPriority . '.14.3 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Hide-Show-List\ Control<tab>a a' 6451exe 'sil! menu ' . g: NetrwMenuPriority . '.14.4 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Copy\ To\ Target<tab>mc mc' 6452exe 'sil! menu ' . g: NetrwMenuPriority . '.14.5 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Delete<tab>D D' 6453exe 'sil! menu ' . g: NetrwMenuPriority . '.14.6 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Diff<tab>md md' 6454exe 'sil! menu ' . g: NetrwMenuPriority . '.14.7 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Edit<tab>me me' 6455exe 'sil! menu ' . g: NetrwMenuPriority . '.14.8 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Exe\ Cmd<tab>mx mx' 6456exe 'sil! menu ' . g: NetrwMenuPriority . '.14.9 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Move\ To\ Target<tab>mm mm' 6457exe 'sil! menu ' . g: NetrwMenuPriority . '.14.10 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Obtain<tab>O O' 6458exe 'sil! menu ' . g: NetrwMenuPriority . '.14.11 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Print<tab>mp mp' 6459exe 'sil! menu ' . g: NetrwMenuPriority . '.14.12 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Replace<tab>R R' 6460exe 'sil! menu ' . g: NetrwMenuPriority . '.14.13 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Set\ Target<tab>mt mt' 6461exe 'sil! menu ' . g: NetrwMenuPriority . '.14.14 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Tag<tab>mT mT' 6462exe 'sil! menu ' . g: NetrwMenuPriority . '.14.15 ' . g: NetrwTopLvlMenu . 'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz' 6463exe 'sil! menu ' . g: NetrwMenuPriority . '.15 ' . g: NetrwTopLvlMenu . 'Obtain\ File<tab>O O' 6464exe 'sil! menu ' . g: NetrwMenuPriority . '.16.1.1 ' . g: NetrwTopLvlMenu . 'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>' 6465exe 'sil! menu ' . g: NetrwMenuPriority . '.16.1.1 ' . g: NetrwTopLvlMenu . 'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>' 6466exe 'sil! menu ' . g: NetrwMenuPriority . '.16.1.1 ' . g: NetrwTopLvlMenu . 'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>' 6467exe 'sil! menu ' . g: NetrwMenuPriority . '.16.1.1 ' . g: NetrwTopLvlMenu . 'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>' 6468exe '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>' 6469exe 'sil! menu ' . g: NetrwMenuPriority . '.16.2.3 ' . g: NetrwTopLvlMenu . 'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>' 6470exe '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>' 6471exe 'sil! menu ' . g: NetrwMenuPriority . '.16.3 ' . g: NetrwTopLvlMenu . 'Style.Reverse\ Sorting\ Order<tab>' . "r r" 6472exe 'sil! menu ' . g: NetrwMenuPriority . '.16.4.1 ' . g: NetrwTopLvlMenu . 'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>' 6473exe 'sil! menu ' . g: NetrwMenuPriority . '.16.4.2 ' . g: NetrwTopLvlMenu . 'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>' 6474exe 'sil! menu ' . g: NetrwMenuPriority . '.16.4.3 ' . g: NetrwTopLvlMenu . 'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>' 6475exe 'sil! menu ' . g: NetrwMenuPriority . '.16.4.3 ' . g: NetrwTopLvlMenu . 'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>' 6476exe 'sil! menu ' . g: NetrwMenuPriority . '.17 ' . g: NetrwTopLvlMenu . 'Rename\ File/Directory<tab>R R' 6477exe 'sil! menu ' . g: NetrwMenuPriority . '.18 ' . g: NetrwTopLvlMenu . 'Set\ Current\ Directory<tab>c c' 6478let s: netrw_menucnt = 28 6479call s: NetrwBookmarkMenu () " provide some history! uses priorities 2,3, reserves 4, 8.2.x 6480call s: NetrwTgtMenu () " let bookmarks and history be easy targets 6481 6482elseif ! a: domenu 6483let s: netrwcnt = 0 6484let curwin = winnr () 6485windo if getline(2) =~# "Netrw" | let s: netrwcnt = s: netrwcnt + 1 | endif 6486exe curwin . "wincmd w" 6487 6488if s: netrwcnt <= 1 6489exe 'sil! unmenu ' . g: NetrwTopLvlMenu 6490sil ! unlet s: netrw_menu_enabled 6491endif 6492endif 6493return 6494endif 6495 6496endfunction 6497 6498" s:NetrwObtain: obtain file under cursor or from markfile list {{{2 6499" Used by the O maps (as <SID>NetrwObtain()) 6500function s: NetrwObtain ( islocal ) 6501 6502let ykeep = @@ 6503if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 6504let islocal = s: netrwmarkfilelist_ { bufnr ( '%' )}[ 1 ] !~ '^\a\{3,}://' 6505call netrw#Obtain ( islocal , s: netrwmarkfilelist_ { bufnr ( '%' )}) 6506call s: NetrwUnmarkList ( bufnr ( '%' ), b: netrw_curdir ) 6507else 6508call netrw#Obtain ( a: islocal , s: NetrwGetWord ()) 6509endif 6510let @@ = ykeep 6511 6512endfunction 6513 6514" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2 6515" If there's only one window, then the window will first be split. 6516" Returns: 6517" choice = 0 : didn't have to choose 6518" choice = 1 : saved modified file in window first 6519" choice = 2 : didn't save modified file, opened window 6520" choice = 3 : cancel open 6521function s: NetrwPrevWinOpen ( islocal ) 6522let ykeep = @@ 6523" grab a copy of the b:netrw_curdir to pass it along to newly split windows 6524let curdir = b: netrw_curdir 6525 6526" get last window number and the word currently under the cursor 6527let origwin = winnr () 6528let lastwinnr = winnr ( "$" ) 6529let curword = s: NetrwGetWord () 6530let choice = 0 6531let s: prevwinopen = 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen) 6532let s: treedir = s: NetrwTreeDir ( a: islocal ) 6533let curdir = s: treedir 6534 6535let didsplit = 0 6536if lastwinnr == 1 6537" if only one window, open a new one first 6538" g:netrw_preview=0: preview window shown in a horizontally split window 6539" g:netrw_preview=1: preview window shown in a vertically split window 6540if g: netrw_preview 6541" vertically split preview window 6542let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize 6543exe ( g: netrw_alto ? "top " : "bot " ) . "vert " . winsz . "wincmd s" 6544else 6545" horizontally split preview window 6546let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winheight ( 0 )) / 100 : - g: netrw_winsize 6547exe ( g: netrw_alto ? "bel " : "abo " ). winsz . "wincmd s" 6548endif 6549let didsplit = 1 6550 6551else 6552NetrwKeepj call s:SaveBufVars() 6553let eikeep = & ei 6554setl ei = all 6555wincmd p 6556 6557if exists ( "s:lexplore_win" ) && s: lexplore_win == winnr () 6558" whoops -- user trying to open file in the Lexplore window. 6559" Use Lexplore's opening-file window instead. 6560" exe g:netrw_chgwin."wincmd w" 6561wincmd p 6562call s: NetrwBrowse ( 0 , s: NetrwBrowseChgDir ( 0 , s: NetrwGetWord (), 1 )) 6563endif 6564 6565" prevwinnr: the window number of the "prev" window 6566" prevbufnr: the buffer number of the buffer in the "prev" window 6567" bnrcnt : the qty of windows open on the "prev" buffer 6568let prevwinnr = winnr () 6569let prevbufnr = bufnr ( "%" ) 6570let prevbufname = bufname ( "%" ) 6571let prevmod = & mod 6572let bnrcnt = 0 6573NetrwKeepj call s:RestoreBufVars() 6574 6575" if the previous window's buffer has been changed (ie. its modified flag is set), 6576" and it doesn't appear in any other extant window, then ask the 6577" user if s/he wants to abandon modifications therein. 6578if prevmod 6579windo if winbufnr(0) == prevbufnr | let bnrcnt = bnrcnt + 1 | endif 6580exe prevwinnr . "wincmd w" 6581 6582if bnrcnt == 1 && & hidden == 0 6583" only one copy of the modified buffer in a window, and 6584" hidden not set, so overwriting will lose the modified file. Ask first... 6585let choice = confirm ( "Save modified buffer<" . prevbufname . "> first?" , "&Yes\n&No\n&Cancel" ) 6586let & ei = eikeep 6587 6588if choice == 1 6589" Yes -- write file & then browse 6590let v: errmsg = "" 6591sil w 6592if v: errmsg != "" 6593call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to write <%s>!' , ( exists ( "prevbufname" ) ? prevbufname : 'n/a' ))) 6594exe origwin . "wincmd w" 6595let & ei = eikeep 6596let @@ = ykeep 6597return choice 6598endif 6599 6600elseif choice == 2 6601" No -- don't worry about changed file, just browse anyway 6602echomsg "**note** changes to " . prevbufname . " abandoned" 6603 6604else 6605" Cancel -- don't do this 6606exe origwin . "wincmd w" 6607let & ei = eikeep 6608let @@ = ykeep 6609return choice 6610endif 6611endif 6612endif 6613let & ei = eikeep 6614endif 6615 6616" restore b:netrw_curdir (window split/enew may have lost it) 6617let b: netrw_curdir = curdir 6618if a: islocal < 2 6619if a: islocal 6620call netrw#LocalBrowseCheck ( s: NetrwBrowseChgDir ( a: islocal , curword , 0 )) 6621else 6622call s: NetrwBrowse ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , curword , 0 )) 6623endif 6624endif 6625let @@ = ykeep 6626return choice 6627endfunction 6628 6629" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2 6630" Always assumed to be local -> remote 6631" call s:NetrwUpload(filename, target) 6632" call s:NetrwUpload(filename, target, fromdirectory) 6633function s: NetrwUpload ( fname , tgt ,...) 6634 6635if a: tgt =~ '^\a\{3,}://' 6636let tgtdir = substitute ( a: tgt , '^\a\{3,}://[^/]\+/\(.\{-}\)$' , '\1' , '' ) 6637else 6638let tgtdir = substitute ( a: tgt , '^\(.*\)/[^/]*$' , '\1' , '' ) 6639endif 6640 6641if a: 0 > 0 6642let fromdir = a: 1 6643else 6644let fromdir = getcwd () 6645endif 6646 6647if type ( a: fname ) == 1 6648" handle uploading a single file using NetWrite 66491 split 6650exe "NetrwKeepj e " . fnameescape ( s: NetrwFile ( a: fname )) 6651if a: tgt =~ '/$' 6652let wfname = substitute ( a: fname , '^.*/' , '' , '' ) 6653exe "w! " . fnameescape ( a: tgt . wfname ) 6654else 6655exe "w " . fnameescape ( a: tgt ) 6656endif 6657q ! 6658 6659elseif type ( a: fname ) == 3 6660" handle uploading a list of files via scp 6661let curdir = getcwd () 6662if a: tgt =~ '^scp:' 6663if s: NetrwLcd ( fromdir ) 6664return 6665endif 6666let filelist = deepcopy ( s: netrwmarkfilelist_ { bufnr ( '%' )}) 6667let args = join ( map ( filelist , "netrw#os#Escape(v:val, 1)" )) 6668if exists ( "g:netrw_port" ) && g: netrw_port != "" 6669let useport = " " . g: netrw_scpport . " " . g: netrw_port 6670else 6671let useport = "" 6672endif 6673let machine = substitute ( a: tgt , '^scp://\([^/:]\+\).*$' , '\1' , '' ) 6674let tgt = substitute ( a: tgt , '^scp://[^/]\+/\(.*\)$' , '\1' , '' ) 6675call netrw#os#Execute ( s: netrw_silentxfer . "!" . g: netrw_scp_cmd . netrw#os#Escape ( useport , 1 ) . " " . args . " " . netrw#os#Escape ( machine . ":" . tgt , 1 )) 6676if s: NetrwLcd ( curdir ) 6677return 6678endif 6679 6680elseif a: tgt =~ '^ftp:' 6681call s: NetrwMethod ( a: tgt ) 6682if ! s: NetrwValidateHostname ( g: netrw_machine ) 6683call netrw#msg#Notify ( 'ERROR' , printf ( 'Rejecting invalid hostname: <%s>' , g: netrw_machine )) 6684return 6685endif 6686 6687if b: netrw_method == 2 6688" handle uploading a list of files via ftp+.netrc 6689let netrw_fname = b: netrw_fname 6690sil NetrwKeepj new 6691 6692NetrwKeepj put =g:netrw_ftpmode 6693 6694if exists ( "g:netrw_ftpextracmd" ) 6695NetrwKeepj put =g:netrw_ftpextracmd 6696endif 6697 6698NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'" ') 6699 6700if tgtdir == "" 6701let tgtdir = '/' 6702endif 6703NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'" ') 6704 6705for fname in a: fname 6706NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'" ') 6707endfor 6708 6709if exists ( "g:netrw_port" ) && g: netrw_port != "" 6710call 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 )) 6711else 6712call netrw#os#Execute ( s: netrw_silentxfer . "%!" . s: netrw_ftp_cmd . " -i " . netrw#os#Escape ( g: netrw_machine , 1 )) 6713endif 6714" If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 6715sil NetrwKeepj g/Local directory now/d 6716call histdel ( "/" , -1 ) 6717if getline ( 1 ) !~ "^$" && getline ( 1 ) !~ '^Trying ' 6718call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 6719else 6720bw !|q 6721endif 6722 6723elseif b: netrw_method == 3 6724" upload with ftp + machine, id, passwd, and fname (ie. no .netrc) 6725let netrw_fname = b: netrw_fname 6726NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars() 6727let tmpbufnr = bufnr ( "%" ) 6728setl ff = unix 6729 6730if exists ( "g:netrw_port" ) && g: netrw_port != "" 6731NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 6732else 6733NetrwKeepj put ='open '.g:netrw_machine 6734endif 6735 6736if exists ( "g:netrw_uid" ) && g: netrw_uid != "" 6737if exists ( "g:netrw_ftp" ) && g: netrw_ftp == 1 6738NetrwKeepj put =g:netrw_uid 6739if exists ( "s:netrw_passwd" ) 6740NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"') 6741endif 6742elseif exists ( "s:netrw_passwd" ) 6743NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 6744endif 6745endif 6746 6747NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'" ') 6748 6749if exists ( "b:netrw_fname" ) && b: netrw_fname != "" 6750NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'" ') 6751endif 6752 6753if exists ( "g:netrw_ftpextracmd" ) 6754NetrwKeepj put =g:netrw_ftpextracmd 6755endif 6756 6757for fname in a: fname 6758NetrwKeepj call setline(line("$")+1,'put "'.fname.'" ') 6759endfor 6760 6761" perform ftp: 6762" -i : turns off interactive prompting from ftp 6763" -n unix : DON'T use <.netrc>, even though it exists 6764" -n win32: quit being obnoxious about password 6765NetrwKeepj norm! 1G"_dd 6766call netrw#os#Execute ( s: netrw_silentxfer . "%!" . s: netrw_ftp_cmd . " " . g: netrw_ftp_options ) 6767" If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) 6768sil NetrwKeepj g/Local directory now/d 6769call histdel ( "/" , -1 ) 6770if getline ( 1 ) !~ "^$" && getline ( 1 ) !~ '^Trying ' 6771let debugkeep = & debug 6772setl debug = msg 6773call netrw#msg#Notify ( 'ERROR' , getline ( 1 )) 6774let & debug = debugkeep 6775let mod = 1 6776else 6777bw !|q 6778endif 6779elseif ! exists ( "b:netrw_method" ) || b: netrw_method < 0 6780return 6781endif 6782else 6783call netrw#msg#Notify ( 'ERROR' , printf ( "can't obtain files with protocol from<%s>" , a: tgt )) 6784endif 6785endif 6786 6787endfunction 6788 6789" s:NetrwPreview: supports netrw's "p" map {{{2 6790function s: NetrwPreview ( path ) range 6791let ykeep = @@ 6792NetrwKeepj call s:NetrwOptionsSave("s:") 6793if a: path !~ '^\*\{1,2}/' && a: path !~ '^\a\{3,}://' 6794NetrwKeepj call s:NetrwOptionsSafe(1) 6795else 6796NetrwKeepj call s:NetrwOptionsSafe(0) 6797endif 6798if has ( "quickfix" ) 6799if ! isdirectory ( s: NetrwFile ( a: path )) 6800if g: netrw_preview 6801" vertical split 6802let pvhkeep = & pvh 6803let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize 6804let & pvh = winwidth ( 0 ) - winsz 6805else 6806" horizontal split 6807let pvhkeep = & pvh 6808let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winheight ( 0 )) / 100 : - g: netrw_winsize 6809let & pvh = winheight ( 0 ) - winsz 6810endif 6811" g:netrw_preview g:netrw_alto 6812" 1 : vert 1: top -- preview window is vertically split off and on the left 6813" 1 : vert 0: bot -- preview window is vertically split off and on the right 6814" 0 : 1: top -- preview window is horizontally split off and on the top 6815" 0 : 0: bot -- preview window is horizontally split off and on the bottom 6816" 6817" Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via 6818" the BufEnter event set up in netrwPlugin.vim 6819let eikeep = & ei 6820set ei = BufEnter 6821exe ( g: netrw_alto ? "top " : "bot " ) . ( g: netrw_preview ? "vert " : "" ) . "pedit " . fnameescape ( a: path ) 6822let & ei = eikeep 6823if exists ( "pvhkeep" ) 6824let & pvh = pvhkeep 6825endif 6826else 6827call netrw#msg#Notify ( 'WARNING' , printf ( 'sorry, cannot preview a directory such as <%s>' , a: path )) 6828endif 6829else 6830call netrw#msg#Notify ( 'WARNING' , 'sorry, to preview your vim needs the quickfix feature compiled in' ) 6831endif 6832NetrwKeepj call s:NetrwOptionsRestore("s:") 6833let @@ = ykeep 6834endfunction 6835 6836" s:NetrwRefresh: {{{2 6837function s: NetrwRefresh ( islocal , dirname ) 6838" at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first. 6839setl ma noro 6840let ykeep = @@ 6841if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 6842if ! exists ( "w:netrw_treetop" ) 6843if exists ( "b:netrw_curdir" ) 6844let w: netrw_treetop = b: netrw_curdir 6845else 6846let w: netrw_treetop = getcwd () 6847endif 6848endif 6849NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop) 6850endif 6851 6852" save the cursor position before refresh. 6853let screenposn = winsaveview () 6854 6855sil ! NetrwKeepj %d _ 6856if a: islocal 6857NetrwKeepj call netrw#LocalBrowseCheck(a:dirname) 6858else 6859NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname) 6860endif 6861 6862" restore position 6863NetrwKeepj call winrestview(screenposn) 6864 6865" restore file marks 6866if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 6867if exists ( "s:netrwmarkfilemtch_{bufnr('%')}" ) && s: netrwmarkfilemtch_ { bufnr ( "%" )} != "" 6868exe "2match netrwMarkFile /" . s: netrwmarkfilemtch_ { bufnr ( "%" )} . "/" 6869else 68702 match none 6871endif 6872endif 6873 6874" restore 6875let @@ = ykeep 6876endfunction 6877 6878" s:NetrwRefreshDir: refreshes a directory by name {{{2 6879" Called by NetrwMarkFileCopy() 6880" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh() 6881function s: NetrwRefreshDir ( islocal , dirname ) 6882if g: netrw_fastbrowse == 0 6883" slowest mode (keep buffers refreshed, local or remote) 6884let tgtwin = bufwinnr ( a: dirname ) 6885 6886if tgtwin > 0 6887" tgtwin is being displayed, so refresh it 6888let curwin = winnr () 6889exe tgtwin . "wincmd w" 6890NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 6891exe curwin . "wincmd w" 6892 6893elseif bufnr ( a: dirname ) > 0 6894let bn = bufnr ( a: dirname ) 6895exe "sil keepj bd " . bn 6896endif 6897 6898elseif g: netrw_fastbrowse <= 1 6899NetrwKeepj call s:LocalBrowseRefresh() 6900endif 6901endfunction 6902 6903" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified 6904" window number to do its editing in. 6905" Supports [count]C where the count, if present, is used to specify 6906" a window to use for editing via the <cr> mapping. 6907function s: NetrwSetChgwin (...) 6908if a: 0 > 0 6909if a: 1 == "" " :NetrwC win# 6910let g: netrw_chgwin = winnr () 6911else " :NetrwC 6912let g: netrw_chgwin = a: 1 6913endif 6914elseif v: count > 0 " [count]C 6915let g: netrw_chgwin = v: count 6916else " C 6917let g: netrw_chgwin = winnr () 6918endif 6919echo "editing window now set to window#" . g: netrw_chgwin 6920endfunction 6921 6922" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2 6923" What this function does is to compute a priority for the patterns 6924" in the g:netrw_sort_sequence. It applies a substitute to any 6925" "files" that satisfy each pattern, putting the priority / in 6926" front. An "*" pattern handles the default priority. 6927function s: NetrwSetSort () 6928let ykeep = @@ 6929if w: netrw_liststyle == s: LONGLIST 6930let seqlist = substitute ( g: netrw_sort_sequence , '\$' , '\\%(\t\\|\$\\)' , 'ge' ) 6931else 6932let seqlist = g: netrw_sort_sequence 6933endif 6934" sanity check -- insure that * appears somewhere 6935if seqlist == "" 6936let seqlist = '*' 6937elseif seqlist !~ '\*' 6938let seqlist = seqlist . ',*' 6939endif 6940let priority = 1 6941while seqlist != "" 6942if seqlist =~ ',' 6943let seq = substitute ( seqlist , ',.*$' , '' , 'e' ) 6944let seqlist = substitute ( seqlist , '^.\{-},\(.*\)$' , '\1' , 'e' ) 6945else 6946let seq = seqlist 6947let seqlist = "" 6948endif 6949if priority < 10 6950let spriority = "00" . priority . g: netrw_sepchr 6951elseif priority < 100 6952let spriority = "0" . priority . g: netrw_sepchr 6953else 6954let spriority = priority . g: netrw_sepchr 6955endif 6956 6957" sanity check 6958if w: netrw_bannercnt > line ( "$" ) 6959" apparently no files were left after a Hiding pattern was used 6960return 6961endif 6962if seq == '*' 6963let starpriority = spriority 6964else 6965exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$g/' . seq . '/s/^/' . spriority . '/' 6966call histdel ( "/" , -1 ) 6967" sometimes multiple sorting patterns will match the same file or directory. 6968" The following substitute is intended to remove the excess matches. 6969exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$g/^\d\{3}' . g: netrw_sepchr . '\d\{3}\//s/^\d\{3}' . g: netrw_sepchr . '\(\d\{3}\/\).\@=/\1/e' 6970NetrwKeepj call histdel("/",-1) 6971endif 6972let priority = priority + 1 6973endwhile 6974if exists ( "starpriority" ) 6975exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$v/^\d\{3}' . g: netrw_sepchr . '/s/^/' . starpriority . '/e' 6976NetrwKeepj call histdel("/",-1) 6977endif 6978 6979" Following line associated with priority -- items that satisfy a priority 6980" pattern get prefixed by ###/ which permits easy sorting by priority. 6981" Sometimes files can satisfy multiple priority patterns -- only the latest 6982" priority pattern needs to be retained. So, at this point, these excess 6983" priority prefixes need to be removed, but not directories that happen to 6984" be just digits themselves. 6985exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\(\d\{3}' . g: netrw_sepchr . '\)\%(\d\{3}' . g: netrw_sepchr . '\)\+\ze./\1/e' 6986NetrwKeepj call histdel("/",-1) 6987let @@ = ykeep 6988 6989endfunction 6990 6991" s:NetrwSetTgt: sets the target to the specified choice index {{{2 6992" Implements [count]Tb (bookhist<b>) 6993" [count]Th (bookhist<h>) 6994" See :help netrw-qb for how to make the choice. 6995function s: NetrwSetTgt ( islocal , bookhist , choice ) 6996 6997if a: bookhist == 'b' 6998" supports choosing a bookmark as a target using a qb-generated list 6999let choice = a: choice - 1 7000if exists ( "g:netrw_bookmarklist[" . choice . "]" ) 7001call netrw#MakeTgt ( g: netrw_bookmarklist [ choice ]) 7002else 7003echomsg "Sorry, bookmark#" . a: choice . " doesn't exist!" 7004endif 7005 7006elseif a: bookhist == 'h' 7007" supports choosing a history stack entry as a target using a qb-generated list 7008let choice = ( a: choice % g: netrw_dirhistmax ) + 1 7009if exists ( "g:netrw_dirhist_" . choice ) 7010let histentry = g: netrw_dirhist_ { choice } 7011call netrw#MakeTgt ( histentry ) 7012else 7013echomsg "Sorry, history#" . a: choice . " not available!" 7014endif 7015endif 7016 7017" refresh the display 7018if ! exists ( "b:netrw_curdir" ) 7019let b: netrw_curdir = getcwd () 7020endif 7021call s: NetrwRefresh ( a: islocal , b: netrw_curdir ) 7022 7023endfunction 7024 7025" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2 7026function s: NetrwSortStyle ( islocal ) 7027NetrwKeepj call s:NetrwSaveWordPosn() 7028let svpos = winsaveview () 7029 7030let g: netrw_sort_by = ( g: netrw_sort_by =~# '^n' ) ? 'time' : ( g: netrw_sort_by =~# '^t' ) ? 'size' : ( g: netrw_sort_by =~# '^siz' ) ? 'exten' : 'name' 7031NetrwKeepj norm! 0 7032NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0)) 7033NetrwKeepj call winrestview(svpos) 7034endfunction 7035 7036" s:NetrwSplit: mode {{{2 7037" =0 : net and o 7038" =1 : net and t 7039" =2 : net and v 7040" =3 : local and o 7041" =4 : local and t 7042" =5 : local and v 7043function s: NetrwSplit ( mode ) 7044 7045let ykeep = @@ 7046call s: SaveWinVars () 7047 7048if a: mode == 0 7049" remote and o 7050let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winheight ( 0 )) / 100 : - g: netrw_winsize 7051if winsz == 0 | let winsz = "" | endif 7052exe ( g: netrw_alto ? "bel " : "abo " ). winsz . "wincmd s" 7053let s: didsplit = 1 7054NetrwKeepj call s:RestoreWinVars() 7055NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 7056unlet s: didsplit 7057 7058elseif a: mode == 1 7059" remote and t 7060let newdir = s: NetrwBrowseChgDir ( 0 , s: NetrwGetWord (), 1 ) 7061tabnew 7062let s: didsplit = 1 7063NetrwKeepj call s:RestoreWinVars() 7064NetrwKeepj call s:NetrwBrowse(0,newdir) 7065unlet s: didsplit 7066 7067elseif a: mode == 2 7068" remote and v 7069let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize 7070if winsz == 0 | let winsz = "" | endif 7071exe ( g: netrw_altv ? "rightb " : "lefta " ). winsz . "wincmd v" 7072let s: didsplit = 1 7073NetrwKeepj call s:RestoreWinVars() 7074NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)) 7075unlet s: didsplit 7076 7077elseif a: mode == 3 7078" local and o 7079let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winheight ( 0 )) / 100 : - g: netrw_winsize 7080if winsz == 0 | let winsz = "" | endif 7081exe ( g: netrw_alto ? "bel " : "abo " ). winsz . "wincmd s" 7082let s: didsplit = 1 7083NetrwKeepj call s:RestoreWinVars() 7084NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 7085unlet s: didsplit 7086if & ea 7087exe "keepalt wincmd =" 7088endif 7089 7090elseif a: mode == 4 7091" local and t 7092let cursorword = s: NetrwGetWord () 7093let eikeep = & ei 7094let netrw_winnr = winnr () 7095let netrw_line = line ( "." ) 7096let netrw_col = virtcol ( "." ) 7097NetrwKeepj norm! H0 7098let netrw_hline = line ( "." ) 7099setl ei = all 7100exe "NetrwKeepj norm! " . netrw_hline . "G0z\<CR>" 7101exe "NetrwKeepj norm! " . netrw_line . "G0" . netrw_col . "\<bar>" 7102let & ei = eikeep 7103let netrw_curdir = s: NetrwTreeDir ( 0 ) 7104tabnew 7105let b: netrw_curdir = netrw_curdir 7106let s: didsplit = 1 7107NetrwKeepj call s:RestoreWinVars() 7108NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0)) 7109if & ft == "netrw" 7110setl ei = all 7111exe "NetrwKeepj norm! " . netrw_hline . "G0z\<CR>" 7112exe "NetrwKeepj norm! " . netrw_line . "G0" . netrw_col . "\<bar>" 7113let & ei = eikeep 7114endif 7115unlet s: didsplit 7116 7117elseif a: mode == 5 7118" local and v 7119let winsz = ( g: netrw_winsize > 0 ) ? ( g: netrw_winsize * winwidth ( 0 )) / 100 : - g: netrw_winsize 7120if winsz == 0 | let winsz = "" | endif 7121exe ( g: netrw_altv ? "rightb " : "lefta " ). winsz . "wincmd v" 7122let s: didsplit = 1 7123NetrwKeepj call s:RestoreWinVars() 7124NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1)) 7125unlet s: didsplit 7126if & ea 7127exe "keepalt wincmd =" 7128endif 7129 7130else 7131call netrw#msg#Notify ( 'ERROR' , '(NetrwSplit) unsupported mode=' . a: mode ) 7132endif 7133 7134let @@ = ykeep 7135endfunction 7136 7137" s:NetrwTgtMenu: {{{2 7138function s: NetrwTgtMenu () 7139if ! exists ( "s:netrw_menucnt" ) 7140return 7141endif 7142 7143" the following test assures that gvim is running, has menus available, and has menus enabled. 7144if has ( "gui" ) && has ( "menu" ) && has ( "gui_running" ) && & go =~# 'm' && g: netrw_menu 7145if exists ( "g:NetrwTopLvlMenu" ) 7146exe 'sil! unmenu ' . g: NetrwTopLvlMenu . 'Targets' 7147endif 7148if ! exists ( "s:netrw_initbookhist" ) 7149call s: NetrwBookHistRead () 7150endif 7151 7152" try to cull duplicate entries 7153let tgtdict = {} 7154 7155" target bookmarked places 7156if exists ( "g:netrw_bookmarklist" ) && g: netrw_bookmarklist != [] && g: netrw_dirhistmax > 0 7157let cnt = 1 7158for bmd in g: netrw_bookmarklist 7159if has_key ( tgtdict , bmd ) 7160let cnt = cnt + 1 7161continue 7162endif 7163let tgtdict [ bmd ] = cnt 7164let ebmd = escape ( bmd , g: netrw_menu_escape ) 7165" show bookmarks for goto menu 7166exe 'sil! menu <silent> ' . g: NetrwMenuPriority . ".19.1." . cnt . " " . g: NetrwTopLvlMenu . 'Targets.' . ebmd . " :call netrw#MakeTgt(" . escape ( string ( bmd ), '|' ) . ")\<cr>" 7167let cnt = cnt + 1 7168endfor 7169endif 7170 7171" target directory browsing history 7172if exists ( "g:netrw_dirhistmax" ) && g: netrw_dirhistmax > 0 7173let histcnt = 1 7174while histcnt <= g: netrw_dirhistmax 7175let priority = g: netrw_dirhistcnt + histcnt 7176if exists ( "g:netrw_dirhist_{histcnt}" ) 7177let histentry = g: netrw_dirhist_ { histcnt } 7178if has_key ( tgtdict , histentry ) 7179let histcnt = histcnt + 1 7180continue 7181endif 7182let tgtdict [ histentry ] = histcnt 7183let ehistentry = escape ( histentry , g: netrw_menu_escape ) 7184exe 'sil! menu <silent> ' . g: NetrwMenuPriority . ".19.2." . priority . " " . g: NetrwTopLvlMenu . 'Targets.' . ehistentry . " :call netrw#MakeTgt(" . escape ( string ( histentry ), '|' ) . ")\<cr>" 7185endif 7186let histcnt = histcnt + 1 7187endwhile 7188endif 7189endif 7190endfunction 7191 7192" s:NetrwTreeDir: determine tree directory given current cursor position {{{2 7193" (full path directory with trailing slash returned) 7194function s: NetrwTreeDir ( islocal ) 7195 7196if exists ( "s:treedir" ) && exists ( "s:prevwinopen" ) 7197" s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early 7198let treedir = s: treedir 7199unlet s: treedir 7200unlet s: prevwinopen 7201return treedir 7202endif 7203if exists ( "s:prevwinopen" ) 7204unlet s: prevwinopen 7205endif 7206 7207if ! exists ( "b:netrw_curdir" ) || b: netrw_curdir == "" 7208let b: netrw_curdir = getcwd () 7209endif 7210let treedir = b: netrw_curdir 7211let s: treecurpos = winsaveview () 7212 7213if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 7214 7215" extract tree directory if on a line specifying a subdirectory (ie. ends with "/") 7216let curline = substitute ( getline ( '.' ), "\t -->.*$" , '' , '' ) 7217if curline =~ '/$' 7218let treedir = substitute ( getline ( '.' ), '^\%(' . s: treedepthstring . '\)*\([^' . s: treedepthstring . '].\{-}\)$' , '\1' , 'e' ) 7219elseif curline =~ '@$' 7220let potentialdir = resolve ( s: NetrwTreePath ( w: netrw_treetop )) 7221else 7222let treedir = "" 7223endif 7224 7225" detect user attempting to close treeroot 7226if curline !~ '^' . s: treedepthstring && getline ( '.' ) != '..' 7227" now force a refresh 7228sil ! NetrwKeepj %d _ 7229return b: netrw_curdir 7230endif 7231 7232" COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop 7233" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir)) 7234" let newdir = w:netrw_treetop.'/'.potentialdir 7235if a: islocal && curline =~ '@$' 7236if isdirectory ( s: NetrwFile ( potentialdir )) 7237let treedir = potentialdir 7238let w: netrw_treetop = treedir 7239endif 7240else 7241let potentialdir = s: NetrwFile ( substitute ( curline , '^' . s: treedepthstring . '\+ \(.*\)@$' , '\1' , '' )) 7242let treedir = s: NetrwTreePath ( w: netrw_treetop ) 7243endif 7244endif 7245 7246" sanity maintenance: keep those //s away... 7247let treedir = substitute ( treedir , '//$' , '/' , '' ) 7248return treedir 7249endfunction 7250 7251" s:NetrwTreeDisplay: recursive tree display {{{2 7252function s: NetrwTreeDisplay ( dir , depth ) 7253" ensure that there are no folds 7254setl nofen 7255 7256" install ../ and shortdir 7257if a: depth == "" 7258call setline ( line ( "$" ) + 1 , '../' ) 7259endif 7260if a: dir =~ '^\a\{3,}://' 7261if a: dir == w: netrw_treetop 7262let shortdir = a: dir 7263else 7264let shortdir = substitute ( a: dir , '^.*/\([^/]\+\)/$' , '\1/' , 'e' ) 7265endif 7266call setline ( line ( "$" ) + 1 , a: depth . shortdir ) 7267else 7268let shortdir = substitute ( a: dir , '^.*/' , '' , 'e' ) 7269call setline ( line ( "$" ) + 1 , a: depth . shortdir . '/' ) 7270endif 7271" append a / to dir if its missing one 7272let dir = a: dir 7273 7274" display subtrees (if any) 7275let depth = s: treedepthstring . a: depth 7276 7277" implement g:netrw_hide for tree listings (uses g:netrw_list_hide) 7278if g: netrw_hide == 1 7279" hide given patterns 7280let listhide = split ( g: netrw_list_hide , ',' ) 7281for pat in listhide 7282call filter ( w: netrw_treedict [ dir ], { _ , v -> v !~# pat }) 7283endfor 7284 7285elseif g: netrw_hide == 2 7286" show given patterns (only) 7287let listhide = split ( g: netrw_list_hide , ',' ) 7288let entries = [] 7289for entry in w: netrw_treedict [ dir ] 7290for pat in listhide 7291if entry =~ pat 7292call add ( entries , entry ) 7293break 7294endif 7295endfor 7296endfor 7297let w: netrw_treedict [ dir ] = entries 7298endif 7299if depth != "" 7300" always remove "." and ".." entries when there's depth 7301call filter ( w: netrw_treedict [ dir ], 'v:val !~ "\\.\\.$"' ) 7302call filter ( w: netrw_treedict [ dir ], 'v:val !~ "\\.\\./$"' ) 7303call filter ( w: netrw_treedict [ dir ], 'v:val !~ "\\.$"' ) 7304call filter ( w: netrw_treedict [ dir ], 'v:val !~ "\\./$"' ) 7305endif 7306 7307for entry in w: netrw_treedict [ dir ] 7308if dir =~ '/$' 7309let direntry = substitute ( dir . entry , '[@/]$' , '' , 'e' ) 7310else 7311let direntry = substitute ( dir . '/' . entry , '[@/]$' , '' , 'e' ) 7312endif 7313if entry =~ '/$' && has_key ( w: netrw_treedict , direntry ) 7314NetrwKeepj call s:NetrwTreeDisplay(direntry,depth) 7315elseif entry =~ '/$' && has_key ( w: netrw_treedict , direntry . '/' ) 7316NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth) 7317elseif entry =~ '@$' && has_key ( w: netrw_treedict , direntry . '@' ) 7318NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth) 7319else 7320sil ! NetrwKeepj call setline(line("$")+1,depth.entry) 7321endif 7322endfor 7323endfunction 7324 7325" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2 7326function s: NetrwRefreshTreeDict ( dir ) 7327if ! exists ( "w:netrw_treedict" ) 7328return 7329endif 7330 7331for entry in w: netrw_treedict [ a: dir ] 7332let direntry = substitute ( a: dir . '/' . entry , '[@/]$' , '' , 'e' ) 7333 7334if entry =~ '/$' && has_key ( w: netrw_treedict , direntry ) 7335NetrwKeepj call s:NetrwRefreshTreeDict(direntry) 7336let filelist = s: NetrwLocalListingList ( direntry , 0 ) 7337let w: netrw_treedict [ direntry ] = sort ( filelist ) 7338 7339elseif entry =~ '/$' && has_key ( w: netrw_treedict , direntry . '/' ) 7340NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/') 7341let filelist = s: NetrwLocalListingList ( direntry . '/' , 0 ) 7342let w: netrw_treedict [ direntry ] = sort ( filelist ) 7343 7344elseif entry =~ '@$' && has_key ( w: netrw_treedict , direntry . '@' ) 7345NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/') 7346let liststar = netrw#fs#Glob ( direntry . '/' , '*' , 1 ) 7347let listdotstar = netrw#fs#Glob ( direntry . '/' , '.*' , 1 ) 7348 7349else 7350endif 7351endfor 7352endfunction 7353 7354" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2 7355" Called by s:PerformListing() 7356function s: NetrwTreeListing ( dirname ) 7357if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 7358 7359" update the treetop 7360if ! exists ( "w:netrw_treetop" ) 7361let w: netrw_treetop = a: dirname 7362let s: netrw_treetop = w: netrw_treetop 7363" use \V in case the directory contains specials chars like '$' or '~' 7364elseif ( w: netrw_treetop =~ ( '^' . '\V' . a: dirname ) 7365\ && strdisplaywidth ( a: dirname ) < strdisplaywidth ( w: netrw_treetop )) 7366\ || a: dirname !~ ( '^' . '\V' . w: netrw_treetop ) 7367let w: netrw_treetop = a: dirname 7368let s: netrw_treetop = w: netrw_treetop 7369endif 7370if exists ( "w:netrw_treetop" ) 7371let s: netrw_treetop = w: netrw_treetop 7372else 7373let w: netrw_treetop = getcwd () 7374let s: netrw_treetop = w: netrw_treetop 7375endif 7376 7377if ! exists ( "w:netrw_treedict" ) 7378" insure that we have a treedict, albeit empty 7379let w: netrw_treedict = {} 7380endif 7381 7382" update the dictionary for the current directory 7383exe "sil! NetrwKeepj keepp " . w: netrw_bannercnt . ',$g@^\.\.\=/$@d _' 7384let w: netrw_treedict [ a: dirname ] = getline ( w: netrw_bannercnt , line ( "$" )) 7385exe "sil! NetrwKeepj " . w: netrw_bannercnt . ",$d _" 7386 7387" if past banner, record word 7388if exists ( "w:netrw_bannercnt" ) && line ( "." ) > w: netrw_bannercnt 7389let fname = expand ( "<cword>" ) 7390else 7391let fname = "" 7392endif 7393 7394" display from treetop on down 7395NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"") 7396 7397" remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed) 7398while getline ( 1 ) =~ '^\s*$' && byte2line ( 1 ) > 0 73991 d 7400endwhile 7401 7402exe "setl " . g: netrw_bufsettings 7403 7404return 7405endif 7406endfunction 7407 7408" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2 7409" Normally, treetop is w:netrw_treetop, but a 7410" user of the function ( netrw#SetTreetop() ) 7411" wipes that out prior to calling this function 7412function s: NetrwTreePath ( treetop ) 7413if line ( "." ) < w: netrw_bannercnt + 2 7414let treedir = a: treetop 7415if treedir !~ '/$' 7416let treedir = treedir . '/' 7417endif 7418return treedir 7419endif 7420 7421let svpos = winsaveview () 7422let depth = substitute ( getline ( '.' ), '^\(\%(' . s: treedepthstring . '\)*\)[^' . s: treedepthstring . '].\{-}$' , '\1' , 'e' ) 7423let depth = substitute ( depth , '^' . s: treedepthstring , '' , '' ) 7424let curline = getline ( '.' ) 7425if curline =~ '/$' 7426let treedir = substitute ( curline , '^\%(' . s: treedepthstring . '\)*\([^' . s: treedepthstring . '].\{-}\)$' , '\1' , 'e' ) 7427elseif curline =~ '@\s\+-->' 7428let treedir = substitute ( curline , '^\%(' . s: treedepthstring . '\)*\([^' . s: treedepthstring . '].\{-}\)$' , '\1' , 'e' ) 7429let treedir = substitute ( treedir , '@\s\+-->.*$' , '' , 'e' ) 7430else 7431let treedir = "" 7432endif 7433" construct treedir by searching backwards at correct depth 7434while depth != "" && search ( '^' . depth . '[^' . s: treedepthstring . '].\{-}/$' , 'bW' ) 7435let dirname = substitute ( getline ( '.' ), '^\(' . s: treedepthstring . '\)*' , '' , 'e' ) 7436let treedir = dirname . treedir 7437let depth = substitute ( depth , '^' . s: treedepthstring , '' , '' ) 7438endwhile 7439if a: treetop =~ '/$' 7440let treedir = a: treetop . treedir 7441else 7442let treedir = a: treetop . '/' . treedir 7443endif 7444let treedir = substitute ( treedir , '//$' , '/' , '' ) 7445call winrestview ( svpos ) 7446return treedir 7447endfunction 7448 7449" s:NetrwWideListing: {{{2 7450function s: NetrwWideListing () 7451 7452if w: netrw_liststyle == s: WIDELIST 7453" look for longest filename (cpf=characters per filename) 7454" cpf: characters per filename 7455" fpl: filenames per line 7456" fpc: filenames per column 7457setl ma noro 7458let dict = {} 7459" save the unnamed register and register 0-9 and a 7460let dict . a = [ getreg ( 'a' ), getregtype ( 'a' )] 7461for i in range ( 0 , 9 ) 7462let dict [ i ] = [ getreg ( i ), getregtype ( i )] 7463endfor 7464let dict . unnamed = [ getreg ( '' ), getregtype ( '' )] 7465let b: netrw_cpf = 0 7466if line ( "$" ) >= w: netrw_bannercnt 7467" determine the maximum filename size; use that to set cpf 7468exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' 7469NetrwKeepj call histdel("/",-1) 7470else 7471" restore stored registers 7472call s: RestoreRegister ( dict ) 7473return 7474endif 7475" allow for two spaces to separate columns 7476let b: netrw_cpf = b: netrw_cpf + 2 7477 7478" determine qty files per line (fpl) 7479let w: netrw_fpl = winwidth ( 0 ) / b: netrw_cpf 7480if w: netrw_fpl <= 0 7481let w: netrw_fpl = 1 7482endif 7483 7484" make wide display 7485" fpc: files per column of wide listing 7486exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$s/^.*$/\=escape(printf("%-' . b: netrw_cpf . 'S",submatch(0)),"\\")/' 7487NetrwKeepj call histdel("/",-1) 7488let fpc = ( line ( "$" ) - w: netrw_bannercnt + w: netrw_fpl ) / w: netrw_fpl 7489let newcolstart = w: netrw_bannercnt + fpc 7490let newcolend = newcolstart + fpc - 1 7491if ! has ( 'nvim' ) && has ( "clipboard" ) && g: netrw_clipboard 7492sil ! let keepregstar = @* 7493sil ! let keepregplus = @+ 7494endif 7495while line ( "$" ) >= newcolstart 7496if newcolend > line ( "$" ) | let newcolend = line ( "$" ) | endif 7497let newcolqty = newcolend - newcolstart 7498exe newcolstart 7499" COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @* 7500if newcolqty == 0 7501exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax" . w: netrw_bannercnt . "G$\"ap" 7502else 7503exe "sil! NetrwKeepj norm! 0\<c-v>" . newcolqty . 'j$h"ax' . w: netrw_bannercnt . 'G$"ap' 7504endif 7505exe "sil! NetrwKeepj " . newcolstart . ',' . newcolend . 'd _' 7506exe 'sil! NetrwKeepj ' . w: netrw_bannercnt 7507endwhile 7508if ! has ( 'nvim' ) && has ( "clipboard" ) 7509if @* != keepregstar | sil ! let @* = keepregstar | endif 7510if @+ != keepregplus | sil ! let @+ = keepregplus | endif 7511endif 7512exe "sil! NetrwKeepj " . w: netrw_bannercnt . ',$s/\s\+$//e' 7513NetrwKeepj call histdel("/",-1) 7514exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')' . "\<cr>" 7515exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')' . "\<cr>" 7516exe "setl " . g: netrw_bufsettings 7517call s: RestoreRegister ( dict ) 7518return 7519else 7520if hasmapto ( "w" , "n" ) 7521sil ! nunmap <buffer> w 7522endif 7523if hasmapto ( "b" , "n" ) 7524sil ! nunmap <buffer> b 7525endif 7526endif 7527endfunction 7528 7529" s:PerformListing: {{{2 7530function s: PerformListing ( islocal ) 7531sil ! NetrwKeepj %d _ 7532" call DechoBuf(bufnr("%")) 7533 7534" set up syntax highlighting {{{3 7535sil ! setl ft = netrw 7536 7537NetrwKeepj call s:NetrwOptionsSafe(a:islocal) 7538setl noro ma 7539 7540 7541if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treedict" ) 7542" force a refresh for tree listings 7543sil ! NetrwKeepj %d _ 7544endif 7545 7546" save current directory on directory history list 7547NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir) 7548 7549" Set up the banner {{{3 7550if g: netrw_banner 7551NetrwKeepj call setline(1,'" ============================================================================') 7552if exists ( "g:netrw_pchk" ) 7553" this undocumented option allows pchk to run with different versions of netrw without causing spurious 7554" failure detections. 7555NetrwKeepj call setline(2,'" Netrw Directory Listing') 7556else 7557NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.' )') 7558endif 7559if exists ( "g:netrw_pchk" ) 7560let curdir = substitute ( b: netrw_curdir , expand ( "$HOME" ), '~' , '' ) 7561else 7562let curdir = b: netrw_curdir 7563endif 7564if exists ( "g:netrw_bannerbackslash" ) && g: netrw_bannerbackslash 7565NetrwKeepj call setline(3,'" '.substitute(curdir,' /','\\','g')) 7566else 7567NetrwKeepj call setline(3,'" '.curdir) 7568endif 7569let w: netrw_bannercnt = 3 7570NetrwKeepj exe "sil! NetrwKeepj " .w:netrw_bannercnt 7571else 7572NetrwKeepj 1 7573let w: netrw_bannercnt = 1 7574endif 7575 7576" construct sortby string: [name|time|size|exten] [reversed] 7577let sortby = g: netrw_sort_by 7578if g: netrw_sort_direction =~# "^r" 7579let sortby = sortby . " reversed" 7580endif 7581 7582" Sorted by... {{{3 7583if g: netrw_banner 7584if g: netrw_sort_by =~# "^n" 7585" sorted by name (also includes the sorting sequence in the banner) 7586NetrwKeepj put ='\" Sorted by '.sortby 7587NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence 7588let w: netrw_bannercnt = w: netrw_bannercnt + 2 7589else 7590" sorted by time, size, exten 7591NetrwKeepj put ='\" Sorted by '.sortby 7592let w: netrw_bannercnt = w: netrw_bannercnt + 1 7593endif 7594exe "sil! NetrwKeepj " . w: netrw_bannercnt 7595endif 7596 7597" show copy/move target, if any {{{3 7598if g: netrw_banner 7599if exists ( "s:netrwmftgt" ) && exists ( "s:netrwmftgt_islocal" ) 7600NetrwKeepj put ='' 7601if s: netrwmftgt_islocal 7602sil ! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)') 7603else 7604sil ! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)') 7605endif 7606let w: netrw_bannercnt = w: netrw_bannercnt + 1 7607else 7608endif 7609exe "sil! NetrwKeepj " . w: netrw_bannercnt 7610endif 7611 7612" Hiding... -or- Showing... {{{3 7613if g: netrw_banner 7614if g: netrw_list_hide != "" && g: netrw_hide 7615if g: netrw_hide == 1 7616NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide 7617else 7618NetrwKeepj put ='\" Showing: '.g:netrw_list_hide 7619endif 7620let w: netrw_bannercnt = w: netrw_bannercnt + 1 7621endif 7622exe "NetrwKeepj " . w: netrw_bannercnt 7623 7624let quickhelp = g: netrw_quickhelp % len ( s: QuickHelp ) 7625NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp] 7626NetrwKeepj put ='\" ==============================================================================' 7627let w: netrw_bannercnt = w: netrw_bannercnt + 2 7628endif 7629 7630" bannercnt should index the line just after the banner 7631if g: netrw_banner 7632let w: netrw_bannercnt = w: netrw_bannercnt + 1 7633exe "sil! NetrwKeepj " . w: netrw_bannercnt 7634endif 7635 7636" get list of files 7637if a: islocal 7638let filelist = s: NetrwLocalListingList ( b: netrw_curdir , 1 ) 7639call append ( w: netrw_bannercnt - 1 , filelist ) 7640silent ! NetrwKeepj g/^$/d 7641silent ! NetrwKeepj %s/\r$//e 7642execute printf ( "setl ts=%d" , g: netrw_maxfilenamelen + 1 ) 7643else " remote 7644NetrwKeepj let badresult= s:NetrwRemoteListing() 7645if badresult 7646return 7647endif 7648endif 7649 7650" manipulate the directory listing (hide, sort) {{{3 7651if ! exists ( "w:netrw_bannercnt" ) 7652let w: netrw_bannercnt = 0 7653endif 7654 7655if ! g: netrw_banner || line ( "$" ) >= w: netrw_bannercnt 7656if g: netrw_hide && g: netrw_list_hide != "" 7657NetrwKeepj call s:NetrwListHide() 7658endif 7659if ! g: netrw_banner || line ( "$" ) >= w: netrw_bannercnt 7660 7661if g: netrw_sort_by =~# "^n" 7662" sort by name 7663NetrwKeepj call s:NetrwSetSort() 7664 7665if ! g: netrw_banner || w: netrw_bannercnt < line ( "$" ) 7666if g: netrw_sort_direction =~# 'n' 7667" name: sort by name of file 7668exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$sort' . ' ' . g: netrw_sort_options 7669else 7670" reverse direction sorting 7671exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$sort!' . ' ' . g: netrw_sort_options 7672endif 7673endif 7674 7675" remove priority pattern prefix 7676exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\d\{3}' . g: netrw_sepchr . '//e' 7677NetrwKeepj call histdel("/",-1) 7678 7679elseif g: netrw_sort_by =~# "^ext" 7680" exten: sort by extension 7681" The histdel(...,-1) calls remove the last search from the search history 7682exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$g+/+s/^/001' . g: netrw_sepchr . '/' 7683NetrwKeepj call histdel("/",-1) 7684exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$v+[./]+s/^/002' . g: netrw_sepchr . '/' 7685NetrwKeepj call histdel("/",-1) 7686exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$v+[' . g: netrw_sepchr . '/]+s/^\(.*\.\)\(.\{-\}\)$/\2' . g: netrw_sepchr . '&/e' 7687NetrwKeepj call histdel("/",-1) 7688if ! g: netrw_banner || w: netrw_bannercnt < line ( "$" ) 7689if g: netrw_sort_direction =~# 'n' 7690" normal direction sorting 7691exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$sort' . ' ' . g: netrw_sort_options 7692else 7693" reverse direction sorting 7694exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$sort!' . ' ' . g: netrw_sort_options 7695endif 7696endif 7697exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s/^.\{-}' . g: netrw_sepchr . '//e' 7698NetrwKeepj call histdel("/",-1) 7699 7700elseif a: islocal 7701if ! g: netrw_banner || w: netrw_bannercnt < line ( "$" ) 7702if g: netrw_sort_direction =~# 'n' 7703exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$sort' . ' ' . g: netrw_sort_options 7704else 7705exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$sort!' . ' ' . g: netrw_sort_options 7706endif 7707exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\d\{-}\///e' 7708NetrwKeepj call histdel("/",-1) 7709endif 7710endif 7711 7712elseif g: netrw_sort_direction =~# 'r' 7713if ! g: netrw_banner || w: netrw_bannercnt < line ( '$' ) 7714exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$g/^/m ' . w: netrw_bannercnt 7715call histdel ( "/" , -1 ) 7716endif 7717endif 7718endif 7719 7720" convert to wide/tree listing {{{3 7721NetrwKeepj call s:NetrwWideListing() 7722NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir) 7723 7724" resolve symbolic links if local and (thin or tree) 7725if a: islocal && ( w: netrw_liststyle == s: THINLIST || ( exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST )) 7726sil ! keepp g/@$/call s:ShowLink() 7727endif 7728 7729if exists ( "w:netrw_bannercnt" ) && ( line ( "$" ) >= w: netrw_bannercnt || ! g: netrw_banner ) 7730" place cursor on the top-left corner of the file listing 7731exe 'sil! ' . w: netrw_bannercnt 7732sil ! NetrwKeepj norm! 0 7733else 7734endif 7735 7736" record previous current directory 7737let w: netrw_prvdir = b: netrw_curdir 7738 7739" save certain window-oriented variables into buffer-oriented variables {{{3 7740NetrwKeepj call s:SetBufWinVars() 7741NetrwKeepj call s:NetrwOptionsRestore("w:") 7742 7743" set display to netrw display settings 7744exe "setl " . g: netrw_bufsettings 7745if g: netrw_liststyle == s: LONGLIST 7746exe "setl ts=" . ( g: netrw_maxfilenamelen + 1 ) 7747endif 7748" call DechoBuf(bufnr("%")) 7749 7750if exists ( "s:treecurpos" ) 7751NetrwKeepj call winrestview(s:treecurpos) 7752unlet s: treecurpos 7753endif 7754 7755endfunction 7756 7757" s:SetupNetrwStatusLine: {{{2 7758function s: SetupNetrwStatusLine ( statline ) 7759 7760if ! exists ( "s:netrw_setup_statline" ) 7761let s: netrw_setup_statline = 1 7762 7763if ! exists ( "s:netrw_users_stl" ) 7764let s: netrw_users_stl = & stl 7765endif 7766if ! exists ( "s:netrw_users_ls" ) 7767let s: netrw_users_ls = & laststatus 7768endif 7769 7770" set up User9 highlighting as needed 7771let dict = {} 7772let dict . a = [ getreg ( 'a' ), getregtype ( 'a' )] 7773redir @a 7774try 7775hi User9 7776catch /^Vim\%((\a\{3,})\)\=:E411/ 7777if & bg == "dark" 7778hi User9 ctermfg = yellow ctermbg = blue guifg = yellow guibg = blue 7779else 7780hi User9 ctermbg = yellow ctermfg = blue guibg = yellow guifg = blue 7781endif 7782endtry 7783redir END 7784call s: RestoreRegister ( dict ) 7785endif 7786 7787" set up status line (may use User9 highlighting) 7788" insure that windows have a statusline 7789" make sure statusline is displayed 7790let & l: stl = a: statline 7791setl laststatus = 2 7792redraw 7793 7794endfunction 7795 7796" Remote Directory Browsing Support: {{{1 7797 7798" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2 7799" This function assumes that a long listing will be received. Size, time, 7800" and reverse sorts will be requested of the server but not otherwise 7801" enforced here. 7802function s: NetrwRemoteFtpCmd ( path , listcmd ) 7803" sanity check: {{{3 7804if ! exists ( "w:netrw_method" ) 7805if exists ( "b:netrw_method" ) 7806let w: netrw_method = b: netrw_method 7807else 7808call netrw#msg#Notify ( 'ERROR' , '(s:NetrwRemoteFtpCmd) internal netrw error' ) 7809return 7810endif 7811endif 7812 7813" WinXX ftp uses unix style input, so set ff to unix " {{{3 7814let ffkeep = & ff 7815setl ma ff = unix noro 7816 7817" clear off any older non-banner lines " {{{3 7818" note that w:netrw_bannercnt indexes the line after the banner 7819exe "sil! NetrwKeepj " . w: netrw_bannercnt . ",$d _" 7820 7821"......................................... 7822if w: netrw_method == 2 || w: netrw_method == 5 " {{{3 7823" ftp + <.netrc>: Method #2 7824if a: path != "" 7825NetrwKeepj put ='cd \"'.a:path.'\"' 7826endif 7827if exists ( "g:netrw_ftpextracmd" ) 7828NetrwKeepj put =g:netrw_ftpextracmd 7829endif 7830NetrwKeepj call setline(line("$")+1,a:listcmd) 7831if exists ( "g:netrw_port" ) && g: netrw_port != "" 7832exe 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 ) 7833else 7834exe s: netrw_silentxfer . " NetrwKeepj " . w: netrw_bannercnt . ",$!" . s: netrw_ftp_cmd . " -i " . netrw#os#Escape ( g: netrw_machine , 1 ) 7835endif 7836 7837"......................................... 7838elseif w: netrw_method == 3 " {{{3 7839" ftp + machine,id,passwd,filename: Method #3 7840setl ff = unix 7841if exists ( "g:netrw_port" ) && g: netrw_port != "" 7842NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port 7843else 7844NetrwKeepj put ='open '.g:netrw_machine 7845endif 7846 7847" handle userid and password 7848let host = substitute ( g: netrw_machine , '\..*$' , '' , '' ) 7849if exists ( "s:netrw_hup" ) && exists ( "s:netrw_hup[host]" ) 7850call netrw#NetUserPass ( "ftp:" . host ) 7851endif 7852if exists ( "g:netrw_uid" ) && g: netrw_uid != "" 7853if exists ( "g:netrw_ftp" ) && g: netrw_ftp == 1 7854NetrwKeepj put =g:netrw_uid 7855if exists ( "s:netrw_passwd" ) && s: netrw_passwd != "" 7856NetrwKeepj put ='\"'.s:netrw_passwd.'\"' 7857endif 7858elseif exists ( "s:netrw_passwd" ) 7859NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"' 7860endif 7861endif 7862 7863if a: path != "" 7864NetrwKeepj put ='cd \"'.a:path.'\"' 7865endif 7866if exists ( "g:netrw_ftpextracmd" ) 7867NetrwKeepj put =g:netrw_ftpextracmd 7868endif 7869NetrwKeepj call setline(line("$")+1,a:listcmd) 7870 7871" perform ftp: 7872" -i : turns off interactive prompting from ftp 7873" -n unix : DON'T use <.netrc>, even though it exists 7874" -n win32: quit being obnoxious about password 7875if exists ( "w:netrw_bannercnt" ) 7876call netrw#os#Execute ( s: netrw_silentxfer . w: netrw_bannercnt . ",$!" . s: netrw_ftp_cmd . " " . g: netrw_ftp_options ) 7877endif 7878 7879"......................................... 7880elseif w: netrw_method == 9 " {{{3 7881" sftp username@machine: Method #9 7882" s:netrw_sftp_cmd 7883setl ff = unix 7884 7885" restore settings 7886let & l: ff = ffkeep 7887return 7888 7889"......................................... 7890else " {{{3 7891call netrw#msg#Notify ( 'WARNING' , printf ( 'unable to comply with your request<%s>' , bufname ( "%" ))) 7892endif 7893 7894" cleanup for Windows " {{{3 7895if has ( "win32" ) 7896sil ! NetrwKeepj %s/\r$//e 7897NetrwKeepj call histdel("/",-1) 7898endif 7899if a: listcmd == "dir" 7900" infer directory/link based on the file permission string 7901sil ! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e 7902sil ! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e 7903NetrwKeepj call histdel("/",-1) 7904NetrwKeepj call histdel("/",-1) 7905if w: netrw_liststyle == s: THINLIST || w: netrw_liststyle == s: WIDELIST || ( exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST ) 7906exe "sil! NetrwKeepj " . w: netrw_bannercnt . ',$s/^\%(\S\+\s\+\)\{8}//e' 7907NetrwKeepj call histdel("/",-1) 7908endif 7909endif 7910 7911" ftp's listing doesn't seem to include ./ or ../ " {{{3 7912if ! search ( '^\.\/$\|\s\.\/$' , 'wn' ) 7913exe 'NetrwKeepj ' . w: netrw_bannercnt 7914NetrwKeepj put ='./' 7915endif 7916if ! search ( '^\.\.\/$\|\s\.\.\/$' , 'wn' ) 7917exe 'NetrwKeepj ' . w: netrw_bannercnt 7918NetrwKeepj put ='../' 7919endif 7920 7921" restore settings " {{{3 7922let & l: ff = ffkeep 7923endfunction 7924 7925" s:NetrwRemoteListing: {{{2 7926function s: NetrwRemoteListing () 7927 7928if ! exists ( "w:netrw_bannercnt" ) && exists ( "s:bannercnt" ) 7929let w: netrw_bannercnt = s: bannercnt 7930endif 7931if ! exists ( "w:netrw_bannercnt" ) && exists ( "b:bannercnt" ) 7932let w: netrw_bannercnt = b: bannercnt 7933endif 7934 7935call s: RemotePathAnalysis ( b: netrw_curdir ) 7936 7937" sanity check: 7938if exists ( "b:netrw_method" ) && b: netrw_method =~ '[235]' 7939if ! executable ( "ftp" ) 7940call netrw#msg#Notify ( 'ERROR' , "this system doesn't support remote directory listing via ftp" ) 7941call s: NetrwOptionsRestore ( "w:" ) 7942return -1 7943endif 7944 7945elseif ! exists ( "g:netrw_list_cmd" ) || g: netrw_list_cmd == '' 7946if g: netrw_list_cmd == "" 7947call netrw#msg#Notify ( 'ERROR' , printf ( 'your g:netrw_list_cmd is empty; perhaps %s is not executable on your system' , g: netrw_ssh_cmd )) 7948else 7949call netrw#msg#Notify ( 'ERROR' , "this system doesn't support remote directory listing via " . g: netrw_list_cmd ) 7950endif 7951 7952NetrwKeepj call s:NetrwOptionsRestore("w:") 7953return -1 7954endif " (remote handling sanity check) 7955 7956if exists ( "b:netrw_method" ) 7957let w: netrw_method = b: netrw_method 7958endif 7959 7960if s: method == "ftp" 7961" use ftp to get remote file listing {{{3 7962let s: method = "ftp" 7963let listcmd = g: netrw_ftp_list_cmd 7964if g: netrw_sort_by =~# '^t' 7965let listcmd = g: netrw_ftp_timelist_cmd 7966elseif g: netrw_sort_by =~# '^s' 7967let listcmd = g: netrw_ftp_sizelist_cmd 7968endif 7969call s: NetrwRemoteFtpCmd ( s: path , listcmd ) 7970 7971" report on missing file or directory messages 7972if search ( '[Nn]o such file or directory\|Failed to change directory' ) 7973let mesg = getline ( "." ) 7974if exists ( "w:netrw_bannercnt" ) 7975setl ma 7976exe w: netrw_bannercnt . ",$d _" 7977setl noma 7978endif 7979NetrwKeepj call s:NetrwOptionsRestore("w:") 7980call netrw#msg#Notify ( 'WARNING' , mesg ) 7981return -1 7982endif 7983 7984if w: netrw_liststyle == s: THINLIST || w: netrw_liststyle == s: WIDELIST || ( exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST ) 7985" shorten the listing 7986exe "sil! keepalt NetrwKeepj " . w: netrw_bannercnt 7987 7988" cleanup 7989if g: netrw_ftp_browse_reject != "" 7990exe "sil! keepalt NetrwKeepj g/" . g: netrw_ftp_browse_reject . "/NetrwKeepj d" 7991NetrwKeepj call histdel("/",-1) 7992endif 7993sil ! NetrwKeepj %s/\r$//e 7994NetrwKeepj call histdel("/",-1) 7995 7996" if there's no ../ listed, then put ../ in 7997let line1 = line ( "." ) 7998exe "sil! NetrwKeepj " . w: netrw_bannercnt 7999let line2 = search ( '\.\.\/\%(\s\|$\)' , 'cnW' ) 8000if line2 == 0 8001sil ! NetrwKeepj put='../' 8002endif 8003exe "sil! NetrwKeepj " . line1 8004sil ! NetrwKeepj norm! 0 8005 8006if search ( '^\d\{2}-\d\{2}-\d\{2}\s' , 'n' ) " M$ ftp site cleanup 8007exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//' 8008NetrwKeepj call histdel("/",-1) 8009else " normal ftp cleanup 8010exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e' 8011exe "sil! NetrwKeepj " . w: netrw_bannercnt . ',$g/ -> /s# -> .*/$#/#e' 8012exe "sil! NetrwKeepj " . w: netrw_bannercnt . ',$g/ -> /s# -> .*$#/#e' 8013NetrwKeepj call histdel("/",-1) 8014NetrwKeepj call histdel("/",-1) 8015NetrwKeepj call histdel("/",-1) 8016endif 8017endif 8018 8019else 8020" use ssh to get remote file listing {{{3 8021let listcmd = s: MakeSshCmd ( g: netrw_list_cmd ) 8022if g: netrw_scp_cmd =~ '^pscp' 8023exe "NetrwKeepj r! " . listcmd . netrw#os#Escape ( s: path , 1 ) 8024" remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like 8025sil ! NetrwKeepj g/^Listing directory/NetrwKeepj d 8026sil ! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e 8027sil ! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e 8028NetrwKeepj call histdel("/",-1) 8029NetrwKeepj call histdel("/",-1) 8030NetrwKeepj call histdel("/",-1) 8031if g: netrw_liststyle != s: LONGLIST 8032sil ! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e 8033NetrwKeepj call histdel("/",-1) 8034endif 8035else 8036if s: path == "" 8037exe "NetrwKeepj keepalt r! " . listcmd 8038else 8039exe "NetrwKeepj keepalt r! " . listcmd . ' ' . netrw#os#Escape ( fnameescape ( s: path ), 1 ) 8040endif 8041endif 8042 8043" cleanup 8044if g: netrw_ssh_browse_reject != "" 8045exe "sil! g/" . g: netrw_ssh_browse_reject . "/NetrwKeepj d" 8046NetrwKeepj call histdel("/",-1) 8047endif 8048endif 8049 8050if w: netrw_liststyle == s: LONGLIST 8051" do a long listing; these substitutions need to be done prior to sorting {{{3 8052 8053if s: method == "ftp" 8054" cleanup 8055exe "sil! NetrwKeepj " . w: netrw_bannercnt 8056while getline ( '.' ) =~# g: netrw_ftp_browse_reject 8057sil ! NetrwKeepj d 8058endwhile 8059" if there's no ../ listed, then put ../ in 8060let line1 = line ( "." ) 8061sil ! NetrwKeepj 1 8062sil ! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W') 8063let line2 = line ( "." ) 8064if line2 == 0 8065if b: netrw_curdir != '/' 8066exe 'sil! NetrwKeepj ' . w: netrw_bannercnt . "put='../'" 8067endif 8068endif 8069exe "sil! NetrwKeepj " . line1 8070sil ! NetrwKeepj norm! 0 8071endif 8072 8073if search ( '^\d\{2}-\d\{2}-\d\{2}\s' , 'n' ) " M$ ftp site cleanup 8074exe '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/' 8075elseif exists ( "w:netrw_bannercnt" ) && w: netrw_bannercnt <= line ( "$" ) 8076exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$s/ -> .*$//e' 8077exe 'sil NetrwKeepj ' . w: netrw_bannercnt . ',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e' 8078exe 'sil NetrwKeepj ' . w: netrw_bannercnt 8079NetrwKeepj call histdel("/",-1) 8080NetrwKeepj call histdel("/",-1) 8081NetrwKeepj call histdel("/",-1) 8082endif 8083endif 8084 8085 8086return 0 8087endfunction 8088 8089" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2 8090function s: NetrwRemoteRm ( usrhost , path ) range 8091let svpos = winsaveview () 8092 8093let all = 0 8094if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 8095" remove all marked files 8096for fname in s: netrwmarkfilelist_ { bufnr ( "%" )} 8097let ok = s: NetrwRemoteRmFile ( a: path , fname , all ) 8098if ok =~# 'q\%[uit]' 8099break 8100elseif ok =~# 'a\%[ll]' 8101let all = 1 8102endif 8103endfor 8104call s: NetrwUnmarkList ( bufnr ( "%" ), b: netrw_curdir ) 8105 8106else 8107" remove files specified by range 8108 8109" preparation for removing multiple files/directories 8110let keepsol = & l: sol 8111setl nosol 8112let ctr = a: firstline 8113 8114" remove multiple files and directories 8115while ctr <= a: lastline 8116exe "NetrwKeepj " . ctr 8117let ok = s: NetrwRemoteRmFile ( a: path , s: NetrwGetWord (), all ) 8118if ok =~# 'q\%[uit]' 8119break 8120elseif ok =~# 'a\%[ll]' 8121let all = 1 8122endif 8123let ctr = ctr + 1 8124endwhile 8125let & l: sol = keepsol 8126endif 8127 8128" refresh the (remote) directory listing 8129NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 8130NetrwKeepj call winrestview(svpos) 8131endfunction 8132 8133" s:NetrwRemoteRmFile: {{{2 8134function s: NetrwRemoteRmFile ( path , rmfile , all ) 8135 8136let all = a: all 8137let ok = "" 8138 8139if a: rmfile !~ '^"' && ( a: rmfile =~ '@$' || a: rmfile !~ '[\/]$' ) 8140" attempt to remove file 8141if ! all 8142echohl Statement 8143call inputsave () 8144let ok = input ( "Confirm deletion of file<" . a: rmfile . "> " , "[{y(es)},n(o),a(ll),q(uit)] " ) 8145call inputrestore () 8146echohl NONE 8147if ok == "" 8148let ok = "no" 8149endif 8150let ok = substitute ( ok , '\[{y(es)},n(o),a(ll),q(uit)]\s*' , '' , 'e' ) 8151if ok =~# 'a\%[ll]' 8152let all = 1 8153endif 8154endif 8155 8156if all || ok =~# 'y\%[es]' || ok == "" 8157if exists ( "w:netrw_method" ) && ( w: netrw_method == 2 || w: netrw_method == 3 ) 8158let path = a: path 8159if path =~ '^\a\{3,}://' 8160let path = substitute ( path , '^\a\{3,}://[^/]\+/' , '' , '' ) 8161endif 8162sil ! NetrwKeepj .,$d _ 8163call s: NetrwRemoteFtpCmd ( path , "delete " . '"' . a: rmfile . '"' ) 8164else 8165let netrw_rm_cmd = s: MakeSshCmd ( g: netrw_rm_cmd ) 8166if ! exists ( "b:netrw_curdir" ) 8167call netrw#msg#Notify ( 'ERROR' , "for some reason b:netrw_curdir doesn't exist!" ) 8168let ok = "q" 8169else 8170let remotedir = substitute ( b: netrw_curdir , '^.\{-}//[^/]\+/\(.*\)$' , '\1' , '' ) 8171if remotedir != "" 8172let netrw_rm_cmd = netrw_rm_cmd . " " . netrw#os#Escape ( fnameescape ( remotedir . a: rmfile )) 8173else 8174let netrw_rm_cmd = netrw_rm_cmd . " " . netrw#os#Escape ( fnameescape ( a: rmfile )) 8175endif 8176let ret = system ( netrw_rm_cmd ) 8177if v: shell_error != 0 8178if exists ( "b:netrw_curdir" ) && b: netrw_curdir != getcwd () && ! g: netrw_keepdir 8179call 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 )) 8180else 8181call netrw#msg#Notify ( 'WARNING' , printf ( 'cmd<%s> failed' , netrw_rm_cmd )) 8182endif 8183elseif ret != 0 8184call netrw#msg#Notify ( 'WARNING' , printf ( 'cmd<%s> failed' , netrw_rm_cmd )) 8185endif 8186endif 8187endif 8188elseif ok =~# 'q\%[uit]' 8189endif 8190 8191else 8192" attempt to remove directory 8193if ! all 8194call inputsave () 8195let ok = input ( "Confirm deletion of directory<" . a: rmfile . "> " , "[{y(es)},n(o),a(ll),q(uit)] " ) 8196call inputrestore () 8197if ok == "" 8198let ok = "no" 8199endif 8200let ok = substitute ( ok , '\[{y(es)},n(o),a(ll),q(uit)]\s*' , '' , 'e' ) 8201if ok =~# 'a\%[ll]' 8202let all = 1 8203endif 8204endif 8205 8206if all || ok =~# 'y\%[es]' || ok == "" 8207if exists ( "w:netrw_method" ) && ( w: netrw_method == 2 || w: netrw_method == 3 ) 8208NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile) 8209else 8210let rmfile = substitute ( a: path . a: rmfile , '/$' , '' , '' ) 8211let netrw_rmdir_cmd = s: MakeSshCmd ( netrw#fs#WinPath ( g: netrw_rmdir_cmd )) . ' ' . netrw#os#Escape ( netrw#fs#WinPath ( rmfile )) 8212let ret = system ( netrw_rmdir_cmd ) 8213 8214if v: shell_error != 0 8215let netrw_rmf_cmd = s: MakeSshCmd ( netrw#fs#WinPath ( g: netrw_rmf_cmd )) . ' ' . netrw#os#Escape ( netrw#fs#WinPath ( substitute ( rmfile , '[\/]$' , '' , 'e' ))) 8216let ret = system ( netrw_rmf_cmd ) 8217 8218if v: shell_error != 0 8219call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to remove directory<%s> -- is it empty?' , rmfile )) 8220endif 8221endif 8222endif 8223 8224elseif ok =~# 'q\%[uit]' 8225endif 8226endif 8227 8228return ok 8229endfunction 8230 8231" s:NetrwRemoteRename: rename a remote file or directory {{{2 8232function s: NetrwRemoteRename ( usrhost , path ) range 8233 8234" preparation for removing multiple files/directories 8235let svpos = winsaveview () 8236let ctr = a: firstline 8237let rename_cmd = s: MakeSshCmd ( g: netrw_rename_cmd ) 8238 8239" rename files given by the markfilelist 8240if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 8241for oldname in s: netrwmarkfilelist_ { bufnr ( "%" )} 8242if exists ( "subfrom" ) 8243let newname = substitute ( oldname , subfrom , subto , '' ) 8244else 8245call inputsave () 8246let newname = input ( "Moving " . oldname . " to : " , oldname ) 8247call inputrestore () 8248if newname =~ '^s/' 8249let subfrom = substitute ( newname , '^s/\([^/]*\)/.*/$' , '\1' , '' ) 8250let subto = substitute ( newname , '^s/[^/]*/\(.*\)/$' , '\1' , '' ) 8251let newname = substitute ( oldname , subfrom , subto , '' ) 8252endif 8253endif 8254 8255if exists ( "w:netrw_method" ) && ( w: netrw_method == 2 || w: netrw_method == 3 ) 8256NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname) 8257else 8258let oldname = netrw#os#Escape ( a: path . oldname ) 8259let newname = netrw#os#Escape ( a: path . newname ) 8260let ret = system ( netrw#fs#WinPath ( rename_cmd ) . ' ' . oldname . ' ' . newname ) 8261endif 8262 8263endfor 8264call s: NetrwUnMarkFile ( 1 ) 8265 8266else 8267 8268" attempt to rename files/directories 8269let keepsol = & l: sol 8270setl nosol 8271while ctr <= a: lastline 8272exe "NetrwKeepj " . ctr 8273 8274let oldname = s: NetrwGetWord () 8275 8276call inputsave () 8277let newname = input ( "Moving " . oldname . " to : " , oldname ) 8278call inputrestore () 8279 8280if exists ( "w:netrw_method" ) && ( w: netrw_method == 2 || w: netrw_method == 3 ) 8281call s: NetrwRemoteFtpCmd ( a: path , "rename " . oldname . " " . newname ) 8282else 8283let oldname = netrw#os#Escape ( a: path . oldname ) 8284let newname = netrw#os#Escape ( a: path . newname ) 8285let ret = system ( netrw#fs#WinPath ( rename_cmd ) . ' ' . oldname . ' ' . newname ) 8286endif 8287 8288let ctr = ctr + 1 8289endwhile 8290let & l: sol = keepsol 8291endif 8292 8293" refresh the directory 8294NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0)) 8295NetrwKeepj call winrestview(svpos) 8296endfunction 8297 8298" Local Directory Browsing Support: {{{1 8299 8300" netrw#FileUrlEdit: handles editing file://* files {{{2 8301" Should accept: file://localhost/etc/fstab 8302" file:///etc/fstab 8303" file:///c:/WINDOWS/clock.avi 8304" file:///c|/WINDOWS/clock.avi 8305" file://localhost/c:/WINDOWS/clock.avi 8306" file://localhost/c|/WINDOWS/clock.avi 8307" file://c:/foo.txt 8308" file:///c:/foo.txt 8309" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value 8310function netrw#FileUrlEdit ( fname ) 8311let fname = a: fname 8312if fname =~ '^file://localhost/' 8313let fname = substitute ( fname , '^file://localhost/' , 'file:///' , '' ) 8314endif 8315if has ( "win32" ) 8316if fname =~ '^file:///\=\a[|:]/' 8317let fname = substitute ( fname , '^file:///\=\(\a\)[|:]/' , 'file://\1:/' , '' ) 8318endif 8319endif 8320let fname2396 = netrw#RFC2396 ( fname ) 8321let fname2396e = fnameescape ( fname2396 ) 8322let plainfname = substitute ( fname2396 , 'file://\(.*\)' , '\1' , "" ) 8323if has ( "win32" ) 8324if plainfname =~ '^/\+\a:' 8325let plainfname = substitute ( plainfname , '^/\+\(\a:\)' , '\1' , '' ) 8326endif 8327endif 8328 8329exe "sil doau BufReadPre " . fname2396e 8330exe 'NetrwKeepj keepalt edit ' . fnameescape ( plainfname ) 8331exe 'sil! NetrwKeepj keepalt bdelete ' . fnameescape ( a: fname ) 8332 8333exe "sil doau BufReadPost " . fname2396e 8334endfunction 8335 8336" netrw#LocalBrowseCheck: {{{2 8337function netrw#LocalBrowseCheck ( dirname ) 8338" This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(), 8339" and by <cr> when atop a listed file/directory (via a buffer-local map) 8340" 8341" unfortunate interaction -- split window debugging can't be used here, must use 8342" D-echoRemOn or D-echoTabOn as the BufEnter event triggers 8343" another call to LocalBrowseCheck() when attempts to write 8344" to the DBG buffer are made. 8345" 8346" The &ft == "netrw" test was installed because the BufEnter event 8347" would hit when re-entering netrw windows, creating unexpected 8348" refreshes (and would do so in the middle of NetrwSaveOptions(), too) 8349" getting E930: Cannot use :redir inside execute 8350 8351let ykeep = @@ 8352if isdirectory ( s: NetrwFile ( a: dirname )) 8353 8354if & ft != "netrw" || ( exists ( "b:netrw_curdir" ) && b: netrw_curdir != a: dirname ) || g: netrw_fastbrowse <= 1 8355sil ! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8356 8357elseif & ft == "netrw" && line ( "$" ) == 1 8358sil ! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8359 8360elseif exists ( "s:treeforceredraw" ) 8361unlet s: treeforceredraw 8362sil ! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname) 8363endif 8364return 8365endif 8366 8367" The following code wipes out currently unused netrw buffers 8368" IF g:netrw_fastbrowse is zero (ie. slow browsing selected) 8369" AND IF the listing style is not a tree listing 8370if exists ( "g:netrw_fastbrowse" ) && g: netrw_fastbrowse == 0 && g: netrw_liststyle != s: TREELIST 8371let ibuf = 1 8372let buflast = bufnr ( "$" ) 8373while ibuf <= buflast 8374if bufwinnr ( ibuf ) == -1 && ! empty ( bufname ( ibuf )) && isdirectory ( s: NetrwFile ( bufname ( ibuf ))) 8375exe "sil! keepj keepalt " . ibuf . "bw!" 8376endif 8377let ibuf = ibuf + 1 8378endwhile 8379endif 8380let @@ = ykeep 8381" not a directory, ignore it 8382endfunction 8383 8384" s:LocalBrowseRefresh: this function is called after a user has {{{2 8385" performed any shell command. The idea is to cause all local-browsing 8386" buffers to be refreshed after a user has executed some shell command, 8387" on the chance that s/he removed/created a file/directory with it. 8388function s: LocalBrowseRefresh () 8389" determine which buffers currently reside in a tab 8390if ! exists ( "s:netrw_browselist" ) 8391return 8392endif 8393if ! exists ( "w:netrw_bannercnt" ) 8394return 8395endif 8396if exists ( "s:netrw_events" ) && s: netrw_events == 1 8397" s:LocalFastBrowser gets called (indirectly) from a 8398let s: netrw_events = 2 8399return 8400endif 8401let itab = 1 8402let buftablist = [] 8403let ykeep = @@ 8404while itab <= tabpagenr ( "$" ) 8405let buftablist = buftablist + tabpagebuflist () 8406let itab = itab + 1 8407sil ! tabn 8408endwhile 8409" GO through all buffers on netrw_browselist (ie. just local-netrw buffers): 8410" | refresh any netrw window 8411" | wipe out any non-displaying netrw buffer 8412let curwinid = win_getid ( winnr ()) 8413let ibl = 0 8414for ibuf in s: netrw_browselist 8415if bufwinnr ( ibuf ) == -1 && index ( buftablist , ibuf ) == -1 8416" wipe out any non-displaying netrw buffer 8417" (ibuf not shown in a current window AND 8418" ibuf not in any tab) 8419exe "sil! keepj bd " . fnameescape ( ibuf ) 8420call remove ( s: netrw_browselist , ibl ) 8421continue 8422elseif index ( tabpagebuflist (), ibuf ) != -1 8423" refresh any netrw buffer 8424exe bufwinnr ( ibuf ) . "wincmd w" 8425if getline ( "." ) =~# 'Quick Help' 8426" decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp 8427" (counteracts s:NetrwBrowseChgDir()'s incrementing) 8428let g: netrw_quickhelp = g: netrw_quickhelp - 1 8429endif 8430if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 8431NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop) 8432endif 8433NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8434endif 8435let ibl = ibl + 1 8436endfor 8437call win_gotoid ( curwinid ) 8438let @@ = ykeep 8439endfunction 8440 8441" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2 8442" 8443" g:netrw_ Directory Is 8444" fastbrowse Local Remote 8445" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow) 8446" med 1 D H H=Hiding a buffer implies it may be re-used (fast) 8447" fast 2 H H 8448" 8449" Deleting a buffer means that it will be re-loaded when examined, hence "slow". 8450" Hiding a buffer means that it will be re-used when examined, hence "fast". 8451" (re-using a buffer may not be as accurate) 8452" 8453" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing 8454" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing. 8455" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event. 8456" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored. 8457" =2: autocmds installed (doesn't ignore any FocusGained events) 8458function s: LocalFastBrowser () 8459 8460" initialize browselist, a list of buffer numbers that the local browser has used 8461if ! exists ( "s:netrw_browselist" ) 8462let s: netrw_browselist = [] 8463endif 8464 8465" append current buffer to fastbrowse list 8466if empty ( s: netrw_browselist ) || bufnr ( "%" ) > s: netrw_browselist [ -1 ] 8467call add ( s: netrw_browselist , bufnr ( "%" )) 8468endif 8469 8470" enable autocmd events to handle refreshing/removing local browser buffers 8471" If local browse buffer is currently showing: refresh it 8472" If local browse buffer is currently hidden : wipe it 8473" g:netrw_fastbrowse=0 : slow speed, never re-use directory listing 8474" =1 : medium speed, re-use directory listing for remote only 8475" =2 : fast speed, always re-use directory listing when possible 8476if g: netrw_fastbrowse <= 1 && ! exists ( "#ShellCmdPost" ) && ! exists ( "s:netrw_events" ) 8477let s: netrw_events = 1 8478augroup AuNetrwEvent 8479au ! 8480if has ( "win32" ) 8481au ShellCmdPost * call s: LocalBrowseRefresh () 8482else 8483au ShellCmdPost , FocusGained * call s: LocalBrowseRefresh () 8484endif 8485augroup END 8486 8487" user must have changed fastbrowse to its fast setting, so remove 8488" the associated autocmd events 8489elseif g: netrw_fastbrowse > 1 && exists ( "#ShellCmdPost" ) && exists ( "s:netrw_events" ) 8490unlet s: netrw_events 8491augroup AuNetrwEvent 8492au ! 8493augroup END 8494augroup ! AuNetrwEvent 8495endif 8496endfunction 8497 8498function s: NetrwLocalListingList ( dirname , setmaxfilenamelen ) 8499" get the list of files contained in the current directory 8500let dirname = a: dirname 8501let dirnamelen = strlen ( dirname ) 8502let filelist = map ([ '.' , '..' ] + readdir ( dirname ), 'netrw#fs#PathJoin(dirname, v:val)' ) 8503 8504if g: netrw_cygwin == 0 && has ( "win32" ) 8505elseif index ( filelist , '..' ) == -1 && dirname !~ '/' 8506" include ../ in the glob() entry if its missing 8507let filelist = filelist + [ netrw#fs#ComposePath ( dirname , "../" )] 8508endif 8509 8510if a: setmaxfilenamelen && get ( g: , 'netrw_dynamic_maxfilenamelen' , 0 ) 8511let filelistcopy = map ( deepcopy ( filelist ), 'fnamemodify(v:val, ":t")' ) 8512let g: netrw_maxfilenamelen = max ( map ( filelistcopy , 'len(v:val)' )) + 1 8513endif 8514 8515let resultfilelist = [] 8516for filename in filelist 8517 8518let ftype = getftype ( filename ) 8519if ftype ==# "link" 8520" indicate a symbolic link 8521let pfile = filename . "@" 8522 8523elseif ftype ==# "socket" 8524" indicate a socket 8525let pfile = filename . "=" 8526 8527elseif ftype ==# "fifo" 8528" indicate a fifo 8529let pfile = filename . "|" 8530 8531elseif ftype ==# "dir" 8532" indicate a directory 8533let pfile = filename . "/" 8534 8535elseif exists ( "b:netrw_curdir" ) && b: netrw_curdir !~ '^.*://' && ! isdirectory ( s: NetrwFile ( filename )) 8536if has ( "win32" ) 8537if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$' 8538" indicate an executable 8539let pfile = filename . "*" 8540else 8541" normal file 8542let pfile = filename 8543endif 8544elseif executable ( filename ) 8545" indicate an executable 8546let pfile = filename . "*" 8547else 8548" normal file 8549let pfile = filename 8550endif 8551 8552else 8553" normal file 8554let pfile = filename 8555endif 8556 8557if pfile =~ '//$' 8558let pfile = substitute ( pfile , '//$' , '/' , 'e' ) 8559endif 8560let pfile = strpart ( pfile , dirnamelen ) 8561let pfile = substitute ( pfile , '^[/\\]' , '' , 'e' ) 8562 8563if w: netrw_liststyle == s: LONGLIST 8564let longfile = printf ( "%-" . g: netrw_maxfilenamelen . "S" , pfile ) 8565let sz = getfsize ( filename ) 8566let szlen = 15 - ( strdisplaywidth ( longfile ) - g: netrw_maxfilenamelen ) 8567let szlen = ( szlen > 0 ) ? szlen : 0 8568 8569if g: netrw_sizestyle =~# "[hH]" 8570let sz = s: NetrwHumanReadable ( sz ) 8571endif 8572let fsz = printf ( "%" . szlen . "S" , sz ) 8573let pfile = longfile . " " . fsz . " " . strftime ( g: netrw_timefmt , getftime ( filename )) 8574endif 8575 8576if g: netrw_sort_by =~# "^t" 8577" sort by time (handles time up to 1 quintillion seconds, US) 8578" Decorate listing by prepending a timestamp/ . Sorting will then be done based on time. 8579let t = getftime ( filename ) 8580let ft = printf ( "%018d" , t ) 8581let ftpfile = ft . '/' . pfile 8582let resultfilelist += [ ftpfile ] 8583 8584elseif g: netrw_sort_by =~ "^s" 8585" sort by size (handles file sizes up to 1 quintillion bytes, US) 8586let sz = getfsize ( filename ) 8587let fsz = printf ( "%018d" , sz ) 8588let fszpfile = fsz . '/' . pfile 8589let resultfilelist += [ fszpfile ] 8590 8591else 8592" sort by name 8593let resultfilelist += [ pfile ] 8594endif 8595endfor 8596 8597return resultfilelist 8598endfunction 8599 8600" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2 8601function s: NetrwLocalExecute ( cmd ) 8602let ykeep = @@ 8603" sanity check 8604if ! executable ( a: cmd ) 8605call netrw#msg#Notify ( 'ERROR' , printf ( "the file<%s> is not executable!" , a: cmd )) 8606let @@ = ykeep 8607return 8608endif 8609 8610let optargs = input ( ":!" . a: cmd , "" , "file" ) 8611let result = system ( a: cmd . optargs ) 8612 8613" strip any ansi escape sequences off 8614let result = substitute ( result , "\e\\[[0-9;]*m" , "" , "g" ) 8615 8616" show user the result(s) 8617echomsg result 8618let @@ = ykeep 8619 8620endfunction 8621 8622" s:NetrwLocalRename: rename a local file or directory {{{2 8623function s: NetrwLocalRename ( path ) range 8624 8625if ! exists ( "w:netrw_bannercnt" ) 8626let w: netrw_bannercnt = b: netrw_bannercnt 8627endif 8628 8629" preparation for removing multiple files/directories 8630let ykeep = @@ 8631let ctr = a: firstline 8632let svpos = winsaveview () 8633let all = 0 8634 8635" rename files given by the markfilelist 8636if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 8637for oldname in s: netrwmarkfilelist_ { bufnr ( "%" )} 8638if exists ( "subfrom" ) 8639let newname = substitute ( oldname , subfrom , subto , '' ) 8640else 8641call inputsave () 8642let newname = input ( "Moving " . oldname . " to : " , oldname , "file" ) 8643call inputrestore () 8644if newname =~ '' 8645" two ctrl-x's : ignore all of string preceding the ctrl-x's 8646let newname = substitute ( newname , '^.*' , '' , '' ) 8647elseif newname =~ '' 8648" one ctrl-x : ignore portion of string preceding ctrl-x but after last / 8649let newname = substitute ( newname , '[^/]*' , '' , '' ) 8650endif 8651if newname =~ '^s/' 8652let subfrom = substitute ( newname , '^s/\([^/]*\)/.*/$' , '\1' , '' ) 8653let subto = substitute ( newname , '^s/[^/]*/\(.*\)/$' , '\1' , '' ) 8654let newname = substitute ( oldname , subfrom , subto , '' ) 8655endif 8656endif 8657if ! all && filereadable ( newname ) 8658call inputsave () 8659let response = input ( "File<" . newname . "> already exists; do you want to overwrite it? (y/all/n) " ) 8660call inputrestore () 8661if response == "all" 8662let all = 1 8663elseif response != "y" && response != "yes" 8664" refresh the directory 8665NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8666NetrwKeepj call winrestview(svpos) 8667let @@ = ykeep 8668return 8669endif 8670endif 8671call rename ( oldname , newname ) 8672endfor 8673call s: NetrwUnmarkList ( bufnr ( "%" ), b: netrw_curdir ) 8674 8675else 8676 8677" attempt to rename files/directories 8678while ctr <= a: lastline 8679exe "NetrwKeepj " . ctr 8680 8681" sanity checks 8682if line ( "." ) < w: netrw_bannercnt 8683let ctr = ctr + 1 8684continue 8685endif 8686let curword = s: NetrwGetWord () 8687if curword == "./" || curword == "../" 8688let ctr = ctr + 1 8689continue 8690endif 8691 8692NetrwKeepj norm! 0 8693let reset_ssl = 0 8694if exists ( '+shellslash' ) && !& ssl 8695let reset_ssl = 1 8696set ssl 8697endif 8698" Consistently use / as directory separator 8699let oldname = netrw#fs#ComposePath ( a: path , curword ) 8700if reset_ssl 8701set nossl 8702endif 8703 8704call inputsave () 8705let newname = input ( "Moving " . oldname . " to : " , substitute ( oldname , '/*$' , '' , 'e' )) 8706call inputrestore () 8707 8708call rename ( oldname , newname ) 8709let ctr = ctr + 1 8710endwhile 8711endif 8712 8713" refresh the directory 8714NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0)) 8715NetrwKeepj call winrestview(svpos) 8716let @@ = ykeep 8717endfunction 8718 8719" s:NetrwLocalRm: {{{2 8720function s: NetrwLocalRm ( path ) range 8721if ! exists ( "w:netrw_bannercnt" ) 8722let w: netrw_bannercnt = b: netrw_bannercnt 8723endif 8724 8725" preparation for removing multiple files/directories 8726let ykeep = @@ 8727let ret = 0 8728let all = 0 8729let svpos = winsaveview () 8730 8731if exists ( "s:netrwmarkfilelist_{bufnr('%')}" ) 8732" remove all marked files 8733for fname in s: netrwmarkfilelist_ { bufnr ( "%" )} 8734let ok = s: NetrwLocalRmFile ( a: path , fname , all ) 8735if ok =~# '^a\%[ll]$' 8736let all = 1 8737elseif ok =~# "n\%[o]" 8738break 8739endif 8740endfor 8741call s: NetrwUnMarkFile ( 1 ) 8742 8743else 8744" remove (multiple) files and directories 8745 8746let keepsol = & l: sol 8747setl nosol 8748let ctr = a: firstline 8749while ctr <= a: lastline 8750exe "NetrwKeepj " . ctr 8751 8752" sanity checks 8753if line ( "." ) < w: netrw_bannercnt 8754let ctr = ctr + 1 8755continue 8756endif 8757 8758let curword = s: NetrwGetWord () 8759if curword == "./" || curword == "../" 8760let ctr = ctr + 1 8761continue 8762endif 8763 8764let ok = s: NetrwLocalRmFile ( a: path , curword , all ) 8765if ok =~# '^a\%[ll]$' 8766let all = 1 8767elseif ok =~# "n\%[o]" 8768break 8769endif 8770 8771let ctr = ctr + 1 8772endwhile 8773 8774let & l: sol = keepsol 8775endif 8776 8777" refresh the directory 8778if bufname ( "%" ) != "NetrwMessage" 8779NetrwKeepj call s:NetrwRefresh(1, s:NetrwBrowseChgDir(1, './' , 0)) 8780NetrwKeepj call winrestview(svpos) 8781endif 8782 8783let @@ = ykeep 8784endfunction 8785 8786" s:NetrwLocalRmFile: remove file fname given the path {{{2 8787" Give confirmation prompt unless all==1 8788function s: NetrwLocalRmFile ( path , fname , all ) 8789let all = a: all 8790let ok = "" 8791let dir = 0 8792NetrwKeepj norm! 0 8793let rmfile = s: NetrwFile ( netrw#fs#ComposePath ( a: path , escape ( a: fname , '\\' ))) -> fnamemodify ( ':.' ) 8794 8795" if not a directory 8796if rmfile !~ '^"' && ( rmfile =~ '@$' || rmfile !~ '[\/]$' ) 8797let msg = "Confirm deletion of file <%s> [{y(es)},n(o),a(ll)]: " 8798else 8799let msg = "Confirm *recursive* deletion of directory <%s> [{y(es)},n(o),a(ll)]: " 8800let dir = 1 8801endif 8802 8803" Ask confirmation 8804if ! all 8805echohl Statement 8806call inputsave () 8807let ok = input ( printf ( msg , rmfile )) 8808call inputrestore () 8809echohl NONE 8810if ok =~# '^a\%[ll]$' || ok =~# '^y\%[es]$' 8811let all = 1 8812else 8813let ok = 'no' 8814endif 8815endif 8816 8817if ! dir && ( all || empty ( ok )) 8818" This works because delete return 0 if successful 8819if netrw#fs#Remove ( rmfile ) 8820call netrw#msg#Notify ( 'ERROR' , printf ( "unable to delete <%s>!" , rmfile )) 8821else 8822" Remove file only if there are no pending changes 8823execute printf ( 'silent! bwipeout %s' , fnameescape ( rmfile )) 8824endif 8825 8826elseif dir && ( all || empty ( ok )) 8827" Remove trailing / 8828let rmfile = substitute ( rmfile , '[\/]$' , '' , 'e' ) 8829if delete ( rmfile , "rf" ) 8830call netrw#msg#Notify ( 'ERROR' , printf ( "unable to delete directory <%s>!" , rmfile )) 8831endif 8832 8833endif 8834 8835return ok 8836endfunction 8837 8838" Support Functions: {{{1 8839 8840" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2 8841function netrw#Call ( funcname ,...) 8842return call ( "s:" . a: funcname , a: 000 ) 8843endfunction 8844 8845" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2 8846" I expect this function to be used in 8847" :PChkAssert netrw#Expose("netrwmarkfilelist") 8848" for example. 8849function netrw#Expose ( varname ) 8850if exists ( "s:" . a: varname ) 8851exe "let retval= s:" . a: varname 8852if exists ( "g:netrw_pchk" ) 8853if type ( retval ) == 3 8854let retval = copy ( retval ) 8855let i = 0 8856while i < len ( retval ) 8857let retval [ i ] = substitute ( retval [ i ], expand ( "$HOME" ), '~' , '' ) 8858let i = i + 1 8859endwhile 8860endif 8861return string ( retval ) 8862else 8863endif 8864else 8865let retval = "n/a" 8866endif 8867 8868return retval 8869endfunction 8870 8871" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2 8872function netrw#Modify ( varname , newvalue ) 8873exe "let s:" . a: varname . "= " . string ( a: newvalue ) 8874endfunction 8875 8876" netrw#RFC2396: converts %xx into characters {{{2 8877function netrw#RFC2396 ( fname ) 8878return substitute ( a: fname , '%\(\x\x\)' , '\=printf("%c","0x".submatch(1))' , 'ge' ) 8879endfunction 8880 8881" netrw#UserMaps: supports user-specified maps {{{2 8882" see :help function() 8883" 8884" g:Netrw_UserMaps is a List with members such as: 8885" [[keymap sequence, function reference],...] 8886" 8887" The referenced function may return a string, 8888" refresh : refresh the display 8889" -other- : this string will be executed 8890" or it may return a List of strings. 8891" 8892" Each keymap-sequence will be set up with a nnoremap 8893" to invoke netrw#UserMaps(a:islocal). 8894" Related functions: 8895" netrw#Expose(varname) -- see s:varname variables 8896" netrw#Modify(varname,newvalue) -- modify value of s:varname variable 8897" netrw#Call(funcname,...) -- call internal netrw function with optional arguments 8898function netrw#UserMaps ( islocal ) 8899 8900" set up usermaplist 8901if exists ( "g:Netrw_UserMaps" ) && type ( g: Netrw_UserMaps ) == 3 8902for umap in g: Netrw_UserMaps 8903" if umap[0] is a string and umap[1] is a string holding a function name 8904if type ( umap [ 0 ]) == 1 && type ( umap [ 1 ]) == 1 8905exe "nno <buffer> <silent> " . umap [ 0 ] . " :call <SID>UserMaps(" . a: islocal . ",'" . umap [ 1 ] . "')<cr>" 8906else 8907call netrw#msg#Notify ( 'WARNING' , printf ( 'ignoring usermap <%s> -- not a [string,funcref] entry' , string ( umap [ 0 ]))) 8908endif 8909endfor 8910endif 8911endfunction 8912 8913" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2 8914" cb : bl2mf=0 add marked files to buffer list 8915" cB : bl2mf=1 use bufferlist to mark files 8916" (mnemonic: cb = copy (marked files) to buffer list) 8917function s: NetrwBadd ( islocal , bl2mf ) 8918if a: bl2mf 8919" cB: add buffer list to marked files 8920redir => bufl 8921ls 8922redir END 8923let bufl = map ( split ( bufl , "\n" ), 'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')' ) 8924for fname in bufl 8925call s: NetrwMarkFile ( a: islocal , fname ) 8926endfor 8927else 8928" cb: add marked files to buffer list 8929for fname in s: netrwmarkfilelist_ { bufnr ( "%" )} 8930exe "badd " . fnameescape ( fname ) 8931endfor 8932let curbufnr = bufnr ( "%" ) 8933let curdir = s: NetrwGetCurdir ( a: islocal ) 8934call s: NetrwUnmarkList ( curbufnr , curdir ) " remove markings from local buffer 8935endif 8936endfunction 8937 8938" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2 8939" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark() 8940function s: DeleteBookmark ( fname ) 8941call s: MergeBookmarks () 8942 8943if exists ( "g:netrw_bookmarklist" ) 8944let indx = index ( g: netrw_bookmarklist , a: fname ) 8945if indx == -1 8946let indx = 0 8947while indx < len ( g: netrw_bookmarklist ) 8948if g: netrw_bookmarklist [ indx ] =~ a: fname 8949call remove ( g: netrw_bookmarklist , indx ) 8950let indx = indx - 1 8951endif 8952let indx = indx + 1 8953endwhile 8954else 8955" remove exact match 8956call remove ( g: netrw_bookmarklist , indx ) 8957endif 8958endif 8959 8960endfunction 8961 8962" s:FileReadable: o/s independent filereadable {{{2 8963function s: FileReadable ( fname ) 8964if g: netrw_cygwin 8965let ret = filereadable ( s: NetrwFile ( substitute ( a: fname , g: netrw_cygdrive . '/\(.\)' , '\1:/' , '' ))) 8966else 8967let ret = filereadable ( s: NetrwFile ( a: fname )) 8968endif 8969 8970return ret 8971endfunction 8972 8973" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2 8974" Places correct suffix on end of temporary filename, 8975" using the suffix provided with fname 8976function s: GetTempfile ( fname ) 8977 8978if ! exists ( "b:netrw_tmpfile" ) 8979" get a brand new temporary filename 8980let tmpfile = tempname () 8981 8982let tmpfile = substitute ( tmpfile , '\' , '/' , 'ge' ) 8983 8984" sanity check -- does the temporary file's directory exist? 8985if ! isdirectory ( s: NetrwFile ( substitute ( tmpfile , '[^/]\+$' , '' , 'e' ))) 8986call netrw#msg#Notify ( 'ERROR' , printf ( 'your <%s> directory is missing!' , substitute ( tmpfile , '[^/]\+$' , '' , 'e' ))) 8987return "" 8988endif 8989 8990" let netrw#NetSource() know about the tmpfile 8991let s: netrw_tmpfile = tmpfile " used by netrw#NetSource() and netrw#BrowseX() 8992 8993" o/s dependencies 8994if g: netrw_cygwin != 0 8995let tmpfile = substitute ( tmpfile , '^\(\a\):' , g: netrw_cygdrive . '/\1' , 'e' ) 8996elseif has ( "win32" ) 8997if ! exists ( "+shellslash" ) || !& ssl 8998let tmpfile = substitute ( tmpfile , '/' , '\' , 'g' ) 8999endif 9000else 9001let tmpfile = tmpfile 9002endif 9003let b: netrw_tmpfile = tmpfile 9004else 9005" re-use temporary filename 9006let tmpfile = b: netrw_tmpfile 9007endif 9008 9009" use fname's suffix for the temporary file 9010" Restrict the suffix to word characters so shell metacharacters in a 9011" remote filename (e.g. sftp://host/foo.txt;id) cannot ride along into 9012" the tempfile name and out into a downstream shell command. 9013if a: fname != "" 9014if a: fname =~ '\.\w\+$' 9015if a: fname =~ '\.tar\.gz$' || a: fname =~ '\.tar\.bz2$' || a: fname =~ '\.tar\.xz$' 9016let suffix = ".tar" . substitute ( a: fname , '^.*\(\.\w\+\)$' , '\1' , 'e' ) 9017elseif a: fname =~ '.txz$' 9018let suffix = ".txz" . substitute ( a: fname , '^.*\(\.\w\+\)$' , '\1' , 'e' ) 9019else 9020let suffix = substitute ( a: fname , '^.*\(\.\w\+\)$' , '\1' , 'e' ) 9021endif 9022let tmpfile = substitute ( tmpfile , '\.tmp$' , '' , 'e' ) 9023let tmpfile .= suffix 9024let s: netrw_tmpfile = tmpfile " supports netrw#NetSource() 9025endif 9026endif 9027 9028return tmpfile 9029endfunction 9030 9031" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2 9032" a correct command for use with a system() call 9033function s: MakeSshCmd ( sshcmd ) 9034let machine = shellescape ( s: machine , 1 ) 9035if s: user != '' 9036let machine = shellescape ( s: user , 1 ) . '@' . machine 9037endif 9038let sshcmd = substitute ( a: sshcmd , '\<HOSTNAME\>' , machine , '' ) 9039if exists ( "g:netrw_port" ) && g: netrw_port != "" 9040let sshcmd = substitute ( sshcmd , "USEPORT" , g: netrw_sshport . ' ' . shellescape ( g: netrw_port , 1 ), '' ) 9041elseif exists ( "s:port" ) && s: port != "" 9042let sshcmd = substitute ( sshcmd , "USEPORT" , g: netrw_sshport . ' ' . shellescape ( s: port , 1 ), '' ) 9043else 9044let sshcmd = substitute ( sshcmd , "USEPORT " , '' , '' ) 9045endif 9046return sshcmd 9047endfunction 9048 9049" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2 9050" Note that bookmark paths should always be absolute. 9051function s: MakeBookmark ( fname ) 9052 9053if ! exists ( "g:netrw_bookmarklist" ) 9054let g: netrw_bookmarklist = [] 9055endif 9056 9057" Normalize path to prevent duplicate entries 9058let bookmark_path = netrw#fs#AbsPath ( s: NetrwFile ( a: fname )) 9059let ignore_case = 0 9060if has ( 'win32' ) 9061let bookmark_path = substitute ( bookmark_path , '\\' , '/' , 'ge' ) 9062let ignore_case = 1 9063endif 9064let bookmark_path = simplify ( bookmark_path ) 9065 9066if isdirectory ( bookmark_path ) && bookmark_path !~ '/$' 9067let bookmark_path .= '/' 9068endif 9069 9070if index ( g: netrw_bookmarklist , bookmark_path , 0 , ignore_case ) == -1 9071" Not currently in the bookmarks list, so include it 9072call add ( g: netrw_bookmarklist , bookmark_path ) 9073call sort ( g: netrw_bookmarklist ) 9074endif 9075 9076endfunction 9077 9078" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2 9079function s: MergeBookmarks () 9080" get bookmarks from .netrwbook file 9081let savefile = s: NetrwHome () . "/.netrwbook" 9082if filereadable ( s: NetrwFile ( savefile )) 9083NetrwKeepj call s:NetrwBookHistSave() 9084NetrwKeepj call delete(savefile) 9085endif 9086endfunction 9087 9088" s:NetrwBMShow: {{{2 9089function s: NetrwBMShow () 9090redir => bmshowraw 9091menu 9092redir END 9093let bmshowlist = split ( bmshowraw , '\n' ) 9094if bmshowlist != [] 9095let bmshowfuncs = filter ( bmshowlist , 'v:val =~# "<SNR>\\d\\+_BMShow()"' ) 9096if bmshowfuncs != [] 9097let bmshowfunc = substitute ( bmshowfuncs [ 0 ], '^.*:\(call.*BMShow()\).*$' , '\1' , '' ) 9098if bmshowfunc =~# '^call.*BMShow()' 9099exe "sil! NetrwKeepj " . bmshowfunc 9100endif 9101endif 9102endif 9103endfunction 9104 9105" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2 9106function s: NetrwCursor ( editfile ) 9107if ! exists ( "w:netrw_liststyle" ) 9108let w: netrw_liststyle = g: netrw_liststyle 9109endif 9110 9111 9112if & ft != "netrw" 9113" if the current window isn't a netrw directory listing window, then use user cursorline/column 9114" settings. Affects when netrw is used to read/write a file using scp/ftp/etc. 9115 9116elseif g: netrw_cursor == 8 9117if w: netrw_liststyle == s: WIDELIST 9118setl cursorline 9119setl cursorcolumn 9120else 9121setl cursorline 9122endif 9123elseif g: netrw_cursor == 7 9124setl cursorline 9125elseif g: netrw_cursor == 6 9126if w: netrw_liststyle == s: WIDELIST 9127setl cursorline 9128endif 9129elseif g: netrw_cursor == 4 9130" all styles: cursorline, cursorcolumn 9131setl cursorline 9132setl cursorcolumn 9133 9134elseif g: netrw_cursor == 3 9135" thin-long-tree: cursorline, user's cursorcolumn 9136" wide : cursorline, cursorcolumn 9137if w: netrw_liststyle == s: WIDELIST 9138setl cursorline 9139setl cursorcolumn 9140else 9141setl cursorline 9142endif 9143 9144elseif g: netrw_cursor == 2 9145" thin-long-tree: cursorline, user's cursorcolumn 9146" wide : cursorline, user's cursorcolumn 9147setl cursorline 9148 9149elseif g: netrw_cursor == 1 9150" thin-long-tree: user's cursorline, user's cursorcolumn 9151" wide : cursorline, user's cursorcolumn 9152if w: netrw_liststyle == s: WIDELIST 9153setl cursorline 9154else 9155endif 9156 9157else 9158" all styles: user's cursorline, user's cursorcolumn 9159let & l: cursorline = s: netrw_usercul 9160let & l: cursorcolumn = s: netrw_usercuc 9161endif 9162 9163endfunction 9164 9165" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2 9166function s: RestoreCursorline () 9167if exists ( "s:netrw_usercul" ) 9168let & l: cursorline = s: netrw_usercul 9169endif 9170if exists ( "s:netrw_usercuc" ) 9171let & l: cursorcolumn = s: netrw_usercuc 9172endif 9173endfunction 9174 9175" s:RestoreRegister: restores all registers given in the dict {{{2 9176function s: RestoreRegister ( dict ) 9177for [ key , val ] in items ( a: dict ) 9178if key == 'unnamed' 9179let key = '' 9180endif 9181call setreg ( key , val [ 0 ], val [ 1 ]) 9182endfor 9183endfunction 9184 9185" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2 9186function s: NetrwEnew (...) 9187 9188" Clean out the last buffer: 9189" Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window 9190" If so, delete it. 9191let bufid = bufnr ( '$' ) 9192if bufid > 1 && ! buflisted ( bufid ) && bufloaded ( bufid ) && bufname ( bufid ) == "" && bufwinid ( bufid ) == -1 9193execute printf ( "silent! bdelete! %s" , bufid ) 9194endif 9195 9196" grab a function-local-variable copy of buffer variables 9197if exists ( "b:netrw_bannercnt" ) | let netrw_bannercnt = b: netrw_bannercnt | endif 9198if exists ( "b:netrw_browser_active" ) | let netrw_browser_active = b: netrw_browser_active | endif 9199if exists ( "b:netrw_cpf" ) | let netrw_cpf = b: netrw_cpf | endif 9200if exists ( "b:netrw_curdir" ) | let netrw_curdir = b: netrw_curdir | endif 9201if exists ( "b:netrw_explore_bufnr" ) | let netrw_explore_bufnr = b: netrw_explore_bufnr | endif 9202if exists ( "b:netrw_explore_indx" ) | let netrw_explore_indx = b: netrw_explore_indx | endif 9203if exists ( "b:netrw_explore_line" ) | let netrw_explore_line = b: netrw_explore_line | endif 9204if exists ( "b:netrw_explore_list" ) | let netrw_explore_list = b: netrw_explore_list | endif 9205if exists ( "b:netrw_explore_listlen" ) | let netrw_explore_listlen = b: netrw_explore_listlen | endif 9206if exists ( "b:netrw_explore_mtchcnt" ) | let netrw_explore_mtchcnt = b: netrw_explore_mtchcnt | endif 9207if exists ( "b:netrw_fname" ) | let netrw_fname = b: netrw_fname | endif 9208if exists ( "b:netrw_lastfile" ) | let netrw_lastfile = b: netrw_lastfile | endif 9209if exists ( "b:netrw_liststyle" ) | let netrw_liststyle = b: netrw_liststyle | endif 9210if exists ( "b:netrw_method" ) | let netrw_method = b: netrw_method | endif 9211if exists ( "b:netrw_option" ) | let netrw_option = b: netrw_option | endif 9212if exists ( "b:netrw_prvdir" ) | let netrw_prvdir = b: netrw_prvdir | endif 9213 9214NetrwKeepj call s:NetrwOptionsRestore("w:") 9215" when tree listing uses file TreeListing... a new buffer is made. 9216" Want the old buffer to be unlisted. 9217" COMBAK: this causes a problem, see P43 9218" setl nobl 9219let netrw_keepdiff = & l: diff 9220call s: NetrwEditFile ( "enew!" , "" , "" ) 9221let & l: diff = netrw_keepdiff 9222NetrwKeepj call s:NetrwOptionsSave("w:") 9223 9224" copy function-local-variables to buffer variable equivalents 9225if exists ( "netrw_bannercnt" ) | let b: netrw_bannercnt = netrw_bannercnt | endif 9226if exists ( "netrw_browser_active" ) | let b: netrw_browser_active = netrw_browser_active | endif 9227if exists ( "netrw_cpf" ) | let b: netrw_cpf = netrw_cpf | endif 9228if exists ( "netrw_curdir" ) | let b: netrw_curdir = netrw_curdir | endif 9229if exists ( "netrw_explore_bufnr" ) | let b: netrw_explore_bufnr = netrw_explore_bufnr | endif 9230if exists ( "netrw_explore_indx" ) | let b: netrw_explore_indx = netrw_explore_indx | endif 9231if exists ( "netrw_explore_line" ) | let b: netrw_explore_line = netrw_explore_line | endif 9232if exists ( "netrw_explore_list" ) | let b: netrw_explore_list = netrw_explore_list | endif 9233if exists ( "netrw_explore_listlen" ) | let b: netrw_explore_listlen = netrw_explore_listlen | endif 9234if exists ( "netrw_explore_mtchcnt" ) | let b: netrw_explore_mtchcnt = netrw_explore_mtchcnt | endif 9235if exists ( "netrw_fname" ) | let b: netrw_fname = netrw_fname | endif 9236if exists ( "netrw_lastfile" ) | let b: netrw_lastfile = netrw_lastfile | endif 9237if exists ( "netrw_liststyle" ) | let b: netrw_liststyle = netrw_liststyle | endif 9238if exists ( "netrw_method" ) | let b: netrw_method = netrw_method | endif 9239if exists ( "netrw_option" ) | let b: netrw_option = netrw_option | endif 9240if exists ( "netrw_prvdir" ) | let b: netrw_prvdir = netrw_prvdir | endif 9241 9242if a: 0 > 0 9243let b: netrw_curdir = a: 1 9244if b: netrw_curdir =~ '/$' 9245if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST 9246setl nobl 9247file NetrwTreeListing 9248setl nobl bt = nowrite bh = hide 9249nno <silent> <buffer> [ :sil call < SID > TreeListMove('[') < cr > 9250nno <silent> <buffer> ] :sil call < SID > TreeListMove(']') < cr > 9251else 9252call s: NetrwBufRename ( b: netrw_curdir ) 9253endif 9254endif 9255endif 9256endfunction 9257 9258" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2 9259function s: NetrwInsureWinVars () 9260if ! exists ( "w:netrw_liststyle" ) 9261let curbuf = bufnr ( "%" ) 9262let curwin = winnr () 9263let iwin = 1 9264while iwin <= winnr ( "$" ) 9265exe iwin . "wincmd w" 9266if winnr () != curwin && bufnr ( "%" ) == curbuf && exists ( "w:netrw_liststyle" ) 9267" looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer 9268let winvars = w: 9269break 9270endif 9271let iwin = iwin + 1 9272endwhile 9273exe "keepalt " . curwin . "wincmd w" 9274if exists ( "winvars" ) 9275for k in keys ( winvars ) 9276let w: { k } = winvars [ k ] 9277endfor 9278endif 9279endif 9280endfunction 9281 9282" s:NetrwLcd: handles changing the (local) directory {{{2 9283" Returns: 0=success 9284" -1=failed 9285function s: NetrwLcd ( newdir ) 9286 9287let err472 = 0 9288try 9289exe 'NetrwKeepj sil lcd ' . fnameescape ( a: newdir ) 9290catch /^Vim\%((\a\+)\)\=:E344/ 9291" Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share. 9292" Therefore, detect if a Windows share is present, and if E344 occurs, just settle at 9293" 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or 9294" forward slashes ('//Foo'), depending on whether backslashes have been converted to 9295" forward slashes by earlier code; so check for both. 9296if has ( "win32" ) && ! g: netrw_cygwin 9297if a: newdir =~ '^\\\\\w\+' || a: newdir =~ '^//\w\+' 9298let dirname = '\' 9299exe 'NetrwKeepj sil lcd ' . fnameescape ( dirname ) 9300endif 9301endif 9302catch /^Vim\%((\a\+)\)\=:E472/ 9303let err472 = 1 9304endtry 9305 9306if err472 9307call netrw#msg#Notify ( 'ERROR' , printf ( 'unable to change directory to <%s> (permissions?)' , a: newdir )) 9308if ! exists ( "w:netrw_prvdir" ) 9309call s: NetrwOptionsRestore ( "w:" ) 9310exe "setl " . g: netrw_bufsettings 9311endif 9312return -1 9313endif 9314 9315return 0 9316endfunction 9317 9318" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2 9319" changed sorting, etc. Also see s:NetrwRestoreWordPosn(). 9320function s: NetrwSaveWordPosn () 9321let s: netrw_saveword = '^' . fnameescape ( getline ( '.' )) . '$' 9322endfunction 9323 9324" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2 9325" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G 9326function s: NetrwHumanReadable ( sz ) 9327 9328if g: netrw_sizestyle ==# 'h' 9329if a: sz >= 1000000000 9330let sz = printf ( "%.1f" , a: sz / 1000000000.0 ) . "g" 9331elseif a: sz >= 10000000 9332let sz = printf ( "%d" , a: sz / 1000000 ) . "m" 9333elseif a: sz >= 1000000 9334let sz = printf ( "%.1f" , a: sz / 1000000.0 ) . "m" 9335elseif a: sz >= 10000 9336let sz = printf ( "%d" , a: sz / 1000 ) . "k" 9337elseif a: sz >= 1000 9338let sz = printf ( "%.1f" , a: sz / 1000.0 ) . "k" 9339else 9340let sz = a: sz 9341endif 9342 9343elseif g: netrw_sizestyle ==# 'H' 9344if a: sz >= 1073741824 9345let sz = printf ( "%.1f" , a: sz / 1073741824.0 ) . "G" 9346elseif a: sz >= 10485760 9347let sz = printf ( "%d" , a: sz / 1048576 ) . "M" 9348elseif a: sz >= 1048576 9349let sz = printf ( "%.1f" , a: sz / 1048576.0 ) . "M" 9350elseif a: sz >= 10240 9351let sz = printf ( "%d" , a: sz / 1024 ) . "K" 9352elseif a: sz >= 1024 9353let sz = printf ( "%.1f" , a: sz / 1024.0 ) . "K" 9354else 9355let sz = a: sz 9356endif 9357 9358else 9359let sz = a: sz 9360endif 9361 9362return sz 9363endfunction 9364 9365" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2 9366" changed sorting, etc. Also see s:NetrwSaveWordPosn(). 9367function s: NetrwRestoreWordPosn () 9368sil ! call search ( s: netrw_saveword , 'w' ) 9369endfunction 9370 9371" s:RestoreBufVars: {{{2 9372function s: RestoreBufVars () 9373 9374if exists ( "s:netrw_curdir" ) | let b: netrw_curdir = s: netrw_curdir | endif 9375if exists ( "s:netrw_lastfile" ) | let b: netrw_lastfile = s: netrw_lastfile | endif 9376if exists ( "s:netrw_method" ) | let b: netrw_method = s: netrw_method | endif 9377if exists ( "s:netrw_fname" ) | let b: netrw_fname = s: netrw_fname | endif 9378if exists ( "s:netrw_machine" ) | let b: netrw_machine = s: netrw_machine | endif 9379if exists ( "s:netrw_browser_active" ) | let b: netrw_browser_active = s: netrw_browser_active | endif 9380 9381endfunction 9382 9383" s:RemotePathAnalysis: {{{2 9384function s: RemotePathAnalysis ( dirname ) 9385 9386" method :// user @ machine :port /path 9387let dirpat = '^\(\w\{-}\)://\(\([^@]\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$' 9388let s: method = substitute ( a: dirname , dirpat , '\1' , '' ) 9389let s: user = substitute ( a: dirname , dirpat , '\3' , '' ) 9390let s: machine = substitute ( a: dirname , dirpat , '\4' , '' ) 9391let s: port = substitute ( a: dirname , dirpat , '\5' , '' ) 9392let s: path = substitute ( a: dirname , dirpat , '\6' , '' ) 9393let s: fname = substitute ( s: path , '^.*/\ze.' , '' , '' ) 9394if s: machine =~ '@' 9395let dirpat = '^\(.*\)@\(.\{-}\)$' 9396let s: user = s: user . '@' . substitute ( s: machine , dirpat , '\1' , '' ) 9397let s: machine = substitute ( s: machine , dirpat , '\2' , '' ) 9398endif 9399 9400 9401endfunction 9402 9403" s:RemoteSystem: runs a command on a remote host using ssh {{{2 9404" Returns status 9405" Runs system() on 9406" [cd REMOTEDIRPATH;] a:cmd 9407" Note that it doesn't do netrw#os#Escape(a:cmd)! 9408function s: RemoteSystem ( cmd ) 9409if ! executable ( g: netrw_ssh_cmd ) 9410call netrw#msg#Notify ( 'ERROR' , printf ( 'g:netrw_ssh_cmd<%s> is not executable!' , g: netrw_ssh_cmd )) 9411elseif ! exists ( "b:netrw_curdir" ) 9412call netrw#msg#Notify ( 'ERROR' , "for some reason b:netrw_curdir doesn't exist!" ) 9413else 9414let cmd = s: MakeSshCmd ( g: netrw_ssh_cmd . " USEPORT HOSTNAME" ) 9415let remotedir = substitute ( b: netrw_curdir , '^.*//[^/]\+/\(.*\)$' , '\1' , '' ) 9416if remotedir != "" 9417let cmd = cmd . ' cd ' . netrw#os#Escape ( remotedir ) . ";" 9418else 9419let cmd = cmd . ' ' 9420endif 9421let cmd = cmd . a: cmd 9422let ret = system ( cmd ) 9423endif 9424return ret 9425endfunction 9426 9427" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2 9428function s: RestoreWinVars () 9429if exists ( "s:bannercnt" ) | let w: netrw_bannercnt = s: bannercnt | unlet s: bannercnt | endif 9430if exists ( "s:col" ) | let w: netrw_col = s: col | unlet s: col | endif 9431if exists ( "s:curdir" ) | let w: netrw_curdir = s: curdir | unlet s: curdir | endif 9432if exists ( "s:explore_bufnr" ) | let w: netrw_explore_bufnr = s: explore_bufnr | unlet s: explore_bufnr | endif 9433if exists ( "s:explore_indx" ) | let w: netrw_explore_indx = s: explore_indx | unlet s: explore_indx | endif 9434if exists ( "s:explore_line" ) | let w: netrw_explore_line = s: explore_line | unlet s: explore_line | endif 9435if exists ( "s:explore_listlen" ) | let w: netrw_explore_listlen = s: explore_listlen | unlet s: explore_listlen | endif 9436if exists ( "s:explore_list" ) | let w: netrw_explore_list = s: explore_list | unlet s: explore_list | endif 9437if exists ( "s:explore_mtchcnt" ) | let w: netrw_explore_mtchcnt = s: explore_mtchcnt | unlet s: explore_mtchcnt | endif 9438if exists ( "s:fpl" ) | let w: netrw_fpl = s: fpl | unlet s: fpl | endif 9439if exists ( "s:hline" ) | let w: netrw_hline = s: hline | unlet s: hline | endif 9440if exists ( "s:line" ) | let w: netrw_line = s: line | unlet s: line | endif 9441if exists ( "s:liststyle" ) | let w: netrw_liststyle = s: liststyle | unlet s: liststyle | endif 9442if exists ( "s:method" ) | let w: netrw_method = s: method | unlet s: method | endif 9443if exists ( "s:prvdir" ) | let w: netrw_prvdir = s: prvdir | unlet s: prvdir | endif 9444if exists ( "s:treedict" ) | let w: netrw_treedict = s: treedict | unlet s: treedict | endif 9445if exists ( "s:treetop" ) | let w: netrw_treetop = s: treetop | unlet s: treetop | endif 9446if exists ( "s:winnr" ) | let w: netrw_winnr = s: winnr | unlet s: winnr | endif 9447endfunction 9448 9449" s:Rexplore: implements returning from a buffer to a netrw directory {{{2 9450" 9451" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap 9452" is true) and a command, :Rexplore, which call this function. 9453" 9454" s:netrw_posn is set up by s:NetrwBrowseChgDir() 9455" 9456" s:rexposn_BUFNR used to save/restore cursor position 9457function s: NetrwRexplore ( islocal , dirname ) 9458if exists ( "s:netrwdrag" ) 9459return 9460endif 9461 9462if & ft == "netrw" && exists ( "w:netrw_rexfile" ) && w: netrw_rexfile != "" 9463" a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile 9464exe "NetrwKeepj e " . w: netrw_rexfile 9465unlet w: netrw_rexfile 9466return 9467endif 9468 9469" --------------------------- 9470" :Rex issued while in a file 9471" --------------------------- 9472 9473" record current file so :Rex can return to it from netrw 9474let w: netrw_rexfile = expand ( "%" ) 9475 9476if ! exists ( "w:netrw_rexlocal" ) 9477return 9478endif 9479if w: netrw_rexlocal 9480NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir) 9481else 9482NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir) 9483endif 9484if exists ( "s:initbeval" ) 9485setl beval 9486endif 9487if exists ( "s:rexposn_" . bufnr ( "%" )) 9488" restore position in directory listing 9489NetrwKeepj call winrestview(s:rexposn_{bufnr('%')}) 9490if exists ( "s:rexposn_" . bufnr ( '%' )) 9491unlet s: rexposn_ { bufnr ( '%' )} 9492endif 9493else 9494endif 9495 9496if has ( "syntax" ) && exists ( "g:syntax_on" ) && g: syntax_on 9497if exists ( "s:explore_match" ) 9498exe "2match netrwMarkFile /" . s: explore_match . "/" 9499endif 9500endif 9501 9502endfunction 9503 9504" s:SaveBufVars: save selected b: variables to s: variables {{{2 9505" use s:RestoreBufVars() to restore b: variables from s: variables 9506function s: SaveBufVars () 9507 9508if exists ( "b:netrw_curdir" ) | let s: netrw_curdir = b: netrw_curdir | endif 9509if exists ( "b:netrw_lastfile" ) | let s: netrw_lastfile = b: netrw_lastfile | endif 9510if exists ( "b:netrw_method" ) | let s: netrw_method = b: netrw_method | endif 9511if exists ( "b:netrw_fname" ) | let s: netrw_fname = b: netrw_fname | endif 9512if exists ( "b:netrw_machine" ) | let s: netrw_machine = b: netrw_machine | endif 9513if exists ( "b:netrw_browser_active" ) | let s: netrw_browser_active = b: netrw_browser_active | endif 9514 9515endfunction 9516 9517" s:SavePosn: saves position associated with current buffer into a dictionary {{{2 9518function s: SavePosn ( posndict ) 9519 9520if ! exists ( "a:posndict[bufnr('%')]" ) 9521let a: posndict [ bufnr ( "%" )] = [] 9522endif 9523call add ( a: posndict [ bufnr ( "%" )], winsaveview ()) 9524 9525return a: posndict 9526endfunction 9527 9528" s:RestorePosn: restores position associated with current buffer using dictionary {{{2 9529function s: RestorePosn ( posndict ) 9530if exists ( "a:posndict" ) 9531if has_key ( a: posndict , bufnr ( "%" )) 9532let posnlen = len ( a: posndict [ bufnr ( "%" )]) 9533if posnlen > 0 9534let posnlen = posnlen - 1 9535call winrestview ( a: posndict [ bufnr ( "%" )][ posnlen ]) 9536call remove ( a: posndict [ bufnr ( "%" )], posnlen ) 9537endif 9538endif 9539endif 9540endfunction 9541 9542" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2 9543function s: SaveWinVars () 9544if exists ( "w:netrw_bannercnt" ) | let s: bannercnt = w: netrw_bannercnt | endif 9545if exists ( "w:netrw_col" ) | let s: col = w: netrw_col | endif 9546if exists ( "w:netrw_curdir" ) | let s: curdir = w: netrw_curdir | endif 9547if exists ( "w:netrw_explore_bufnr" ) | let s: explore_bufnr = w: netrw_explore_bufnr | endif 9548if exists ( "w:netrw_explore_indx" ) | let s: explore_indx = w: netrw_explore_indx | endif 9549if exists ( "w:netrw_explore_line" ) | let s: explore_line = w: netrw_explore_line | endif 9550if exists ( "w:netrw_explore_listlen" ) | let s: explore_listlen = w: netrw_explore_listlen | endif 9551if exists ( "w:netrw_explore_list" ) | let s: explore_list = w: netrw_explore_list | endif 9552if exists ( "w:netrw_explore_mtchcnt" ) | let s: explore_mtchcnt = w: netrw_explore_mtchcnt | endif 9553if exists ( "w:netrw_fpl" ) | let s: fpl = w: netrw_fpl | endif 9554if exists ( "w:netrw_hline" ) | let s: hline = w: netrw_hline | endif 9555if exists ( "w:netrw_line" ) | let s: line = w: netrw_line | endif 9556if exists ( "w:netrw_liststyle" ) | let s: liststyle = w: netrw_liststyle | endif 9557if exists ( "w:netrw_method" ) | let s: method = w: netrw_method | endif 9558if exists ( "w:netrw_prvdir" ) | let s: prvdir = w: netrw_prvdir | endif 9559if exists ( "w:netrw_treedict" ) | let s: treedict = w: netrw_treedict | endif 9560if exists ( "w:netrw_treetop" ) | let s: treetop = w: netrw_treetop | endif 9561if exists ( "w:netrw_winnr" ) | let s: winnr = w: netrw_winnr | endif 9562endfunction 9563 9564" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2 9565" To allow separate windows to have their own activities, such as 9566" Explore **/pattern, several variables have been made window-oriented. 9567" However, when the user splits a browser window (ex: ctrl-w s), these 9568" variables are not inherited by the new window. SetBufWinVars() and 9569" UseBufWinVars() get around that. 9570function s: SetBufWinVars () 9571if exists ( "w:netrw_liststyle" ) | let b: netrw_liststyle = w: netrw_liststyle | endif 9572if exists ( "w:netrw_bannercnt" ) | let b: netrw_bannercnt = w: netrw_bannercnt | endif 9573if exists ( "w:netrw_method" ) | let b: netrw_method = w: netrw_method | endif 9574if exists ( "w:netrw_prvdir" ) | let b: netrw_prvdir = w: netrw_prvdir | endif 9575if exists ( "w:netrw_explore_indx" ) | let b: netrw_explore_indx = w: netrw_explore_indx | endif 9576if exists ( "w:netrw_explore_listlen" ) | let b: netrw_explore_listlen = w: netrw_explore_listlen | endif 9577if exists ( "w:netrw_explore_mtchcnt" ) | let b: netrw_explore_mtchcnt = w: netrw_explore_mtchcnt | endif 9578if exists ( "w:netrw_explore_bufnr" ) | let b: netrw_explore_bufnr = w: netrw_explore_bufnr | endif 9579if exists ( "w:netrw_explore_line" ) | let b: netrw_explore_line = w: netrw_explore_line | endif 9580if exists ( "w:netrw_explore_list" ) | let b: netrw_explore_list = w: netrw_explore_list | endif 9581endfunction 9582 9583" s:SetRexDir: set directory for :Rexplore {{{2 9584function s: SetRexDir ( islocal , dirname ) 9585let w: netrw_rexdir = a: dirname 9586let w: netrw_rexlocal = a: islocal 9587let s: rexposn_ { bufnr ( "%" )} = winsaveview () 9588endfunction 9589 9590" s:ShowLink: used to modify thin and tree listings to show links {{{2 9591function s: ShowLink () 9592if exists ( "b:netrw_curdir" ) 9593keepp :norm! $?\a 9594"call histdel("/",-1) 9595if exists ( "w:netrw_liststyle" ) && w: netrw_liststyle == s: TREELIST && exists ( "w:netrw_treetop" ) 9596let basedir = s: NetrwTreePath ( w: netrw_treetop ) 9597else 9598let basedir = b: netrw_curdir . '/' 9599endif 9600let fname = basedir . s: NetrwGetWord () 9601let resname = resolve ( fname ) 9602if resname =~ '^\M' . basedir 9603let dirlen = strlen ( basedir ) 9604let resname = strpart ( resname , dirlen ) 9605endif 9606let modline = getline ( "." ) . "\t --> " . resname 9607setl noro ma 9608call setline ( "." , modline ) 9609setl ro noma nomod 9610endif 9611endfunction 9612 9613" s:ShowStyle: {{{2 9614function s: ShowStyle () 9615if ! exists ( "w:netrw_liststyle" ) 9616let liststyle = g: netrw_liststyle 9617else 9618let liststyle = w: netrw_liststyle 9619endif 9620if liststyle == s: THINLIST 9621return s: THINLIST . ":thin" 9622elseif liststyle == s: LONGLIST 9623return s: LONGLIST . ":long" 9624elseif liststyle == s: WIDELIST 9625return s: WIDELIST . ":wide" 9626elseif liststyle == s: TREELIST 9627return s: TREELIST . ":tree" 9628else 9629return 'n/a' 9630endif 9631endfunction 9632 9633" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2 9634function s: TreeListMove ( dir ) 9635let curline = getline ( '.' ) 9636let prvline = ( line ( "." ) > 1 ) ? getline ( line ( "." ) - 1 ) : '' 9637let nxtline = ( line ( "." ) < line ( "$" )) ? getline ( line ( "." ) + 1 ) : '' 9638let curindent = substitute ( getline ( '.' ), '^\(\%(' . s: treedepthstring . '\)*\)[^' . s: treedepthstring . '].\{-}$' , '\1' , 'e' ) 9639let indentm1 = substitute ( curindent , '^' . s: treedepthstring , '' , '' ) 9640let treedepthchr = substitute ( s: treedepthstring , ' ' , '' , 'g' ) 9641let stopline = exists ( "w:netrw_bannercnt" ) ? w: netrw_bannercnt : 1 9642" COMBAK : need to handle when on a directory 9643" COMBAK : need to handle ]] and ][. In general, needs work!!! 9644if curline !~ '/$' 9645if a: dir == '[[' && prvline != '' 9646NetrwKeepj norm! 0 9647let nl = search ( '^' . indentm1 . '\%(' . s: treedepthstring . '\)\@!' , 'bWe' , stopline ) " search backwards 9648elseif a: dir == '[]' && nxtline != '' 9649NetrwKeepj norm! 0 9650let nl = search ( '^\%(' . curindent . '\)\@!' , 'We' ) " search forwards 9651if nl != 0 9652NetrwKeepj norm! k 9653else 9654NetrwKeepj norm! G 9655endif 9656endif 9657endif 9658 9659endfunction 9660 9661" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2 9662" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function 9663" can't be called except via emenu. But due to locale, that menu line may not be called 9664" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway. 9665function s: UpdateBuffersMenu () 9666if has ( "gui" ) && has ( "menu" ) && has ( "gui_running" ) && & go =~# 'm' && g: netrw_menu 9667try 9668sil emenu Buffers.Refresh\ menu 9669catch /^Vim\%((\a\+)\)\=:E/ 9670let v: errmsg = "" 9671sil NetrwKeepj call s:NetrwBMShow() 9672endtry 9673endif 9674endfunction 9675 9676" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2 9677" Matching function to s:SetBufWinVars() 9678function s: UseBufWinVars () 9679if exists ( "b:netrw_liststyle" ) && ! exists ( "w:netrw_liststyle" ) | let w: netrw_liststyle = b: netrw_liststyle | endif 9680if exists ( "b:netrw_bannercnt" ) && ! exists ( "w:netrw_bannercnt" ) | let w: netrw_bannercnt = b: netrw_bannercnt | endif 9681if exists ( "b:netrw_method" ) && ! exists ( "w:netrw_method" ) | let w: netrw_method = b: netrw_method | endif 9682if exists ( "b:netrw_prvdir" ) && ! exists ( "w:netrw_prvdir" ) | let w: netrw_prvdir = b: netrw_prvdir | endif 9683if exists ( "b:netrw_explore_indx" ) && ! exists ( "w:netrw_explore_indx" ) | let w: netrw_explore_indx = b: netrw_explore_indx | endif 9684if exists ( "b:netrw_explore_listlen" ) && ! exists ( "w:netrw_explore_listlen" ) | let w: netrw_explore_listlen = b: netrw_explore_listlen | endif 9685if exists ( "b:netrw_explore_mtchcnt" ) && ! exists ( "w:netrw_explore_mtchcnt" ) | let w: netrw_explore_mtchcnt = b: netrw_explore_mtchcnt | endif 9686if exists ( "b:netrw_explore_bufnr" ) && ! exists ( "w:netrw_explore_bufnr" ) | let w: netrw_explore_bufnr = b: netrw_explore_bufnr | endif 9687if exists ( "b:netrw_explore_line" ) && ! exists ( "w:netrw_explore_line" ) | let w: netrw_explore_line = b: netrw_explore_line | endif 9688if exists ( "b:netrw_explore_list" ) && ! exists ( "w:netrw_explore_list" ) | let w: netrw_explore_list = b: netrw_explore_list | endif 9689endfunction 9690 9691" s:UserMaps: supports user-defined UserMaps {{{2 9692" * calls a user-supplied funcref(islocal,curdir) 9693" * interprets result 9694" See netrw#UserMaps() 9695function s: UserMaps ( islocal , funcname ) 9696if ! exists ( "b:netrw_curdir" ) 9697let b: netrw_curdir = getcwd () 9698endif 9699let Funcref = function ( a: funcname ) 9700let result = Funcref ( a: islocal ) 9701 9702if type ( result ) == 1 9703" if result from user's funcref is a string... 9704if result == "refresh" 9705call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 9706elseif result != "" 9707exe result 9708endif 9709 9710elseif type ( result ) == 3 9711" if result from user's funcref is a List... 9712for action in result 9713if action == "refresh" 9714call s: NetrwRefresh ( a: islocal , s: NetrwBrowseChgDir ( a: islocal , './' , 0 )) 9715elseif action != "" 9716exe action 9717endif 9718endfor 9719endif 9720endfunction 9721 9722" Deprecated: {{{1 9723 9724" }}} 9725" Settings Restoration: {{{1 9726 9727let & cpo = s: keepcpo 9728unlet s: keepcpo 9729 9730" }}} 9731" vim:ts=8 sts=4 sw=4 et fdm=marker