" netrw.vim: Handles file transfer and remote directory listing across " AUTOLOAD SECTION " Date: Oct 02, 2007 " Version: 114 " Maintainer: Charles E Campbell, Jr " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim " Copyright: Copyright (C) 1999-2007 Charles E. Campbell, Jr. {{{1 " Permission is hereby granted to use and distribute this code, " with or without modifications, provided that this copyright " notice is copied with it. Like anything else that's free, " netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided " *as is* and comes with no warranty of any kind, either " expressed or implied. By using this plugin, you agree that " in no event will the copyright holder be liable for any damages " resulting from the use of this software. " of this software. " COMBAK: worked with tmpfile s:GetTempname() in NetRead() NetWrite() " !!NEEDS DEBUGGING && TESTING!!! "redraw!|call inputsave()|call input("Press to continue")|call inputrestore() " " But be doers of the Word, and not only hearers, deluding your own selves {{{1 " (James 1:22 RSV) " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- " Load Once: {{{1 if &cp || exists("g:loaded_netrw") finish endif if !exists("s:NOTE") let s:NOTE = 0 let s:WARNING = 1 let s:ERROR = 2 endif let g:loaded_netrw = "v114" if v:version < 700 call netrw#ErrorMsg(s:WARNING,"you need vim version 7.0 or later for version ".g:loaded_netrw." of netrw",1) finish endif let s:keepcpo= &cpo setlocal cpo&vim "DechoTabOn "call Decho("doing autoload/netrw.vim version ".g:loaded_netrw) " ====================== " Netrw Variables: {{{1 " ====================== " --------------------------------------------------------------------- " Netrw Constants: {{{2 if !exists("g:NETRW_BOOKMARKMAX") let g:NETRW_BOOKMARKMAX= 0 endif if !exists("g:NETRW_DIRHIST_CNT") let g:NETRW_DIRHIST_CNT= 0 endif if !exists("s:LONGLIST") let s:THINLIST = 0 let s:LONGLIST = 1 let s:WIDELIST = 2 let s:TREELIST = 3 let s:MAXLIST = 4 endif " --------------------------------------------------------------------- " Default values for netrw's global protocol variables {{{2 if !exists("g:netrw_dav_cmd") let g:netrw_dav_cmd = "cadaver" endif if !exists("g:netrw_fetch_cmd") if executable("fetch") let g:netrw_fetch_cmd = "fetch -o" else let g:netrw_fetch_cmd = "" endif endif if !exists("g:netrw_ftp_cmd") let g:netrw_ftp_cmd = "ftp" endif if !exists("g:netrw_http_cmd") if executable("curl") let g:netrw_http_cmd = "curl -o" elseif executable("wget") let g:netrw_http_cmd = "wget -q -O" elseif executable("fetch") let g:netrw_http_cmd = "fetch -o" else let g:netrw_http_cmd = "" endif endif if !exists("g:netrw_rcp_cmd") let g:netrw_rcp_cmd = "rcp" endif if !exists("g:netrw_rsync_cmd") let g:netrw_rsync_cmd = "rsync" endif if !exists("g:netrw_scp_cmd") let g:netrw_scp_cmd = "scp -q" endif if !exists("g:netrw_sftp_cmd") let g:netrw_sftp_cmd = "sftp" endif if !exists("g:netrw_ssh_cmd") let g:netrw_ssh_cmd= "ssh" endif if (has("win32") || has("win95") || has("win64") || has("win16")) \ && exists("g:netrw_use_nt_rcp") \ && g:netrw_use_nt_rcp \ && executable( $SystemRoot .'/system32/rcp.exe') let s:netrw_has_nt_rcp = 1 let s:netrw_rcpmode = '-b' else let s:netrw_has_nt_rcp = 0 let s:netrw_rcpmode = '' endif " --------------------------------------------------------------------- " Default values for netrw's global variables {{{2 " Cygwin Detection ------- {{{3 if !exists("g:netrw_cygwin") if has("win32") || has("win95") || has("win64") || has("win16") if &shell =~ '\%(\\|\\)\%(\.exe\)\=$' let g:netrw_cygwin= 1 else let g:netrw_cygwin= 0 endif else let g:netrw_cygwin= 0 endif endif " Default values - a-c ---------- {{{3 if !exists("g:netrw_alto") let g:netrw_alto= &sb endif if !exists("g:netrw_altv") let g:netrw_altv= &spr endif if !exists("g:netrw_browse_split") let g:netrw_browse_split= 0 endif if !exists("g:netrw_chgwin") let g:netrw_chgwin = -1 endif if !exists("g:netrw_compress") let g:netrw_compress= "gzip" endif " Default values - d-f ---------- {{{3 if !exists("g:NETRW_DIRHIST_CNT") let g:NETRW_DIRHIST_CNT= 0 endif if !exists("g:netrw_decompress") let g:netrw_decompress= { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf"} endif if !exists("g:netrw_dirhistmax") let g:netrw_dirhistmax= 10 endif if !exists("g:netrw_ftp_browse_reject") let 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$' endif if !exists("g:netrw_ftp_list_cmd") if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin) let g:netrw_ftp_list_cmd = "ls -lF" let g:netrw_ftp_timelist_cmd = "ls -tlF" let g:netrw_ftp_sizelist_cmd = "ls -slF" else let g:netrw_ftp_list_cmd = "dir" let g:netrw_ftp_timelist_cmd = "dir" let g:netrw_ftp_sizelist_cmd = "dir" endif endif if !exists("g:netrw_ftpmode") let g:netrw_ftpmode= "binary" endif " Default values - h-lh ---------- {{{3 if !exists("g:netrw_hide") let g:netrw_hide= 1 endif if !exists("g:netrw_ignorenetrc") if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$' let g:netrw_ignorenetrc= 1 else let g:netrw_ignorenetrc= 0 endif endif if !exists("g:netrw_keepdir") let g:netrw_keepdir= 1 endif if !exists("g:netrw_list_cmd") if g:netrw_scp_cmd =~ '^pscp' && executable("pscp") " provide a 'pscp' listing command if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk") let g:netrw_scp_cmd ="pscp -i C:\\private.ppk" endif let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:" elseif executable(g:netrw_ssh_cmd) " provide a default listing command let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa" else " call Decho(g:netrw_ssh_cmd." is not executable") let g:netrw_list_cmd= "" endif endif if !exists("g:netrw_list_hide") let g:netrw_list_hide= "" endif " Default values - lh-lz ---------- {{{3 if !exists("g:netrw_localcopycmd") if has("win32") || has("win95") || has("win64") || has("win16") if g:netrw_cygwin let g:netrw_localcopycmd= "cp" else let g:netrw_localcopycmd= "copy" endif elseif has("unix") || has("macunix") let g:netrw_localcopycmd= "cp" else let g:netrw_localcopycmd= "" endif endif if !exists("g:netrw_local_mkdir") let g:netrw_local_mkdir= "mkdir" endif if !exists("g:netrw_localmovecmd") if has("win32") || has("win95") || has("win64") || has("win16") if g:netrw_cygwin let g:netrw_localcopycmd= "mv" else let g:netrw_localcopycmd= "move" endif elseif has("unix") || has("macunix") let g:netrw_localcopycmd= "mv" else let g:netrw_localcopycmd= "" endif endif if !exists("g:netrw_local_rmdir") let g:netrw_local_rmdir= "rmdir" endif if !exists("g:netrw_liststyle") let g:netrw_liststyle= s:THINLIST endif if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST " sanity check let g:netrw_liststyle= s:THINLIST endif if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp' let g:netrw_list_cmd= g:netrw_list_cmd." -l" endif " Default values - m-r ---------- {{{3 if !exists("g:netrw_maxfilenamelen") let g:netrw_maxfilenamelen= 32 endif if !exists("g:netrw_menu") let g:netrw_menu= 1 endif if !exists("g:netrw_mkdir_cmd") let g:netrw_mkdir_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir" endif if !exists("g:netrw_mousemaps") if exists("&mouse") && &mouse =~ '[anh]' let g:netrw_mousemaps= 1 else let g:netrw_mousemaps= 0 endif endif if !exists("g:netrw_noretmap") let g:netrw_noretmap= 0 endif if !exists("g:netrw_preview") let g:netrw_preview= 0 endif if !exists("g:netrw_scpport") let g:netrw_scpport= "-P" endif if !exists("g:netrw_sshport") let g:netrw_sshport= "-p" endif if !exists("g:netrw_rename_cmd") let g:netrw_rename_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME mv" endif if !exists("g:netrw_rm_cmd") let g:netrw_rm_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rm" endif if !exists("g:netrw_rmdir_cmd") let g:netrw_rmdir_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir" endif if !exists("g:netrw_rmf_cmd") let g:netrw_rmf_cmd = g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f" endif " Default values - s ---------- {{{3 if exists("g:netrw_silent") && g:netrw_silent != 0 let g:netrw_silentxfer= "silent " else let g:netrw_silentxfer= "" endif if !exists("g:netrw_fastbrowse") let g:netrw_fastbrowse= 1 endif if !exists("g:netrw_shq") if exists("&shq") && &shq != "" let g:netrw_shq= &shq elseif has("win32") || has("win95") || has("win64") || has("win16") if g:netrw_cygwin let g:netrw_shq= "'" else let g:netrw_shq= '"' endif else let g:netrw_shq= "'" endif " call Decho("g:netrw_shq<".g:netrw_shq.">") endif if !exists("g:netrw_sort_by") " alternatives: date size let g:netrw_sort_by= "name" endif if !exists("g:netrw_sort_direction") " alternative: reverse (z y x ...) let g:netrw_sort_direction= "normal" endif if !exists("g:netrw_sort_sequence") let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,\.[a-np-z]$,*,\.info$,\.swp$,\.o$\.obj$,\.bak$' endif if !exists("g:netrw_ssh_browse_reject") let g:netrw_ssh_browse_reject='^total\s\+\d\+$' endif if !has("patch192") if !exists("g:netrw_use_noswf") let g:netrw_use_noswf= 1 endif else let g:netrw_use_noswf= 0 endif " Default values - t-w ---------- {{{3 if !exists("g:netrw_ctags") let g:netrw_ctags= "ctags" endif if !exists("g:netrw_timefmt") let g:netrw_timefmt= "%c" endif if !exists("g:NetrwTopLvlMenu") let g:NetrwTopLvlMenu= "Netrw." endif if !exists("g:netrw_use_errorwindow") let g:netrw_use_errorwindow= 1 endif if !exists("g:netrw_win95ftp") let g:netrw_win95ftp= 1 endif if !exists("g:netrw_winsize") let g:netrw_winsize= "" endif " --------------------------------------------------------------------- " Default values for netrw's script variables: {{{2 if !exists("g:netrw_cd_escape") let g:netrw_cd_escape="[]#*$%'\" ?`!&();<>\\" endif if !exists("g:netrw_fname_escape") let g:netrw_fname_escape= ' ?&;' endif if !exists("g:netrw_tmpfile_escape") let g:netrw_tmpfile_escape= ' ?&;' endif if !exists("s:netrw_glob_escape") let s:netrw_glob_escape= '[]*?`{~$' endif " BufEnter event ignored by decho when following variable is true " Has a side effect that doau BufReadPost doesn't work, so " files read by network transfer aren't appropriately highlighted. "let g:decho_bufenter = 1 "Decho " ============================== " Netrw Utility Functions: {{{1 " ============================== " ------------------------------------------------------------------------ " netrw#NetrwSavePosn: saves position of cursor on screen {{{2 fun! netrw#NetrwSavePosn() " call Dfunc("netrw#NetrwSavePosn()") " Save current line and column let w:netrw_winnr= winnr() let w:netrw_line = line(".") let w:netrw_col = virtcol(".") " Save top-of-screen line norm! H0 let w:netrw_hline= line(".") " set up string holding position parameters let ret = "let w:netrw_winnr=".w:netrw_winnr."|let w:netrw_line=".w:netrw_line."|let w:netrw_col=".w:netrw_col."|let w:netrw_hline=".w:netrw_hline call netrw#NetrwRestorePosn() " call Dret("netrw#NetrwSavePosn : winnr=".w:netrw_winnr." line=".w:netrw_line." col=".w:netrw_col." hline=".w:netrw_hline) return ret endfun " ------------------------------------------------------------------------ " netrw#NetrwRestorePosn: restores the cursor and file position as saved by NetrwSavePosn() {{{2 fun! netrw#NetrwRestorePosn(...) " call Dfunc("netrw#NetrwRestorePosn() a:0=".a:0." winnr=".(exists("w:netrw_winnr")? w:netrw_winnr : -1)." line=".(exists("w:netrw_line")? w:netrw_line : -1)." col=".(exists("w:netrw_col")? w:netrw_col : -1)." hline=".(exists("w:netrw_hline")? w:netrw_hline : -1)) let eikeep= &ei set ei=all if expand("%") == "NetrwMessage" exe s:winBeforeErr."wincmd w" endif if a:0 > 0 exe a:1 endif " restore window if exists("w:netrw_winnr") " call Decho("restore window: exe silent! ".w:netrw_winnr."wincmd w") exe "silent! ".w:netrw_winnr."wincmd w" endif if v:shell_error == 0 " as suggested by Bram M: redraw on no error " allows protocol error messages to remain visible redraw! endif " restore top-of-screen line if exists("w:netrw_hline") " call Decho("restore topofscreen: exe norm! ".w:netrw_hline."G0z") exe "norm! ".w:netrw_hline."G0z\" endif " restore position if exists("w:netrw_line") && exists("w:netrw_col") " call Decho("restore posn: exe norm! ".w:netrw_line."G0".w:netrw_col."|") exe "norm! ".w:netrw_line."G0".w:netrw_col."\" endif let &ei= eikeep " call Dret("netrw#NetrwRestorePosn") endfun " --------------------------------------------------------------------- " s:NetrwOptionSave: save options and set to "standard" form {{{2 " 06/08/07 : removed call to NetrwSafeOptions(), either placed " immediately after NetrwOptionSave() calls in NetRead " and NetWrite, or after the s:NetrwEnew() call in " NetrwBrowse. " vt: normally its "w:" or "s:" (a variable type) fun! s:NetrwOptionSave(vt) " call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr(".")) if !exists("{a:vt}netrw_optionsave") let {a:vt}netrw_optionsave= 1 " call Decho(a:vt."netrw_optionsave=".{a:vt}netrw_optionsave) else " call Dret("s:NetrwOptionSave : netoptionsave=".{a:vt}netrw_optionsave." (options already saved)") return endif " Save current settings and current directory let s:yykeep = @@ if exists("&l:acd") let {a:vt}netrw_acdkeep = &l:acd endif let {a:vt}netrw_aikeep = &l:ai let {a:vt}netrw_awkeep = &l:aw let {a:vt}netrw_cikeep = &l:ci let {a:vt}netrw_cinkeep = &l:cin let {a:vt}netrw_cinokeep = &l:cino let {a:vt}netrw_comkeep = &l:com let {a:vt}netrw_cpokeep = &l:cpo if g:netrw_keepdir let {a:vt}netrw_dirkeep = getcwd() endif let {a:vt}netrw_fokeep = &l:fo " formatoptions let {a:vt}netrw_gdkeep = &l:gd " gdefault let {a:vt}netrw_hidkeep = &l:hidden let {a:vt}netrw_magickeep = &l:magic let {a:vt}netrw_repkeep = &l:report let {a:vt}netrw_spellkeep = &l:spell let {a:vt}netrw_twkeep = &l:tw " textwidth let {a:vt}netrw_wigkeep = &l:wig " wildignore if has("win32") && !has("win95") let {a:vt}netrw_swfkeep= &l:swf " swapfile endif if &go =~ 'a' | silent! let {a:vt}netrw_regstar = @* | endif silent! let {a:vt}netrw_regslash= @/ " call s:NetrwSafeOptions() " call Dret("s:NetrwOptionSave : win#".winnr()." buf#".bufnr(".")) endfun " ------------------------------------------------------------------------ " s:NetrwOptionRestore: restore options {{{2 fun! s:NetrwOptionRestore(vt) " call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr(".")) if !exists("{a:vt}netrw_optionsave") " call Dret("s:NetrwOptionRestore : {a:vt}netrw_optionsave doesn't exist") return endif unlet {a:vt}netrw_optionsave if exists("&acd") if exists("{a:vt}netrw_acdkeep") |let &l:acd = {a:vt}netrw_acdkeep |unlet {a:vt}netrw_acdkeep |endif endif if exists("{a:vt}netrw_aikeep") |let &l:ai = {a:vt}netrw_aikeep |unlet {a:vt}netrw_aikeep |endif if exists("{a:vt}netrw_awkeep") |let &l:aw = {a:vt}netrw_awkeep |unlet {a:vt}netrw_awkeep |endif if exists("{a:vt}netrw_cikeep") |let &l:ci = {a:vt}netrw_cikeep |unlet {a:vt}netrw_cikeep |endif if exists("{a:vt}netrw_cinkeep") |let &l:cin = {a:vt}netrw_cinkeep |unlet {a:vt}netrw_cinkeep |endif if exists("{a:vt}netrw_cinokeep") |let &l:cino = {a:vt}netrw_cinokeep |unlet {a:vt}netrw_cinokeep |endif if exists("{a:vt}netrw_comkeep") |let &l:com = {a:vt}netrw_comkeep |unlet {a:vt}netrw_comkeep |endif if exists("{a:vt}netrw_cpokeep") |let &l:cpo = {a:vt}netrw_cpokeep |unlet {a:vt}netrw_cpokeep |endif if exists("{a:vt}netrw_dirkeep") |exe "lcd ".{a:vt}netrw_dirkeep |unlet {a:vt}netrw_dirkeep |endif if exists("{a:vt}netrw_fokeep") |let &l:fo = {a:vt}netrw_fokeep |unlet {a:vt}netrw_fokeep |endif if exists("{a:vt}netrw_gdkeep") |let &l:gd = {a:vt}netrw_gdkeep |unlet {a:vt}netrw_gdkeep |endif if exists("{a:vt}netrw_hidkeep") |let &l:hidden = {a:vt}netrw_hidkeep |unlet {a:vt}netrw_hidkeep |endif if exists("{a:vt}netrw_magic") |let &l:magic = {a:vt}netrw_magic |unlet {a:vt}netrw_magic |endif if exists("{a:vt}netrw_repkeep") |let &l:report = {a:vt}netrw_repkeep |unlet {a:vt}netrw_repkeep |endif if exists("{a:vt}netrw_spellkeep")|let &l:spell = {a:vt}netrw_spellkeep |unlet {a:vt}netrw_spellkeep|endif if exists("{a:vt}netrw_twkeep") |let &l:tw = {a:vt}netrw_twkeep |unlet {a:vt}netrw_twkeep |endif if exists("{a:vt}netrw_wigkeep") |let &l:wig = {a:vt}netrw_wigkeep |unlet {a:vt}netrw_wigkeep |endif if exists("s:yykeep") |let @@ = s:yykeep |unlet s:yykeep |endif if exists("{a:vt}netrw_swfkeep") if &directory == "" " user hasn't specified a swapfile directory; " netrw will temporarily set the swapfile directory " to the current directory as returned by getcwd(). let &l:directory = getcwd() silent! let &l:swf = {a:vt}netrw_swfkeep setlocal directory= unlet {a:vt}netrw_swfkeep elseif &l:swf != {a:vt}netrw_swfkeep " following line causes a Press ENTER in windows -- can't seem to work around it!!! (COMBAK) silent! let &l:swf= {a:vt}netrw_swfkeep unlet {a:vt}netrw_swfkeep endif endif if exists("{a:vt}netrw_regstar") |silent! let @*= {a:vt}netrw_regstar |unlet {a:vt}netrw_regstar |endif if exists("{a:vt}netrw_regslash")|silent! let @/= {a:vt}netrw_regslash|unlet {a:vt}netrw_regslash|endif " call Dret("s:NetrwOptionRestore : win#".winnr()." buf#".bufnr(".")) endfun " --------------------------------------------------------------------- " s:NetrwSafeOptions: sets options to help netrw do its job {{{2 fun! s:NetrwSafeOptions() " call Dfunc("s:NetrwSafeOptions()") setlocal cino= setlocal com= setlocal cpo-=aA if exists("&acd") setlocal noacd nocin noai noci magic nospell nohid wig= noaw setlocal fo=nroql2 else setlocal nocin noai noci magic nospell nohid wig= noaw setlocal fo=nroql2 endif setlocal tw=0 setlocal report=10000 if g:netrw_use_noswf && has("win32") && !has("win95") setlocal noswf endif " call Dret("s:NetrwSafeOptions") endfun " --------------------------------------------------------------------- " netrw#NetrwClean: remove netrw {{{2 " supports :NetrwClean -- remove netrw from first directory on runtimepath " :NetrwClean! -- remove netrw from all directories on runtimepath fun! netrw#NetrwClean(sys) " call Dfunc("netrw#NetrwClean(sys=".a:sys.")") if a:sys let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No") else let choice= confirm("Remove personal copy of netrw?","&Yes\n&No") endif " call Decho("choice=".choice) let diddel= 0 let diddir= "" if choice == 1 for dir in split(&rtp,',') if filereadable(dir."/plugin/netrwPlugin.vim") " call Decho("removing netrw-related files from ".dir) if s:System("delete",dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif if s:System("delete",dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif if s:System("delete",dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif if s:System("delete",dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif if s:System("delete",dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif if s:System("delete",dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif let diddir= dir let diddel= diddel + 1 if !a:sys|break|endif endif endfor endif echohl WarningMsg if diddel == 0 echomsg "netrw is either not installed or not removable" elseif diddel == 1 echomsg "removed one copy of netrw from <".diddir.">" else echomsg "removed ".diddel." copies of netrw" endif echohl None " call Dret("netrw#NetrwClean") endfun " ------------------------------------------------------------------------ " Netrw Transfer Functions: {{{1 " =============================== " ------------------------------------------------------------------------ " netrw#NetRead: responsible for reading a file over the net {{{2 " mode: =0 read remote file and insert before current line " =1 read remote file and insert after current line " =2 replace with remote file " =3 obtain file, but leave in temporary format fun! netrw#NetRead(mode,...) " call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw) " save options {{{3 call s:NetrwOptionSave("w:") call s:NetrwSafeOptions() " interpret mode into a readcmd {{{3 if a:mode == 0 " read remote file before current line let readcmd = "0r" elseif a:mode == 1 " read file after current line let readcmd = "r" elseif a:mode == 2 " replace with remote file let readcmd = "%r" elseif a:mode == 3 " skip read of file (leave as temporary) let readcmd = "t" else exe a:mode let readcmd = "r" endif let ichoice = (a:0 == 0)? 0 : 1 " call Decho("readcmd<".readcmd."> ichoice=".ichoice) " Get Temporary Filename {{{3 let tmpfile= s:GetTempfile("") if tmpfile == "" " call Dret("netrw#NetRead : unable to get a tempfile!") return endif while ichoice <= a:0 " attempt to repeat with previous host-file-etc if exists("b:netrw_lastfile") && a:0 == 0 " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") let choice = b:netrw_lastfile let ichoice= ichoice + 1 else exe "let choice= a:" . ichoice " call Decho("no lastfile: choice<" . choice . ">") if match(choice,"?") == 0 " give help echomsg 'NetRead Usage:' echomsg ':Nread machine:path uses rcp' echomsg ':Nread "machine path" uses ftp with <.netrc>' echomsg ':Nread "machine id password path" uses ftp' echomsg ':Nread dav://machine[:port]/path uses cadaver' echomsg ':Nread fetch://machine/path uses fetch' echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' echomsg ':Nread http://[user@]machine/path uses http wget' echomsg ':Nread rcp://[user@]machine/path uses rcp' echomsg ':Nread rsync://machine[:port]/path uses rsync' echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp' echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' sleep 4 break elseif match(choice,'^"') != -1 " Reconstruct Choice if choice starts with '"' " call Decho("reconstructing choice") if match(choice,'"$') != -1 " case "..." let choice=strpart(choice,1,s:Strlen(choice)-2) else " case "... ... ..." let choice = strpart(choice,1,s:Strlen(choice)-1) let wholechoice = "" while match(choice,'"$') == -1 let wholechoice = wholechoice . " " . choice let ichoice = ichoice + 1 if ichoice > a:0 if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3) endif " call Dret("netrw#NetRead :2 getcwd<".getcwd().">") return endif let choice= a:{ichoice} endwhile let choice= strpart(wholechoice,1,s:Strlen(wholechoice)-1) . " " . strpart(choice,0,s:Strlen(choice)-1) endif endif endif " call Decho("choice<" . choice . ">") let ichoice= ichoice + 1 " Determine method of read (ftp, rcp, etc) {{{3 call s:NetrwMethod(choice) let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix " Check if NetrwBrowse() should be handling this request " call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">") if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^http://' " call Decho("yes, choice matches '^.*[\/]$'") keepjumps call s:NetrwBrowse(0,choice) " call Dret("netrw#NetRead :3 getcwd<".getcwd().">") return endif " ============ " Perform Protocol-Based Read {{{3 " =========================== if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 echo "(netrw) Processing your read request..." endif "......................................... " rcp: NetRead Method #1 {{{3 if b:netrw_method == 1 " read with rcp " call Decho("read via rcp (method #1)") " ER: nothing done with g:netrw_uid yet? " ER: on Win2K" rcp machine[.user]:file tmpfile " ER: if machine contains '.' adding .user is required (use $USERNAME) " ER: the tmpfile is full path: rcp sees C:\... as host C if s:netrw_has_nt_rcp == 1 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) let uid_machine = g:netrw_machine .'.'. g:netrw_uid else " Any way needed it machine contains a '.' let uid_machine = g:netrw_machine .'.'. $USERNAME endif else if exists("g:netrw_uid") && ( g:netrw_uid != "" ) let uid_machine = g:netrw_uid .'@'. g:netrw_machine else let uid_machine = g:netrw_machine endif endif " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile) exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&;')." ".tmpfile let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " ftp + <.netrc>: NetRead Method #2 {{{3 elseif b:netrw_method == 2 " read with ftp + <.netrc> " call Decho("read via ftp+.netrc (method #2)") let netrw_fname= b:netrw_fname new setlocal ff=unix exe "put ='".g:netrw_ftpmode."'" " call Decho("filter input: ".getline(".")) if exists("g:netrw_ftpextracmd") exe "put ='".g:netrw_ftpextracmd."'" " call Decho("filter input: ".getline(".")) endif exe "put ='".'get \"'.netrw_fname.'\" '.tmpfile."'" " call Decho("filter input: ".getline(".")) if exists("g:netrw_port") && g:netrw_port != "" " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port else " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine endif " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying ' let debugkeep= &debug setlocal debug=msg call netrw#ErrorMsg(s:ERROR,getline(1),4) let &debug= debugkeep endif bd! let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " ftp + machine,id,passwd,filename: NetRead Method #3 {{{3 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname " Construct execution string (four lines) which will be passed through filter " call Decho("read via ftp+mipf (method #3)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) new setlocal ff=unix if exists("g:netrw_port") && g:netrw_port != "" put ='open '.g:netrw_machine.' '.g:netrw_port " call Decho("filter input: ".getline(".")) else put ='open '.g:netrw_machine " call Decho("filter input: ".getline(".")) endif if exists("g:netrw_ftp") && g:netrw_ftp == 1 put =g:netrw_uid " call Decho("filter input: ".getline(".")) put ='\"'.g:netrw_passwd.'\"' " call Decho("filter input: ".getline(".")) else put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' " call Decho("filter input: ".getline(".")) endif if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" put =g:netrw_ftpmode " call Decho("filter input: ".getline(".")) endif if exists("g:netrw_ftpextracmd") exe "put ='".g:netrw_ftpextracmd."'" " call Decho("filter input: ".getline(".")) endif put ='get \"'.netrw_fname.'\" '.tmpfile " call Decho("filter input: ".getline(".")) " perform ftp: " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password norm! 1Gdd " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" " call Decho("error<".getline(1).">") if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,getline(1),5) endif endif bd! let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " scp: NetRead Method #4 {{{3 elseif b:netrw_method == 4 " read with scp " call Decho("read via scp (method #4)") if exists("g:netrw_port") && g:netrw_port != "" let useport= " ".g:netrw_scpport." ".g:netrw_port else let useport= "" endif " call Decho("executing: !".g:netrw_scp_cmd.useport." '".g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape)."' ".tmpfile) exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.g:netrw_machine.":".escape(b:netrw_fname,g:netrw_fname_escape).g:netrw_shq." ".tmpfile let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " http: NetRead Method #5 (wget) {{{3 elseif b:netrw_method == 5 " call Decho("read via http (method #5)") if g:netrw_http_cmd == "" if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6) endif " call Dret("netrw#NetRead :4 getcwd<".getcwd().">") return endif if match(b:netrw_fname,"#") == -1 " simple wget let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname) exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_fname let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) else " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) let netrw_html= substitute(netrw_fname,"#.*$","","") let netrw_tag = substitute(netrw_fname,"^.*#","","") " call Decho("netrw_html<".netrw_html.">") " call Decho("netrw_tag <".netrw_tag.">") " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html) exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) " call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/') exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\" endif let b:netrw_lastfile = choice setlocal ro "......................................... " cadaver: NetRead Method #6 {{{3 elseif b:netrw_method == 6 " call Decho("read via cadaver (method #6)") " Construct execution string (four lines) which will be passed through filter let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) new setlocal ff=unix if exists("g:netrw_port") && g:netrw_port != "" put ='open '.g:netrw_machine.' '.g:netrw_port else put ='open '.g:netrw_machine endif put ='user '.g:netrw_uid.' '.g:netrw_passwd put ='get '.netrw_fname.' '.tmpfile put ='quit' " perform cadaver operation: norm! 1Gdd " call Decho("executing: %!".g:netrw_dav_cmd) exe g:netrw_silentxfer."%!".g:netrw_dav_cmd bd! let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " rsync: NetRead Method #7 {{{3 elseif b:netrw_method == 7 " call Decho("read via rsync (method #7)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) " call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile) exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " fetch: NetRead Method #8 {{{3 " fetch://[user@]host[:http]/path elseif b:netrw_method == 8 " call Decho("read via fetch (method #8)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) if g:netrw_fetch_cmd == "" if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"fetch command not available",7) endif " call Dret("NetRead") endif if exists("g:netrw_option") && g:netrw_option == ":http" let netrw_option= "http" else let netrw_option= "ftp" endif " call Decho("read via fetch for ".netrw_option) if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != "" " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname) exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".netrw_fname else " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname) exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".netrw_fname endif let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method) let b:netrw_lastfile = choice setlocal ro "......................................... " sftp: NetRead Method #9 {{{3 elseif b:netrw_method == 9 " call Decho("read via sftp (method #9)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) " call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile) exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".netrw_fname." ".tmpfile let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method) let b:netrw_lastfile = choice "......................................... " Complain {{{3 else call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8) endif endwhile " cleanup {{{3 if exists("b:netrw_method") " call Decho("cleanup b:netrw_method and b:netrw_fname") unlet b:netrw_method unlet b:netrw_fname endif if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' " call Decho("cleanup by deleting tmpfile<".tmpfile.">") call s:System("delete",tmpfile) endif call s:NetrwOptionRestore("w:") " call Dret("netrw#NetRead :5 getcwd<".getcwd().">") endfun " ------------------------------------------------------------------------ " netrw#NetWrite: responsible for writing a file over the net {{{2 fun! netrw#NetWrite(...) range " call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw) " option handling let mod= 0 call s:NetrwOptionSave("w:") call s:NetrwSafeOptions() " Get Temporary Filename {{{3 let tmpfile= s:GetTempfile("") if tmpfile == "" " call Dret("netrw#NetWrite : unable to get a tempfile!") return endif if a:0 == 0 let ichoice = 0 else let ichoice = 1 endif let curbufname= expand("%") " call Decho("curbufname<".curbufname.">") if &binary " For binary writes, always write entire file. " (line numbers don't really make sense for that). " Also supports the writing of tar and zip files. " call Decho("(write entire file) silent exe w! ".v:cmdarg." ".tmpfile) silent exe "w! ".v:cmdarg." ".tmpfile elseif g:netrw_cygwin " write (selected portion of) file to temporary let cygtmpfile= substitute(tmpfile,'/cygdrive/\(.\)','\1:','') " call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".cygtmpfile) silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".cygtmpfile else " write (selected portion of) file to temporary " call Decho("(write selected portion) silent exe ".a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile) silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile endif if curbufname == "" " if the file is [No Name], and one attempts to Nwrite it, the buffer takes " on the temporary file's name. Deletion of the temporary file during " cleanup then causes an error message. 0file! endif " While choice loop: {{{3 while ichoice <= a:0 " Process arguments: {{{4 " attempt to repeat with previous host-file-etc if exists("b:netrw_lastfile") && a:0 == 0 " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") let choice = b:netrw_lastfile let ichoice= ichoice + 1 else exe "let choice= a:" . ichoice " Reconstruct Choice if choice starts with '"' if match(choice,"?") == 0 echomsg 'NetWrite Usage:"' echomsg ':Nwrite machine:path uses rcp' echomsg ':Nwrite "machine path" uses ftp with <.netrc>' echomsg ':Nwrite "machine id password path" uses ftp' echomsg ':Nwrite dav://[user@]machine/path uses cadaver' echomsg ':Nwrite fetch://[user@]machine/path uses fetch' echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' echomsg ':Nwrite rcp://machine/path uses rcp' echomsg ':Nwrite rsync://[user@]machine/path uses rsync' echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' echomsg ':Nwrite sftp://[user@]machine/path uses sftp' sleep 4 break elseif match(choice,"^\"") != -1 if match(choice,"\"$") != -1 " case "..." let choice=strpart(choice,1,s:Strlen(choice)-2) else " case "... ... ..." let choice = strpart(choice,1,s:Strlen(choice)-1) let wholechoice = "" while match(choice,"\"$") == -1 let wholechoice= wholechoice . " " . choice let ichoice = ichoice + 1 if choice > a:0 if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13) endif " call Dret("netrw#NetWrite") return endif let choice= a:{ichoice} endwhile let choice= strpart(wholechoice,1,s:Strlen(wholechoice)-1) . " " . strpart(choice,0,s:Strlen(choice)-1) endif endif endif let ichoice= ichoice + 1 " call Decho("choice<" . choice . "> ichoice=".ichoice) " Determine method of write (ftp, rcp, etc) {{{4 call s:NetrwMethod(choice) " ============= " Perform Protocol-Based Write {{{4 " ============================ if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 echo "(netrw) Processing your write request..." endif "......................................... " rcp: NetWrite Method #1 {{{4 if b:netrw_method == 1 " call Decho("write via rcp (method #1)") if s:netrw_has_nt_rcp == 1 if exists("g:netrw_uid") && ( g:netrw_uid != "" ) let uid_machine = g:netrw_machine .'.'. g:netrw_uid else let uid_machine = g:netrw_machine .'.'. $USERNAME endif else if exists("g:netrw_uid") && ( g:netrw_uid != "" ) let uid_machine = g:netrw_uid .'@'. g:netrw_machine else let uid_machine = g:netrw_machine endif endif let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".g:netrw_shq.tmpfile.g:netrw_shq." ".uid_machine.":".netrw_fname) exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".g:netrw_shq.tmpfile.g:netrw_shq." ".uid_machine.":".netrw_fname let b:netrw_lastfile = choice "......................................... " ftp + <.netrc>: NetWrite Method #2 {{{4 elseif b:netrw_method == 2 " call Decho("write via ftp+.netrc (method #2)") let netrw_fname= b:netrw_fname new setlocal ff=unix exe "put ='".g:netrw_ftpmode."'" " call Decho(" filter input: ".getline(".")) if exists("g:netrw_ftpextracmd") exe "put ='".g:netrw_ftpextracmd."'" " call Decho("filter input: ".getline(".")) endif exe "put ='".'put \"'.tmpfile.'\" \"'.netrw_fname.'\"'."'" " call Decho(" filter input: ".getline(".")) if exists("g:netrw_port") && g:netrw_port != "" " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port else " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine endif " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,getline(1),14) endif let mod=1 endif bd! let b:netrw_lastfile = choice "......................................... " ftp + machine, id, passwd, filename: NetWrite Method #3 {{{4 elseif b:netrw_method == 3 " Construct execution string (four lines) which will be passed through filter " call Decho("read via ftp+mipf (method #3)") let netrw_fname= b:netrw_fname new setlocal ff=unix if exists("g:netrw_port") && g:netrw_port != "" put ='open '.g:netrw_machine.' '.g:netrw_port " call Decho("filter input: ".getline(".")) else put ='open '.g:netrw_machine " call Decho("filter input: ".getline(".")) endif if exists("g:netrw_ftp") && g:netrw_ftp == 1 put =g:netrw_uid " call Decho("filter input: ".getline(".")) put ='\"'.g:netrw_passwd.'\"' " call Decho("filter input: ".getline(".")) else put ='user \"'.g:netrw_uid.'\" \"'.g:netrw_passwd.'\"' " call Decho("filter input: ".getline(".")) endif put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"' " call Decho("filter input: ".getline(".")) " save choice/id/password for future use let b:netrw_lastfile = choice " perform ftp: " -i : turns off interactive prompting from ftp " -n unix : DON'T use <.netrc>, even though it exists " -n win32: quit being obnoxious about password norm! 1Gdd " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) if getline(1) !~ "^$" if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,getline(1),15) endif let mod=1 endif bd! "......................................... " scp: NetWrite Method #4 {{{4 elseif b:netrw_method == 4 " call Decho("write via scp (method #4)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) if exists("g:netrw_port") && g:netrw_port != "" let useport= " ".g:netrw_scpport." ".g:netrw_port else let useport= "" endif " call Decho("exe ".g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.tmpfile.g:netrw_shq." ".g:netrw_shq.g:netrw_machine.":".netrw_fname.g:netrw_shq) exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_shq.tmpfile.g:netrw_shq." ".g:netrw_shq.g:netrw_machine.":".netrw_fname.g:netrw_shq let b:netrw_lastfile = choice "......................................... " http: NetWrite Method #5 {{{4 elseif b:netrw_method == 5 " call Decho("write via http (method #5)") if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"currently does not support writing using http:",16) endif "......................................... " dav: NetWrite Method #6 (cadaver) {{{4 elseif b:netrw_method == 6 " call Decho("write via cadaver (method #6)") " Construct execution string (four lines) which will be passed through filter let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) new setlocal ff=unix if exists("g:netrw_port") && g:netrw_port != "" put ='open '.g:netrw_machine.' '.g:netrw_port else put ='open '.g:netrw_machine endif put ='user '.g:netrw_uid.' '.g:netrw_passwd put ='put '.tmpfile.' '.netrw_fname " perform cadaver operation: norm! 1Gdd " call Decho("executing: %!".g:netrw_dav_cmd) exe g:netrw_silentxfer."%!".g:netrw_dav_cmd bd! let b:netrw_lastfile = choice "......................................... " rsync: NetWrite Method #7 {{{4 elseif b:netrw_method == 7 " call Decho("write via rsync (method #7)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) " call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname) exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".netrw_fname let b:netrw_lastfile = choice "......................................... " sftp: NetWrite Method #9 {{{4 elseif b:netrw_method == 9 " call Decho("read via sftp (method #9)") let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape) if exists("g:netrw_uid") && ( g:netrw_uid != "" ) let uid_machine = g:netrw_uid .'@'. g:netrw_machine else let uid_machine = g:netrw_machine endif new setlocal ff=unix put ='put \"'.escape(tmpfile,'\').'\" '.netrw_fname " call Decho("filter input: ".getline(".")) norm! 1Gdd " call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine) exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine bd! let b:netrw_lastfile= choice "......................................... " Complain {{{4 else call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17) endif endwhile " Cleanup: {{{3 " call Decho("cleanup") if s:FileReadable(tmpfile) " call Decho("tmpfile<".tmpfile."> readable, will now delete it") call s:System("delete",tmpfile) endif call s:NetrwOptionRestore("w:") if a:firstline == 1 && a:lastline == line("$") " restore modifiability; usually equivalent to set nomod let &mod= mod endif " call Dret("netrw#NetWrite") endfun " --------------------------------------------------------------------- " netrw#NetSource: source a remotely hosted vim script {{{2 " uses NetRead to get a copy of the file into a temporarily file, " then sources that file, " then removes that file. fun! netrw#NetSource(...) " call Dfunc("netrw#NetSource() a:0=".a:0) if a:0 > 0 && a:1 == '?' " give help echomsg 'NetSource Usage:' echomsg ':Nsource dav://machine[:port]/path uses cadaver' echomsg ':Nsource fetch://machine/path uses fetch' echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' echomsg ':Nsource http://[user@]machine/path uses http wget' echomsg ':Nsource rcp://[user@]machine/path uses rcp' echomsg ':Nsource rsync://machine[:port]/path uses rsync' echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp' echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp' sleep 4 else let i= 1 while i <= a:0 call netrw#NetRead(3,a:{i}) " call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">") if s:FileReadable(s:netrw_tmpfile) " call Decho("exe so ".s:netrw_tmpfile) exe "so ".s:netrw_tmpfile call delete(s:netrw_tmpfile) unlet s:netrw_tmpfile else call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48) endif let i= i + 1 endwhile endif " call Dret("netrw#NetSource") endfun " =========================================== " s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2 " readcmd == %r : replace buffer with newly read file " == 0r : read file at top of buffer " == r : read file after current line " == t : leave file in temporary form (ie. don't read into buffer) fun! s:NetrwGetFile(readcmd, tfile, method) " call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)") " readcmd=='t': simply do nothing if a:readcmd == 't' " call Dret("NetrwGetFile : skip read of <".a:tfile.">") return endif " get name of remote filename (ie. url and all) let rfile= bufname("%") " call Decho("rfile<".rfile.">") if exists("*NetReadFixup") " for the use of NetReadFixup (not otherwise used internally) let line2= line("$") endif if a:readcmd[0] == '%' " get file into buffer " call Decho("get file into buffer") " rename the current buffer to the temp file (ie. tfile) if g:netrw_cygwin let tfile= substitute(a:tfile,'/cygdrive/\(.\)','\1:','') else let tfile= a:tfile endif " call Decho("keepalt exe file ".tfile) keepalt exe "silent! keepalt file ".tfile " edit temporary file (ie. read the temporary file in) if rfile =~ '\.zip$' " call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)") call zip#Browse(tfile) elseif rfile =~ '\.tar$' " call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)") call tar#Browse(tfile) elseif rfile =~ '\.tar\.gz' " call Decho("handling remote gzip-compressed tar file") call tar#Browse(tfile) elseif rfile =~ '\.tar\.bz2' " call Decho("handling remote bz2-compressed tar file") call tar#Browse(tfile) else " call Decho("edit temporary file") e! endif " rename buffer back to remote filename exe "silent! keepalt file ".escape(rfile,' ') filetype detect " call Dredir("renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">","ls!") let line1 = 1 let line2 = line("$") elseif s:FileReadable(a:tfile) " read file after current line " call Decho("read file<".a:tfile."> after current line") let curline = line(".") let lastline= line("$") " call Decho("exe<".a:readcmd." ".v:cmdarg." ".a:tfile."> line#".curline) exe a:readcmd." ".v:cmdarg." ".a:tfile let line1= curline + 1 let line2= line("$") - lastline + 1 else " not readable " call Decho("tfile<".a:tfile."> not readable") call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9) " call Dret("NetrwGetFile : tfile<".a:tfile."> not readable") return endif " User-provided (ie. optional) fix-it-up command if exists("*NetReadFixup") " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")") call NetReadFixup(a:method, line1, line2) " else " Decho " call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")") endif " update the Buffers menu if has("gui") && has("gui_running") silent! emenu Buffers.Refresh\ menu endif " call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile)) " make sure file is being displayed redraw! " call Dret("NetrwGetFile") endfun " ------------------------------------------------------------------------ " s:NetrwMethod: determine method of transfer {{{2 " method == 1: rcp " 2: ftp + <.netrc> " 3: ftp + machine, id, password, and [path]filename " 4: scp " 5: http (wget) " 6: cadaver " 7: rsync " 8: fetch " 9: sftp fun! s:NetrwMethod(choice) " globals: method machine id passwd fname " call Dfunc("NetrwMethod(a:choice<".a:choice.">)") " initialization let b:netrw_method = 0 let g:netrw_machine = "" let b:netrw_fname = "" let g:netrw_port = "" let g:netrw_choice = a:choice " Patterns: " mipf : a:machine a:id password filename Use ftp " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd " rcpurm : rcp://[user@]host/filename Use rcp " rcphf : [user@]host:filename Use rcp " scpurm : scp://[user@]host[[#:]port]/filename Use scp " httpurm : http://[user@]host/filename Use wget " davurm : [s]dav://host[:port]/path Use cadaver " rsyncurm : rsync://host[:port]/path Use rsync " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) " sftpurm : sftp://[user@]host/filename Use scp let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' let mf = '^\(\S\+\)\s\+\(\S\+\)$' let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' let rcpurm = '^rcp://\%(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$' let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$' let davurm = '^s\=dav://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$' let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' " call Decho("determine method:") " Determine Method " rcp://user@hostname/...path-to-file if match(a:choice,rcpurm) == 0 " call Decho("rcp://...") let b:netrw_method = 1 let userid = substitute(a:choice,rcpurm,'\1',"") let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"") let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"") if userid != "" let g:netrw_uid= userid endif " scp://user@hostname/...path-to-file elseif match(a:choice,scpurm) == 0 " call Decho("scp://...") let b:netrw_method = 4 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"") let g:netrw_port = substitute(a:choice,scpurm,'\2',"") let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") " http://user@hostname/...path-to-file elseif match(a:choice,httpurm) == 0 " call Decho("http://...") let b:netrw_method = 5 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"") let b:netrw_fname = substitute(a:choice,httpurm,'\2',"") " dav://hostname[:port]/..path-to-file.. elseif match(a:choice,davurm) == 0 " call Decho("dav://...") let b:netrw_method= 6 if a:choice =~ '^s' let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"") else let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"") endif let b:netrw_fname = substitute(a:choice,davurm,'\3',"") " rsync://user@hostname/...path-to-file elseif match(a:choice,rsyncurm) == 0 " call Decho("rsync://...") let b:netrw_method = 7 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"") let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"") " ftp://[user@]hostname[[:#]port]/...path-to-file elseif match(a:choice,ftpurm) == 0 " call Decho("ftp://...") let userid = substitute(a:choice,ftpurm,'\2',"") let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"") let g:netrw_port = substitute(a:choice,ftpurm,'\4',"") let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"") if userid != "" let g:netrw_uid= userid endif if exists("g:netrw_uid") && exists("g:netrw_passwd") let b:netrw_method = 3 else if s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc let b:netrw_method= 2 else if !exists("g:netrw_uid") || g:netrw_uid == "" call NetUserPass() elseif !exists("g:netrw_passwd") || g:netrw_passwd == "" call NetUserPass(g:netrw_uid) " else just use current g:netrw_uid and g:netrw_passwd endif let b:netrw_method= 3 endif endif elseif match(a:choice,fetchurm) == 0 " call Decho("fetch://...") let b:netrw_method = 8 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"") let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"") let b:netrw_option = substitute(a:choice,fetchurm,'\4',"") let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"") " Issue an ftp : "machine id password [path/]filename" elseif match(a:choice,mipf) == 0 " call Decho("(ftp) host id pass file") let b:netrw_method = 3 let g:netrw_machine = substitute(a:choice,mipf,'\1',"") let g:netrw_uid = substitute(a:choice,mipf,'\2',"") let g:netrw_passwd = substitute(a:choice,mipf,'\3',"") let b:netrw_fname = substitute(a:choice,mipf,'\4',"") " Issue an ftp: "hostname [path/]filename" elseif match(a:choice,mf) == 0 " call Decho("(ftp) host file") if exists("g:netrw_uid") && exists("g:netrw_passwd") let b:netrw_method = 3 let g:netrw_machine = substitute(a:choice,mf,'\1',"") let b:netrw_fname = substitute(a:choice,mf,'\2',"") elseif s:FileReadable(expand("$HOME/.netrc")) let b:netrw_method = 2 let g:netrw_machine = substitute(a:choice,mf,'\1',"") let b:netrw_fname = substitute(a:choice,mf,'\2',"") endif " sftp://user@hostname/...path-to-file elseif match(a:choice,sftpurm) == 0 " call Decho("sftp://...") let b:netrw_method = 9 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"") let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"") " Issue an rcp: hostname:filename" (this one should be last) elseif match(a:choice,rcphf) == 0 " call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">") let b:netrw_method = 1 let userid = substitute(a:choice,rcphf,'\2',"") let g:netrw_machine= substitute(a:choice,rcphf,'\3',"") let b:netrw_fname = substitute(a:choice,rcphf,'\4',"") " call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">") " call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">") " call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">") " call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">") if userid != "" let g:netrw_uid= userid endif else if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:WARNING,"cannot determine method",45) endif let b:netrw_method = -1 endif " remove any leading [:#] from port number if g:netrw_port != "" let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','') endif " call Decho("a:choice <".a:choice.">") " call Decho("b:netrw_method <".b:netrw_method.">") " call Decho("g:netrw_machine<".g:netrw_machine.">") " call Decho("g:netrw_port <".g:netrw_port.">") " if exists("g:netrw_uid") "Decho " call Decho("g:netrw_uid <".g:netrw_uid.">") " endif "Decho " if exists("g:netrw_passwd") "Decho " call Decho("g:netrw_passwd <".g:netrw_passwd.">") " endif "Decho " call Decho("b:netrw_fname <".b:netrw_fname.">") " call Dret("NetrwMethod : b:netrw_method=".b:netrw_method) endfun " ------------------------------------------------------------------------ " NetReadFixup: this sort of function is typically written by the user {{{2 " to handle extra junk that their system's ftp dumps " into the transfer. This function is provided as an " example and as a fix for a Windows 95 problem: in my " experience, win95's ftp always dumped four blank lines " at the end of the transfer. if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp fun! NetReadFixup(method, line1, line2) " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") if method == 3 " ftp (no <.netrc>) let fourblanklines= line2 - 3 silent fourblanklines.",".line2."g/^\s*/d" endif " call Dret("NetReadFixup") endfun endif " --------------------------------------------------------------------- " NetUserPass: set username and password for subsequent ftp transfer {{{2 " Usage: :call NetUserPass() -- will prompt for userid and password " :call NetUserPass("uid") -- will prompt for password " :call NetUserPass("uid","password") -- sets global userid and password fun! NetUserPass(...) " get/set userid if a:0 == 0 " call Dfunc("NetUserPass(a:0<".a:0.">)") if !exists("g:netrw_uid") || g:netrw_uid == "" " via prompt let g:netrw_uid= input('Enter username: ') endif else " from command line " call Dfunc("NetUserPass(a:1<".a:1.">) {") let g:netrw_uid= a:1 endif " get password if a:0 <= 1 " via prompt " call Decho("a:0=".a:0." case <=1:") let g:netrw_passwd= inputsecret("Enter Password: ") else " from command line " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") let g:netrw_passwd=a:2 endif " call Dret("NetUserPass") endfun " =========================================== " Shared Browsing Support: {{{1 " =========================================== " --------------------------------------------------------------------- " s:BrowserMaps: {{{2 fun! s:BrowserMaps(islocal) " call Dfunc("s:BrowserMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">") if a:islocal nnoremap :call netrw#LocalBrowseCheck(NetrwBrowseChgDir(1,NetrwGetWord())) nnoremap - :exe "norm! 0"call netrw#LocalBrowseCheck(NetrwBrowseChgDir(1,'../')) nnoremap a :call NetrwHide(1) nnoremap mb :call NetrwBookmarkDir(0,b:netrw_curdir) nnoremap mc :call NetrwMarkFileCopy(1) nnoremap md :call NetrwMarkFileDiff(1) nnoremap me :call NetrwMarkFileEdit(1) nnoremap mf :call NetrwMarkFile(1,NetrwGetWord()) nnoremap mm :call NetrwMarkFileMove(1) nnoremap mp :call NetrwMarkFilePrint(1) nnoremap mr :call NetrwMarkFileRegexp(1) nnoremap mT :call NetrwMarkFileTag(1) nnoremap mt :call NetrwMarkFileTgt(1) nnoremap mx :call NetrwMarkFileExe(1) nnoremap mz :call NetrwMarkFileCompress(1) nnoremap gb :call NetrwBookmarkDir(1,b:netrw_curdir) nnoremap c :exe "cd ".escape(b:netrw_curdir,g:netrw_cd_escape) nnoremap C :let g:netrw_chgwin= winnr() nnoremap d :call NetrwMakeDir("") nnoremap i :call NetrwListStyle(1) nnoremap o :call NetrwSplit(3) nnoremap O :call NetrwObtain(0) nnoremap p :call NetrwPreview(NetrwBrowseChgDir(1,NetrwGetWord(),1)) nnoremap P :call NetrwPrevWinOpen(1) nnoremap q :call NetrwBookmarkDir(2,b:netrw_curdir) nnoremap r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'exe "norm! 0"call NetrwRefresh(1,NetrwBrowseChgDir(1,'./')) nnoremap s :call NetrwSortStyle(1) nnoremap S :call NetSortSequence(1) nnoremap t :call NetrwSplit(4) nnoremap u :call NetrwBookmarkDir(4,expand("%")) nnoremap U :call NetrwBookmarkDir(5,expand("%")) nnoremap v :call NetrwSplit(5) nnoremap x :call netrw#NetrwBrowseX(NetrwBrowseChgDir(1,NetrwGetWord(),0),0)" if !hasmapto('NetrwHideEdit') nmap NetrwHideEdit endif nnoremap NetrwHideEdit :call NetrwHideEdit(1) if !hasmapto('NetrwRefresh') nmap NetrwRefresh endif nnoremap NetrwRefresh :call NetrwRefresh(1,NetrwBrowseChgDir(1,'./')) if s:didstarstar || !mapcheck("","n") nnoremap :Nexplore endif if s:didstarstar || !mapcheck("","n") nnoremap :Pexplore endif if g:netrw_mousemaps == 1 nnoremap :call NetrwLeftmouse(1) nnoremap :call NetrwPrevWinOpen(1) nnoremap :call NetrwMarkFile(1,NetrwGetWord()) exe 'nnoremap :call NetrwLocalRm("'.b:netrw_curdir.'")' exe 'vnoremap :call NetrwLocalRm("'.b:netrw_curdir.'")' if !g:netrw_noretmap if !hasmapto("NetrwReturn") nmap <2-leftmouse> NetrwReturn endif exe 'nnoremap NetrwReturn :call netrw#LocalBrowseCheck("'.b:netrw_curdir.'")' endif endif exe 'com! Rexplore call netrw#LocalBrowseCheck("'.escape(b:netrw_curdir,g:netrw_cd_escape).'")' exe 'nnoremap :call NetrwLocalRm("'.b:netrw_curdir.'")' exe 'vnoremap :call NetrwLocalRm("'.b:netrw_curdir.'")' exe 'nnoremap D :call NetrwLocalRm("'.b:netrw_curdir.'")' exe 'vnoremap D :call NetrwLocalRm("'.b:netrw_curdir.'")' exe 'nnoremap R :call NetrwLocalRename("'.b:netrw_curdir.'")' exe 'vnoremap R :call NetrwLocalRename("'.b:netrw_curdir.'")' exe 'nnoremap m :call NetrwMakeDir("")' nnoremap :he netrw-dir else " remote call s:RemotePathAnalysis(b:netrw_curdir) nnoremap :call NetrwBrowse(0,NetrwBrowseChgDir(0,NetrwGetWord())) nnoremap :call NetrwRefresh(0,NetrwBrowseChgDir(0,'./')) nnoremap - :exe "norm! 0"call NetrwBrowse(0,NetrwBrowseChgDir(0,'../')) nnoremap a :call NetrwHide(0) nnoremap mb :call NetrwBookmarkDir(0,b:netrw_curdir) nnoremap mc :call NetrwMarkFileCopy(0) nnoremap md :call NetrwMarkFileDiff(0) nnoremap me :call NetrwMarkFileEdit(0) nnoremap mf :call NetrwMarkFile(0,NetrwGetWord()) nnoremap mm :call NetrwMarkFileMove(0) nnoremap mp :call NetrwMarkFilePrint(0) nnoremap mr :call NetrwMarkFileRegexp(0) nnoremap mT :call NetrwMarkFileTag(0) nnoremap mt :call NetrwMarkFileTgt(0) nnoremap mx :call NetrwMarkFileExe(0) nnoremap mz :call NetrwMarkFileCompress(0) nnoremap gb :call NetrwBookmarkDir(1,b:netrw_cur) nnoremap C :let g:netrw_chgwin= winnr() nnoremap i :call NetrwListStyle(0) nnoremap o :call NetrwSplit(0) nnoremap O :call NetrwObtain(0) nnoremap p :call NetrwPreview(NetrwBrowseChgDir(1,NetrwGetWord(),1)) nnoremap P :call NetrwPrevWinOpen(0) nnoremap q :call NetrwBookmarkDir(2,b:netrw_curdir) nnoremap r :let g:netrw_sort_direction= (g:netrw_sort_direction =~ 'n')? 'r' : 'n'exe "norm! 0"call NetrwBrowse(0,NetrwBrowseChgDir(0,'./')) nnoremap s :call NetrwSortStyle(0) nnoremap S :call NetSortSequence(0) nnoremap t :call NetrwSplit(1) nnoremap u :call NetrwBookmarkDir(4,b:netrw_curdir) nnoremap U :call NetrwBookmarkDir(5,b:netrw_curdir) nnoremap v :call NetrwSplit(2) nnoremap x :call netrw#NetrwBrowseX(NetrwBrowseChgDir(0,NetrwGetWord()),1) if !hasmapto('NetrwHideEdit') nmap NetrwHideEdit endif nnoremap NetrwHideEdit :call NetrwHideEdit(0) if !hasmapto('NetrwRefresh') nmap NetrwRefresh endif nnoremap NetrwRefresh :call NetrwRefresh(0,NetrwBrowseChgDir(0,'./')) if g:netrw_mousemaps == 1 nnoremap :call NetrwLeftmouse(0) nnoremap :call NetrwPrevWinOpen(0) nnoremap :call NetrwMarkFile(0,NetrwGetWord()) exe 'nnoremap :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' exe 'vnoremap :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' if !g:netrw_noretmap if !hasmapto("NetrwReturn") nmap <2-leftmouse> NetrwReturn endif exe 'nnoremap NetrwReturn :call NetrwBrowse(0,"'.b:netrw_curdir.'")' endif endif exe 'com! Rexplore call s:NetrwBrowse(0,"'.escape(b:netrw_curdir,g:netrw_cd_escape).'")' exe 'nnoremap :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' exe 'vnoremap :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' exe 'nnoremap d :call NetrwMakeDir("'.s:user.s:machine.'")' exe 'nnoremap D :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' exe 'vnoremap D :call NetrwRemoteRm("'.s:user.s:machine.'","'.s:path.'")' exe 'nnoremap R :call NetrwRemoteRename("'.s:user.s:machine.'","'.s:path.'")' exe 'vnoremap R :call NetrwRemoteRename("'.s:user.s:machine.'","'.s:path.'")' nnoremap :he netrw-browse-cmds endif " call Dret("s:BrowserMaps") endfun " --------------------------------------------------------------------- " s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to get a list {{{2 " of the contents of a remote directory. It is assumed that the " g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted " with the requested remote hostname first. fun! s:NetrwBrowse(islocal,dirname) if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif " call Dfunc("NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%").">") " call Dredir("ls!") if exists("s:netrw_skipbrowse") unlet s:netrw_skipbrowse " call Dret("NetrwBrowse : s:netrw_skipbrowse=".s:netrw_skipbrowse) return endif call s:NetrwOptionSave("w:") " clear any marked files if exists("s:netrwmarkfilelist") unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none endif if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep " call Decho("handle w:netrw_acdkeep:") " call Decho("cd ".escape(a:dirname,g:netrw_cd_escape)." (due to 'acd')") exe 'cd '.escape(a:dirname,g:netrw_cd_escape) " call Decho("getcwd<".getcwd().">") elseif !a:islocal && a:dirname !~ '[\/]$' && a:dirname !~ '^"' " looks like a regular file, attempt transfer " call Decho("attempt transfer as regular file<".a:dirname.">") " remove any filetype indicator from end of dirname, except for the {{{3 " "this is a directory" indicator (/). " There shouldn't be one of those here, anyway. let path= substitute(a:dirname,'[*=@|]\r\=$','','e') " call Decho("new path<".path.">") call s:RemotePathAnalysis(a:dirname) " remote-read the requested file into current buffer {{{3 mark ' call s:NetrwEnew(a:dirname) let b:netrw_curdir= a:dirname call s:NetrwSafeOptions() setlocal ma noro " call Decho("exe silent! keepalt file ".s:method."://".s:user.s:machine."/".escape(s:path,g:netrw_cd_escape)." (bt=".&bt.")") exe "silent! keepalt file ".s:method."://".s:user.s:machine."/".escape(s:path,g:netrw_cd_escape) exe "silent keepalt doau BufReadPre ".s:fname silent call netrw#NetRead(2,s:method."://".s:user.s:machine."/".s:path) exe "silent keepalt doau BufReadPost ".s:fname " save certain window-oriented variables into buffer-oriented variables {{{3 call s:SetBufWinVars() call s:NetrwOptionRestore("w:") setlocal nomod nowrap " call Dret("NetrwBrowse : file<".s:fname.">") return endif " use buffer-oriented WinVars if buffer ones exist but window ones don't {{{3 call s:UseBufWinVars() " set up some variables {{{3 let b:netrw_browser_active = 1 let dirname = a:dirname let s:last_sort_by = g:netrw_sort_by call s:NetrwMenu(1) " set up menu {{{3 if s:NetrwGetBuffer(a:islocal,dirname) " set up buffer {{{3 " call Dret("NetrwBrowse : re-using buffer") return endif " set b:netrw_curdir to the new directory name {{{3 " call Decho("set b:netrw_curdir to the new directory name:") let b:netrw_curdir= dirname if b:netrw_curdir =~ '[/\\]$' let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e') endif if b:netrw_curdir == '' if has("amiga") " On the Amiga, the empty string connotes the current directory let b:netrw_curdir= getcwd() else " under unix, when the root directory is encountered, the result " from the preceding substitute is an empty string. let b:netrw_curdir= '/' endif endif if !a:islocal && b:netrw_curdir !~ '/$' let b:netrw_curdir= b:netrw_curdir.'/' endif " call Decho("b:netrw_curdir<".b:netrw_curdir.">") " ------------ " (local only) {{{3 " ------------ if a:islocal " call Decho("local only:") " Set up ShellCmdPost handling. Append current buffer to browselist call s:LocalFastBrowser() " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3 if !g:netrw_keepdir " call Decho("handle keepdir: (g:netrw_keepdir=".g:netrw_keepdir.")") " call Decho('exe cd '.escape(b:netrw_curdir,g:netrw_cd_escape)) try exe 'cd '.escape(b:netrw_curdir,g:netrw_cd_escape) catch /^Vim\%((\a\+)\)\=:E472/ call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".b:netrw_curdir."> (permissions?)",33) if exists("w:netrw_prvdir") let b:netrw_curdir= w:netrw_prvdir else call s:NetrwOptionRestore("w:") let b:netrw_curdir= dirname " call Dret("NetrwBrowse : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">") return endif endtry endif " -------------------------------- " remote handling: {{{3 " -------------------------------- else " call Decho("remote only:") " analyze a:dirname and g:netrw_list_cmd {{{4 " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> a:dirname<".a:dirname.">") if a:dirname == "NetrwTreeListing" let dirname= b:netrw_curdir " call Decho("(dirname was NetrwTreeListing) dirname<".dirname.">") elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir") let dirname= substitute(b:netrw_curdir,'\\','/','g') if dirname !~ '/$' let dirname= dirname.'/' endif let b:netrw_curdir = dirname " call Decho("(liststyle is TREELIST) dirname<".dirname.">") else let dirname = substitute(a:dirname,'\\','/','g') " call Decho("(normal) dirname<".dirname.">") endif let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' if dirname !~ dirpat if !exists("g:netrw_quiet") call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20) endif call s:NetrwOptionRestore("w:") " call Dret("NetrwBrowse : badly formatted dirname<".dirname.">") return endif let b:netrw_curdir= dirname " call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)") endif " (additional remote handling) " ----------------------- " Directory Listing: {{{3 " ----------------------- setlocal noro ma call s:BrowserMaps(a:islocal) call s:PerformListing(a:islocal) " call Dret("NetrwBrowse") return endfun " --------------------------------------------------------------------- " s:NetrwGetBuffer: {{{2 " returns 0=cleared buffer " 1=re-used buffer fun! s:NetrwGetBuffer(islocal,dirname) " call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">)") " re-use buffer if possible {{{3 " call Decho("--re-use a buffer if possible--") if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST " find NetrwTreeList buffer if there is one " call Decho("find NetrwTreeList buffer if there is one") let dirname= "NetrwTreeListing" let bufnum = bufnr('\') if bufnum != -1 " call Dret("s:NetrwGetBuffer : bufnum#".bufnum."") return endif else " find buffer number of buffer named precisely the same as dirname {{{3 " call Decho("--find buffer numnber of buffer named precisely the same as dirname--") " call Dredir("ls!") let dirname= a:dirname " call Decho("find buffer<".dirname.">'s number ") let bufnum= bufnr(escape(dirname,'\')) " call Decho("bufnr(dirname<".escape(dirname,'\').">)=".bufnum) if bufnum < 0 && dirname !~ '/$' " trying appending a trailing / " call Decho("try appending a trailing / to dirname<".dirname.">") let bufnum= bufnr(escape(dirname.'/','\')) if bufnum > 0 let dirname= dirname.'/' endif endif if bufnum < 0 && dirname =~ '/$' " trying removing a trailing / " call Decho("try removing a trailing / from dirname<".dirname.">") let bufnum= bufnr(escape(substitute(dirname,'/$','',''),'\')) if bufnum > 0 let dirname= substitute(dirname,'/$','','') endif endif " call Decho("findbuf1: bufnum=bufnr('".dirname."')=".bufnum." bufname(".bufnum.")<".bufname(bufnum)."> (initial)") let ibuf= 1 " note: !~ was used just below, but that means using ../ to go back would match (ie. abc/def/ and abc/ matches) if bufnum > 0 && bufname(bufnum) != dirname let buflast = bufnr("$") " call Decho("findbuf2: buflast=".buflast) while ibuf <= buflast let bname= substitute(bufname(ibuf),'\\','/','g') " call Decho("findbuf3: dirname<".dirname."> bufname(".ibuf.")<".bname.">") if bname != '' && bname !~ '/' && dirname =~ '/'.bname.'$' | break | endif if bname =~ '^'.dirname.'/\=$' | break | endif if dirname =~ '^'.bname.'/$' | break | endif let ibuf= ibuf + 1 endwhile if ibuf > buflast let bufnum= -1 else let bufnum= ibuf endif " call Decho("findbuf4: bufnum=".bufnum) endif endif " get enew buffer and name it -or- re-use buffer {{{3 " call Decho("--get enewbuffer and name it -or- re-use buffer--") mark ' if bufnum < 0 || !bufexists(bufnum) " call Decho("get enew buffer") call s:NetrwEnew(dirname) call s:NetrwSafeOptions() " name the buffer if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST " call Decho('silent! keepalt file NetrwTreeListing') silent! keepalt file NetrwTreeListing nnoremap [ :silent call TreeListMove('[') nnoremap ] :silent call TreeListMove(']') nnoremap [[ :silent call TreeListMove('[') nnoremap ]] :silent call TreeListMove(']') else " call Decho('exe silent! keepalt file '.escape(dirname,g:netrw_cd_escape)) " let v:errmsg= "" " Decho let escdirname= escape(dirname,g:netrw_cd_escape) exe 'silent! keepalt file '.escdirname " call Decho("errmsg<".v:errmsg."> bufnr(".escdirname.")=".bufnr(escdirname)."<".bufname(bufnr(escdirname)).">") endif " call Decho("named enew buffer#".bufnr("%")."<".bufname("%").">") else " Re-use the buffer " call Decho("re-use buffer#".bufnum.":") let eikeep= &ei set ei=all if getline(2) =~ '^" Netrw Directory Listing' " call Decho("re-use buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: keepalt b ".bufnum) exe "keepalt b ".bufnum else " call Decho("reusing buffer#".bufnum."<".((bufnum > 0)? bufname(bufnum) : "")."> using: b ".bufnum) exe "b ".bufnum endif let &ei= eikeep if line("$") <= 1 call s:NetrwListSettings(a:islocal) " call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but its empty, so refresh it") return 0 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST " call Decho("clear buffer<".expand("%")."> with :%d") silent %d call s:NetrwListSettings(a:islocal) " call Dret("s:NetrwGetBuffer 0 : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh") return 0 else " call Dret("s:NetrwGetBuffer 1 : buf#".bufnr("%")) return 1 endif endif " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast) " slow 0 D D Deleting a buffer implies it will not be re-used (slow) " med 1 D H " fast 2 H H " call Decho("--do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc--") let fname= expand("%") call s:NetrwListSettings(a:islocal) exe "file ".escape(fname,' ') " delete all lines from buffer {{{3 " call Decho("--delete all lines from buffer--") " call Decho("clear buffer<".expand("%")."> with :%d") keepalt silent! %d " call Dret("s:NetrwGetBuffer 0 : buf#".bufnr("%")) return 0 endfun " --------------------------------------------------------------------- " s:NetrwGetWord: it gets the directory named under the cursor {{{2 fun! s:NetrwGetWord() " call Dfunc("NetrwGetWord() line#".line(".")." liststyle=".g:netrw_liststyle." virtcol=".virtcol(".")) call s:UseBufWinVars() " insure that w:netrw_liststyle is set up if !exists("w:netrw_liststyle") if exists("g:netrw_liststyle") let w:netrw_liststyle= g:netrw_liststyle else let w:netrw_liststyle= s:THINLIST endif " call Decho("w:netrw_liststyle=".w:netrw_liststyle) endif if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt " Active Banner support " call Decho("active banner handling") norm! 0 let dirname= "./" let curline= getline(".") if curline =~ '"\s*Sorted by\s' norm s let s:netrw_skipbrowse= 1 echo 'Pressing "s" also works' elseif curline =~ '"\s*Sort sequence:' let s:netrw_skipbrowse= 1 echo 'Press "S" to edit sorting sequence' elseif curline =~ '"\s*Quick Help:' norm ? let s:netrw_skipbrowse= 1 echo 'Pressing "?" also works' elseif curline =~ '"\s*\%(Hiding\|Showing\):' norm a let s:netrw_skipbrowse= 1 echo 'Pressing "a" also works' elseif line("$") > w:netrw_bannercnt exe 'silent keepjumps '.w:netrw_bannercnt endif elseif w:netrw_liststyle == s:THINLIST " call Decho("thin column handling") norm! 0 let dirname= getline(".") elseif w:netrw_liststyle == s:LONGLIST " call Decho("long column handling") norm! 0 let dirname= substitute(getline("."),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e') elseif w:netrw_liststyle == s:TREELIST " call Decho("treelist handling") let dirname= substitute(getline("."),'^\(| \)*','','e') else " call Decho("obtain word from wide listing") let dirname= getline(".") if !exists("b:netrw_cpf") let b:netrw_cpf= 0 exe 'silent keepjumps '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif' " call Decho("computed cpf") endif " call Decho("buf#".bufnr("%")."<".bufname("%").">") let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf " call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt) " call Decho("1: dirname<".dirname.">") if filestart > 0|let dirname= substitute(dirname,'^.\{'.filestart.'}','','')|endif " call Decho("2: dirname<".dirname.">") let dirname = substitute(dirname,'^\(.\{'.b:netrw_cpf.'}\).*$','\1','e') " call Decho("3: dirname<".dirname.">") let dirname = substitute(dirname,'\s\+$','','e') " call Decho("4: dirname<".dirname.">") endif " call Dret("NetrwGetWord <".dirname.">") return dirname endfun " --------------------------------------------------------------------- " s:NetrwListSettings: {{{2 fun! s:NetrwListSettings(islocal) " call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")") let fname= bufname("%") setlocal bt=nofile nobl ma nonu nowrap noro exe "file ".escape(fname,' ') if g:netrw_use_noswf setlocal noswf endif " call Dredir("ls!") " call Decho("exe setlocal ts=".g:netrw_maxfilenamelen) exe "setlocal ts=".g:netrw_maxfilenamelen setlocal isk+=.,~,- if g:netrw_fastbrowse > a:islocal setlocal bh=hide else setlocal bh=delete endif " call Dret("s:NetrwListSettings") endfun " --------------------------------------------------------------------- " s:PerformListing: {{{2 fun! s:PerformListing(islocal) " call Dfunc("s:PerformListing(islocal=".a:islocal.") buf(%)=".bufnr("%")."<".bufname("%").">") " if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho " call Decho("(netrw) Processing your browsing request...") " endif " Decho " call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')) if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") " force a refresh for tree listings " call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d") setlocal ma noro keepjumps %d endif " save current directory on directory history list call s:NetrwBookmarkDir(3,b:netrw_curdir) " Set up the banner {{{3 " call Decho("set up banner") keepjumps put ='\" ============================================================================' keepjumps put ='\" Netrw Directory Listing (netrw '.g:loaded_netrw.')' keepjumps put ='\" '.b:netrw_curdir keepjumps 1d let w:netrw_bannercnt= 3 exe "keepjumps ".w:netrw_bannercnt let sortby= g:netrw_sort_by if g:netrw_sort_direction =~ "^r" let sortby= sortby." reversed" endif " Sorted by... {{{3 " call Decho("handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">") if g:netrw_sort_by =~ "^n" " call Decho("directories will be sorted by name") " sorted by name keepjumps put ='\" Sorted by '.sortby keepjumps put ='\" Sort sequence: '.g:netrw_sort_sequence let w:netrw_bannercnt= w:netrw_bannercnt + 2 else " call Decho("directories will be sorted by size or time") " sorted by size or date keepjumps put ='\" Sorted by '.sortby let w:netrw_bannercnt= w:netrw_bannercnt + 1 endif exe "keepjumps ".w:netrw_bannercnt " show copy/move target, if any if exists("s:netrwmftgt") && exists("s:netrwmfloc") " call Decho("show copy/move target<".s:netrwmftgt."> netrwmfloc=".s:netrwmfloc) if s:netrwmfloc keepjumps put ='\" Copy/Move Tgt: '.s:netrwmftgt.' (local)' else keepjumps put ='\" Copy/Move Tgt: '.s:netrwmftgt.' (remote)' endif let w:netrw_bannercnt= w:netrw_bannercnt + 1 endif exe "keepjumps ".w:netrw_bannercnt " Hiding... -or- Showing... {{{3 " call Decho("handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)") if g:netrw_list_hide != "" && g:netrw_hide if g:netrw_hide == 1 keepjumps put ='\" Hiding: '.g:netrw_list_hide else keepjumps put ='\" Showing: '.g:netrw_list_hide endif let w:netrw_bannercnt= w:netrw_bannercnt + 1 endif exe "keepjumps ".w:netrw_bannercnt keepjumps put ='\" Quick Help: :help -:go up dir D:delete R:rename s:sort-by x:exec' keepjumps put ='\" ============================================================================' let w:netrw_bannercnt= w:netrw_bannercnt + 2 " bannercnt should index the line just after the banner let w:netrw_bannercnt= w:netrw_bannercnt + 1 exe "keepjumps ".w:netrw_bannercnt " call Decho("bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$")) " set up syntax highlighting {{{3 " call Decho("set up syntax highlighting") if has("syntax") setlocal ft=netrw if !exists("g:syntax_on") || !g:syntax_on setlocal ft= endif endif " get list of files " call Decho("Get list of files - islocal=".a:islocal) if a:islocal call s:LocalListing() else " remote call s:NetrwRemoteListing() endif " call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)") " manipulate the directory listing (hide, sort) {{{3 if line("$") >= w:netrw_bannercnt " call Decho("manipulate directory listing (hide)") " call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">") if g:netrw_hide && g:netrw_list_hide != "" call s:NetrwListHide() endif if line("$") >= w:netrw_bannercnt " call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">") if g:netrw_sort_by =~ "^n" " sort by name call s:SetSort() if w:netrw_bannercnt < line("$") " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")") if g:netrw_sort_direction =~ 'n' " normal direction sorting exe 'silent keepjumps '.w:netrw_bannercnt.',$sort' else " reverse direction sorting exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!' endif endif " remove priority pattern prefix " call Decho("remove priority pattern prefix") exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{3}\///e' elseif a:islocal if w:netrw_bannercnt < line("$") " call Decho("g:netrw_sort_direction=".g:netrw_sort_direction) if g:netrw_sort_direction =~ 'n' " call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort') exe 'silent keepjumps '.w:netrw_bannercnt.',$sort' else " call Decho('exe silent keepjumps '.w:netrw_bannercnt.',$sort!') exe 'silent keepjumps '.w:netrw_bannercnt.',$sort!' endif endif exe 'silent keepjumps '.w:netrw_bannercnt.',$s/^\d\{-}\///e' endif elseif g:netrw_sort_direction =~ 'r' " call Decho('reverse the sorted listing') exe 'silent keepjumps '.w:netrw_bannercnt.'g/^/m '.w:netrw_bannercnt endif endif " convert to wide/tree listing {{{3 " call Decho("modify display if wide/tree listing style") call s:NetrwWideListing() call s:NetrwTreeListing(b:netrw_curdir) if exists("w:netrw_bannercnt") && line("$") > w:netrw_bannercnt " place cursor on the top-left corner of the file listing " call Decho("place cursor on top-left corner of file listing") exe 'silent keepjumps '.w:netrw_bannercnt norm! 0 endif " record previous current directory let w:netrw_prvdir= b:netrw_curdir " call Decho("record netrw_prvdir<".w:netrw_prvdir.">") " save certain window-oriented variables into buffer-oriented variables {{{3 call s:SetBufWinVars() call s:NetrwOptionRestore("w:") " set display to netrw display settings " call Decho("set display to netrw display settings (noma nomod etc)") setlocal noma nomod nonu nobl nowrap ro if exists("s:treecurpos") call setpos('.',s:treecurpos) unlet s:treecurpos endif " call Dret("s:PerformListing : curpos<".string(getpos(".")).">") endfun " --------------------------------------------------------------------- " s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2 " directory and a new directory name. Also, if the " "new directory name" is actually a file, " NetrwBrowseChgDir() edits the file. fun! s:NetrwBrowseChgDir(islocal,newdir,...) " call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">") if !exists("b:netrw_curdir") " call Decho("(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!") echoerr "(NetrwBrowseChgDir) b:netrw_curdir doesn't exist!" " call Dret("s:NetrwBrowseChgDir") return endif call s:NetrwOptionSave("s:") call netrw#NetrwSavePosn() let nbcd_curpos = getpos('.') let dirname = substitute(b:netrw_curdir,'\\','/','ge') let newdir = a:newdir " set up o/s-dependent directory recognition pattern if has("amiga") let dirpat= '[\/:]$' else let dirpat= '[\/]$' endif " call Decho("dirname<".dirname."> dirpat<".dirpat.">") if dirname !~ dirpat " apparently vim is "recognizing" that it is in a directory and " is removing the trailing "/". Bad idea, so I put it back. let dirname= dirname.'/' " call Decho("adjusting dirname<".dirname.">") endif if newdir !~ dirpat " ------------ " edit a file: " ------------ " call Decho('case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">") if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)' let dirname= s:NetrwTreeDir().newdir " call Decho("tree listing") elseif newdir =~ '^\(/\|\a:\)' let dirname= newdir else let dirname= s:ComposePath(dirname,newdir) endif " call Decho("handling a file: dirname<".dirname."> (a:0=".a:0.")") " this lets NetrwBrowseX avoid the edit if a:0 < 1 " call Decho("dirname<".dirname."> netrw_cd_escape<".g:netrw_cd_escape."> browse_split=".g:netrw_browse_split) " call Decho("about to edit<".escape(dirname,g:netrw_cd_escape)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist")) if !exists("s:didsplit") if g:netrw_browse_split == 1 new wincmd _ elseif g:netrw_browse_split == 2 rightb vert new wincmd | elseif g:netrw_browse_split == 3 tabnew else " handling a file, didn't split, so remove menu " call Decho("handling a file+didn't split, so remove menu") call s:NetrwMenu(0) " optional change to window if g:netrw_chgwin >= 1 exe g:netrw_chgwin."wincmd w" endif endif endif " the point where netrw actually edits the (local) file " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will if a:islocal " call Decho("edit local file: exe e! ".escape(dirname,g:netrw_cd_escape)) call s:NetrwOptionRestore("s:") setlocal ma nomod noro exe "e! ".escape(dirname,g:netrw_cd_escape) else setlocal ma nomod noro call s:NetrwOptionRestore("s:") endif endif elseif newdir =~ '^/' " --------------------------------- " just go to the new directory spec " --------------------------------- " call Decho('case "just go to new directory spec": newdir<'.newdir.'>') let dirname= newdir call s:NetrwOptionRestore("s:") elseif newdir == './' " -------------------------- " refresh the directory list " -------------------------- " call Decho('case "refresh directory listing": newdir == "./"') call s:NetrwOptionRestore("s:") elseif newdir == '../' " ------------------- " go up one directory " ------------------- " call Decho('case "go up one directory": newdir == "../"') if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") " force a refresh " call Decho("clear buffer<".expand("%")."> with :%d") setlocal noro ma keepjumps %d endif if has("amiga") " amiga " call Decho('case "go up one directory": newdir == "../" and amiga') if a:islocal let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','') let dirname= substitute(dirname,'/$','','') else let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','') endif " call Decho("amiga: dirname<".dirname."> (go up one dir)") else " unix or cygwin " call Decho('case "go up one directory": newdir == "../" and unix or cygwin') if a:islocal let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','') if dirname == "" let dirname= '/' endif else let dirname= substitute(dirname,'^\(\a\+://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','') endif " call Decho("unix: dirname<".dirname."> (go up one dir)") endif call s:NetrwOptionRestore("s:") elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") " call Decho('case liststyle is TREELIST and w:netrw_treedict exists') " force a refresh (for TREELIST, wait for NetrwTreeDir() to force the refresh) setlocal noro ma if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")) " call Decho("clear buffer<".expand("%")."> with :%d") keepjumps %d endif let treedir = s:NetrwTreeDir() let s:treecurpos = nbcd_curpos let haskey= 0 " call Decho("w:netrw_treedict<".string(w:netrw_treedict).">") " search treedict for tree dir as-is if has_key(w:netrw_treedict,treedir) " call Decho('....searched for treedir<'.treedir.'> : found it!') let haskey= 1 else " call Decho('....searched for treedir<'.treedir.'> : not found') endif " search treedict for treedir with a / appended if !haskey && treedir !~ '/$' if has_key(w:netrw_treedict,treedir."/") let treedir= treedir."/" " call Decho('....searched.for treedir<'.treedir.'> found it!') let haskey = 1 else " call Decho('....searched for treedir<'.treedir.'/> : not found') endif endif " search treedict for treedir with any trailing / elided if !haskey && treedir =~ '/$' let treedir= substitute(treedir,'/$','','') if has_key(w:netrw_treedict,treedir) " call Decho('....searched.for treedir<'.treedir.'> found it!') let haskey = 1 else " call Decho('....searched for treedir<'.treedir.'> : not found') endif endif if haskey " close tree listing for selected subdirectory " call Decho("closing selected subdirectory<".dirname.">") call remove(w:netrw_treedict,treedir) " call Decho("removed entry<".dirname."> from treedict") " call Decho("yielding treedict<".string(w:netrw_treedict).">") let dirname= w:netrw_treetop else " go down one directory let dirname= substitute(treedir,'/*$','/','') " call Decho("go down one dir: treedir<".treedir.">") endif else " go down one directory let dirname= s:ComposePath(dirname,newdir) " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">") call s:NetrwOptionRestore("s:") endif " call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">") return dirname endfun " --------------------------------------------------------------------- " s:NetrwHide: this function is invoked by the "a" map for browsing {{{2 " and switches the hiding mode. The actual hiding is done by " s:NetrwListHide(). " g:netrw_hide= 0: show all " 1: show not-hidden files " 2: show hidden files only fun! s:NetrwHide(islocal) " call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide) let svpos= netrw#NetrwSavePosn() if exists("s:netrwmarkfilelist") " call Decho(((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist).">") " call Decho("g:netrw_list_hide<".g:netrw_list_hide.">") " hide the files in the markfile list for fname in s:netrwmarkfilelist " call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." isk=".&isk) if match(g:netrw_list_hide,'\<'.fname.'\>') != -1 " remove fname from hiding list let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','') let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g') let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','') " call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">") else " append fname to hiding list if exists("g:netrw_list_hide") && g:netrw_list_hide != "" let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>' else let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>' endif " call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">") endif endfor unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none let g:netrw_hide= 1 else " switch between show-all/show-not-hidden/show-hidden let g:netrw_hide=(g:netrw_hide+1)%3 exe "norm! 0" if g:netrw_hide && g:netrw_list_hide == "" call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49) " call Dret("NetrwHide") return endif endif call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) " call Dret("NetrwHide") endfun " --------------------------------------------------------------------- " s:NetrwLeftmouse: handles the when in a netrw browsing window {{{2 fun! s:NetrwLeftmouse(islocal) " call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")") if a:islocal if exists("b:netrw_curdir") call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord())) endif else if exists("b:netrw_curdir") call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord())) endif endif " call Dret("s:NetrwLeftmouse") endfun " --------------------------------------------------------------------- " s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2 " separated patterns given in g:netrw_list_hide fun! s:NetrwListHide() " call Dfunc("NetrwListHide() hide=".g:netrw_hide." listhide<".g:netrw_list_hide.">") " find a character not in the "hide" string to use as a separator for :g and :v commands " How-it-works: take the hiding command, convert it into a range. Duplicate " characters don't matter. Remove all such characters from the '/~...90' " string. Use the first character left as a separator character. let listhide= g:netrw_list_hide let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1) " call Decho("sep=".sep) while listhide != "" if listhide =~ ',' let hide = substitute(listhide,',.*$','','e') let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e') else let hide = listhide let listhide = "" endif " Prune the list by hiding any files which match if g:netrw_hide == 1 " call Decho("hiding<".hide."> listhide<".listhide.">") exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d' elseif g:netrw_hide == 2 " call Decho("showing<".hide."> listhide<".listhide.">") exe 'silent keepjumps '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @' endif endwhile if g:netrw_hide == 2 exe 'silent keepjumps '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d' exe 'silent keepjumps '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e' endif " call Dret("NetrwListHide") endfun " --------------------------------------------------------------------- " NetrwHideEdit: allows user to edit the file/directory hiding list fun! s:NetrwHideEdit(islocal) " call Dfunc("NetrwHideEdit(islocal=".a:islocal.")") " save current cursor position let svpos= netrw#NetrwSavePosn() " get new hiding list from user call inputsave() let newhide= input("Edit Hiding List: ",g:netrw_list_hide) call inputrestore() let g:netrw_list_hide= newhide " call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">") " refresh the listing silent call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./")) " restore cursor position call netrw#NetrwRestorePosn(svpos) " call Dret("NetrwHideEdit") endfun " --------------------------------------------------------------------- " NetSortSequence: allows user to edit the sorting sequence fun! s:NetSortSequence(islocal) " call Dfunc("NetSortSequence(islocal=".a:islocal.")") let svpos= netrw#NetrwSavePosn() call inputsave() let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence) call inputrestore() " refresh the listing let g:netrw_sort_sequence= newsortseq call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) " call Dret("NetSortSequence") endfun " --------------------------------------------------------------------- " s:NetrwMarkFile: This function is invoked by mf, and is used to both {{{2 " mark and unmark files. If a markfile list exists, " then the rename and delete functions will use it instead " of whatever may happen to be under the cursor at that " moment. When the mouse and gui are available, " shift-leftmouse may also be used to mark files. fun! s:NetrwMarkFile(islocal,fname) " call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)") " call Decho("b:netrw_curdir<".b:netrw_curdir.">") if exists("s:netrwmarkfilelist") " call Decho("starting s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") " call Decho("starting s:netrwmarkfilemtch<".s:netrwmarkfilemtch.">") if index(s:netrwmarkfilelist,a:fname) == -1 " append filename to list " call Decho("append filename<".a:fname."> to markfilelist<".string(s:netrwmarkfilelist).">") call add(s:netrwmarkfilelist,a:fname) let s:netrwmarkfilemtch= s:netrwmarkfilemtch.'\|\<'.a:fname.'\>' else " remove filename from list " call Decho("remove filename<".a:fname."> from markfilelist<".string(s:netrwmarkfilelist).">") call filter(s:netrwmarkfilelist,'v:val != a:fname') if s:netrwmarkfilelist == [] unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch else let s:netrwmarkfilemtch= substitute(s:netrwmarkfilemtch,'\\<'.a:fname.'\\>','','') let s:netrwmarkfilemtch= substitute(s:netrwmarkfilemtch,'\\|\\|','\\|','g') let s:netrwmarkfilemtch= substitute(s:netrwmarkfilemtch,'^\\|\|\\|$','','') " call Decho("ending s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") " call Decho("ending s:netrwmarkfilemtch<".s:netrwmarkfilemtch.">") endif endif else " call Decho("add fname<".a:fname."> to new markfilelist") let s:netrwmarkfilelist= [] call add(s:netrwmarkfilelist,a:fname) " call Decho("ending s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") if a:fname =~ '/$' let s:netrwmarkfilemtch= '\<'.escape(a:fname,'*./[\') else let s:netrwmarkfilemtch= '\<'.escape(a:fname,'*./[\').'\>' endif " call Decho("ending s:netrwmarkfilemtch<".s:netrwmarkfilemtch.">") endif if exists("s:netrwmarkfilemtch") && s:netrwmarkfilemtch != "" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch."/") exe "2match netrwMarkFile /".s:netrwmarkfilemtch."/" else " call Decho("2match none") 2match none endif " call Dret("s:NetrwMarkFile : netrwmarkfilelist".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : " doesn't exist")) endfun " --------------------------------------------------------------------- " s:NetrwMarkFileCompress: This function, invoked by mz, is used to {{{2 " compress/decompress files using the programs " in g:netrw_compress and g:netrw_uncompress, " using g:netrw_compress_suffix to know which to " do. By default: " g:netrw_compress = "gzip" " g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf"} fun! s:NetrwMarkFileCompress(islocal) " call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmarkfilelist") && exists("g:netrw_compress") && exists("g:netrw_decompress") for fname in s:netrwmarkfilelist " for every filename in the marked list for sfx in sort(keys(g:netrw_decompress)) if fname =~ '\'.sfx.'$' " fname has a suffix indicating that its compressed; apply associated decompression routine let exe= g:netrw_decompress[sfx] " call Decho("fname<".fname."> is compressed so decompress with <".exe.">") if executable(exe) if a:islocal call system(exe." ".fname) else call s:RemoteSystem(exe." ".fname) endif else call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50) endif break endif endfor if exists("exe") unlet exe elseif a:islocal " fname not a compressed file, so compress it call system(g:netrw_compress." ".fname) else " fname not a compressed file, so compress it call s:RemoteSystem(g:netrw_compress." ".fname) endif endfor unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) endif " call Dret("s:NetrwMarkFileCompress") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileCopy: copy marked files to target {{{2 " If no marked files, then set up directory as the " target. Currently does not support copying entire " directories. " Returns 1=success (used by NetrwMarkFileMove()) " 0=failure fun! s:NetrwMarkFileCopy(islocal) " call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---').">") if exists("s:netrwmarkfilelist") " call Decho("s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") " call Decho("s:netrwmarkfilemtch<".string(s:netrwmarkfilemtch).">") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmftgt") && exists("s:netrwmfloc") " call Decho("s:netrwmftgt<".s:netrwmftgt.">") " call Decho("s:netrwmfloc=".s:netrwmfloc) for fname in s:netrwmarkfilelist " call Decho("s:NetrwMarkFileCopy: fname<".fname.">") " sanity check if (a:islocal && isdirectory(fname)) || (!a:islocal && fname =~ '/$') call netrw#ErrorMsg(s:ERROR,"currently netrw can't copy entire directories such as <".fname.">",58) " call Dret("s:NetrwMarkFileCopy 0 : currently netrw can't copy entire directories") return 0 endif if a:islocal && s:netrwmfloc " local to local copy " call Decho("local to local copy") if executable(g:netrw_localcopycmd) " call Decho("let ret= system(".g:netrw_localcopycmd." ".fname." ".s:netrwmftgt.")") let ret= system(g:netrw_localcopycmd." ".fname." ".s:netrwmftgt) if v:shell_error < 0 call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localcopycmd."> failed, aborting",54) break endif else call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localcopycmd."> is not executable!",57) break endif elseif !a:islocal && s:netrwmfloc " remote to local copy " call Decho("remote to local copy") call netrw#NetrwObtain(a:islocal,fname,s:netrwmftgt) elseif a:islocal && !s:netrwmfloc " local to remote copy " call Decho("local to remote copy") call s:NetrwUpload(fname,s:netrwmftgt) else " remote to remote copy " call Decho("remote to remote copy") call s:NetrwUpload(fname,s:netrwmftgt) endif endfor " unmark marked file list (although I expect s:NetrwUpload() " to do it, I'm just making sure) if exists("s:netrwmarkfilelist") unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none endif else call netrw#ErrorMsg(s:ERROR,"missing a markfile copy target!",56) endif " refresh the listing call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) else call netrw#ErrorMsg(s:ERROR,"no files marked!",59) endif " call Dret("s:NetrwMarkFileCopy 1") return 1 endfun " --------------------------------------------------------------------- " s:NetrwMarkFileDiff: This function, invoked by md, is used to {{{2 " invoke vim's diff mode on the marked files. " Either two or three files can be so handled. fun! s:NetrwMarkFileDiff(islocal) " call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">") if exists("s:netrwmarkfilelist") let curdir= b:netrw_curdir let cnt= 0 for fname in s:netrwmarkfilelist let cnt= cnt + 1 if !a:islocal let fname= curdir.fname endif if cnt == 1 " call Decho("diffthis: ".fname) exe "e ".fname diffthis elseif cnt == 2 || cnt == 3 vsplit wincmd l " call Decho("diffthis: ".fname) exe "e ".fname diffthis else break endif endfor unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none endif " call Dret("s:NetrwMarkFileDiff") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileEdit: put marked files on arg list and start editing them {{{2 fun! s:NetrwMarkFileEdit(islocal) " call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")") if exists("s:netrwmarkfilelist") if a:islocal exe 'com! Rexplore call netrw#LocalBrowseCheck("'.escape(b:netrw_curdir,g:netrw_cd_escape).'")' if g:netrw_mousemaps == 1 silent! unmap <2-leftmouse> exe 'nnoremap <2-leftmouse> :call netrw#LocalBrowseCheck("'.b:netrw_curdir.'")' endif else exe 'com! Rexplore call s:NetrwBrowse(0,"'.escape(b:netrw_curdir,g:netrw_cd_escape).'")' if g:netrw_mousemaps == 1 silent! unmap <2-leftmouse> exe 'silent! nnoremap <2-leftmouse> :call NetrwBrowse(0,"'.b:netrw_curdir.'")' endif endif let flist= substitute(escape(join(s:netrwmarkfilelist,"\t"),' '),"\t",' ','g') " unmark marked file list unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none " call Decho("exe silent args ".flist) exe "silent args ".flist endif " call Dret("s:NetrwMarkFileEdit") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileExe: execute arbitrary command on marked files, one at a time {{{2 fun! s:NetrwMarkFileExe(islocal) " call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.")") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmarkfilelist") " get the command call inputsave() let cmd= input("Enter command: ","","file") call inputrestore() " call Decho("cmd<".cmd.">") " apply command to marked files. Substitute: filename -> % " If no %, then append a space and the filename to the command for fname in s:netrwmarkfilelist if cmd =~ '%' let xcmd= substitute(cmd,'%',fname,'g') else let xcmd= cmd.' '.fname endif if a:islocal " call Decho("local: xcmd<".xcmd.">") let ret= system(xcmd) else " call Decho("remote: xcmd<".xcmd.">") let ret= s:RemoteSystem(xcmd) endif if v:shell_error < 0 call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54) break else echo ret endif endfor " unmark marked file list unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none " refresh the listing call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) endif " call Dret("s:NetrwMarkFileExe") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileMove: execute arbitrary command on marked files, one at a time {{{2 fun! s:NetrwMarkFileMove(islocal) " call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")") if exists("s:netrwmarkfilelist") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmftgt") && exists("s:netrwmfloc") if a:islocal && s:netrwmfloc " local to local move if executable(g:netrw_localmovecmd) " call Decho("let ret= system(".g:netrw_localmovecmd." ".fname." ".s:netrwmftgt.")") let ret= system(g:netrw_localmovecmd." ".fname." ".s:netrwmftgt) if v:shell_error < 0 call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> failed, aborting",54) break endif else call netrw#ErrorMsg(s:ERROR,"command<".g:netrw_localmovecmd."> is not executable!",57) break endif else " remote to local move " local to remote move " remote to remote move let netrwmflist = s:netrwmflist let netrwmfmtch = s:netrwmfmtch if s:NetrwMarkFileCopy(islocal) let s:netrwmflist= netrwmflist let s:netrwmfmtch= netrwmfmtch if a:islocal call s:NetrwLocalRm("---") else call s:NetrwRemoteRm("---","---") endif endif endif " First, do a copy, then (attempt to) do a delete call netrw#NetrwRestorePosn(svpos) endif " call Dret("s:NetrwMarkFileMove") endfun " --------------------------------------------------------------------- " s:NetrwMarkFilePrint: This function, invoked by mp, prints marked files {{{2 " using the hardcopy command fun! s:NetrwMarkFilePrint(islocal) " call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")") if exists("s:netrwmarkfilelist") let netrwmarkfilelist= s:netrwmarkfilelist unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch for fname in netrwmarkfilelist 1split exe "silent e ".fname " call Decho("hardcopy ".fname) hardcopy q endfor 2match none endif " call Dret("s:NetrwMarkFilePrint") endfun " --------------------------------------------------------------------- " =========================================== " s:NetrwMarkFileRegexp: This function, invoked by mr, is used to mark {{{2 " files when given a regexp (for which a prompt is " issued). fun! s:NetrwMarkFileRegexp(islocal) " call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")") " get the regular expression call inputsave() let regexp= input("Enter regexp: ","","file") call inputrestore() if a:islocal " get the matching list of files using local glob() let dirname = escape(b:netrw_curdir,s:netrw_glob_escape) let filelist = glob(s:ComposePath(dirname,regexp)) if filelist != "" let filelist= filelist."\n" endif " mark the list of files while filelist != "" if filelist =~ '\n' let filename = substitute(filelist,'\n.*$','','e') let filelist = substitute(filelist,'^.\{-}\n\(.*\)$','\1','e') else let filename = filelist let filelist = "" endif " call Decho("filelist<".filelist.">") " call Decho("filename<".filename.">") call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','','')) endwhile else " convert displayed listing into a filelist let eikeep = &ei let areg = @a silent %y a set ei=all ma 1split enew silent norm! "ap 2 let bannercnt= search('^" =====','W') exe "silent 1,".bannercnt."d" set bt=nofile if g:netrw_liststyle == s:LONGLIST silent %s/\s\{2,}\S.*$//e elseif g:netrw_liststyle == s:WIDELIST silent %s/\s\{2,}/\r/ge elseif g:netrw_liststyle == s:TREELIST silent %s/^| //e silent! g/^ .*$/d endif exe "silent! v/".escape(regexp,'/')."/d" let filelist= getline(1,line("$")) q! for filename in filelist call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','','')) endfor unlet filelist let @a = areg let &ei = eikeep endif " call Dret("s:NetrwMarkFileRegexp") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileTag: This function, invoked by mT, applies {{{2 " g:netrw_ctags to marked files fun! s:NetrwMarkFileTag(islocal) " call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmarkfilelist") " call Decho("s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">") let netrwmarkfilelist= string(s:netrwmarkfilelist) unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch let netrwmarkfilelist= substitute(netrwmarkfilelist,'[[\],]','','g') " call Decho("netrwmarkfilelist<".netrwmarkfilelist.">") if a:islocal if executable(g:netrw_ctags) if g:netrw_shq != "'" let netrwmarkfilelist= substitute(netrwmarkfilelist,"'",g:netrw_shq,'g') endif " call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")") call system(g:netrw_ctags." ".netrwmarkfilelist) else call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51) endif else let cmd= s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist) call netrw#NetrwObtain(a:islocal,"tags") let curdir= b:netrw_curdir 1split e tags let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','') " call Decho("curdir<".curdir."> path<".path.">") exe '%s/\t\(\S\+\)\t/\t'.escape(path,'/').'\1\t/e' wq! endif 2match none call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) endif " call Dret("s:NetrwMarkFileTag") endfun " --------------------------------------------------------------------- " s:NetrwMarkFileTgt: {{{2 fun! s:NetrwMarkFileTgt(islocal) " call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")") let svpos= netrw#NetrwSavePosn() if exists("s:netrwmftgt") || exists("s:netrwmfloc") " call Decho("s:netrwmftgt<".s:netrwmftgt."> exists; removing it") silent! unlet s:netrwmftgt s:netrwmfloc else " call Decho("s:netrwmftgt doesn't exist; setting it to <".b:netrw_curdir.">") let s:netrwmftgt = b:netrw_curdir let s:netrwmfloc = a:islocal endif call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./')) call netrw#NetrwRestorePosn(svpos) " call Dret("s:NetrwMarkFileTgt") endfun " =========================================== " s:NetrwObtain: obtain file under cursor or from markfile list {{{2 fun! s:NetrwObtain(islocal) " call Dfunc("NetrwObtain(islocal=".a:islocal.")") if exists("s:netrwmarkfilelist") for fname in s:netrwmarkfilelist call netrw#NetrwObtain(a:islocal,fname) endfor unlet s:netrwmarkfilelist unlet s:netrwmarkfilemtch 2match none else call netrw#NetrwObtain(a:islocal,expand("")) endif " call Dret("NetrwObtain") endfun " --------------------------------------------------------------------- " netrw#NetrwObtain: {{{2 fun! netrw#NetrwObtain(islocal,fname,...) " call Dfunc("netrw#NetrwObtain(islocal=".a:islocal." fname<".a:fname.">) a:0=".a:0) " NetrwStatusLine support - for obtaining support if a:islocal " obtain local file from getcwd() to b:netrw_curdir if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir let fname= expand("") let fcopy= readfile(b:netrw_curdir."/".fname,"b") call writefile(fcopy,getcwd()."/".fname,"b") elseif !exists("b:netrw_curdir") call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36) else call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37) endif else " obtain a remote file to local directory (see tgtdir below) call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname) " set up target directory (default is vim's idea of the current directory) if a:0 > 0 let tgtdir= a:1 else let tgtdir= '.' endif " call Decho("tgtdir<".tgtdir.">") if exists("w:netrw_method") && w:netrw_method =~ '[235]' " call Decho("method=".w:netrw_method) if executable("ftp") " call Decho("ftp is executable, method=".w:netrw_method) let curdir = b:netrw_curdir let path = substitute(curdir,'ftp://[^/]\+/','','e') let curline= line(".") let endline= line("$")+1 setlocal ma noro keepjumps $ " call Decho("getcwd<".getcwd().">") " call Decho("curdir<".curdir.">") " call Decho("path<".path.">") " call Decho("curline=".curline) " call Decho("endline=".endline) "......................................... if w:netrw_method == 2 " ftp + <.netrc>: Method #2 setlocal ff=unix if path != "" put ='cd '.path " call Decho("ftp: cd ".path) endif if tgtdir != '.' put ='lcd '.tgtdir endif put ='get '.a:fname " call Decho("ftp: get ".a:fname) put ='qui