1" netrwPlugin.vim: Handles file transfer and remote directory listing across a network 2" PLUGIN PORTION 3" Date: Sep 08, 2005 4" Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz> 5" License: Vim License (see vim's :help license) 6" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim 7" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 8" Permission is hereby granted to use and distribute this code, 9" with or without modifications, provided that this copyright 10" notice is copied with it. Like anything else that's free, 11" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided 12" *as is* and comes with no warranty of any kind, either 13" expressed or implied. By using this plugin, you agree that 14" in no event will the copyright holder be liable for any damages 15" resulting from the use of this software. 16" 17" But be doers of the Word, and not only hearers, deluding your own selves {{{1 18" (James 1:22 RSV) 19" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 20 21" --------------------------------------------------------------------- 22" Load Once: {{{1 23if exists("g:loaded_netrw") 24 finish 25endif 26let s:keepcpo= &cpo 27set cpo&vim 28 29" --------------------------------------------------------------------- 30" Public Interface: {{{1 31 32" Local Browsing: {{{2 33augroup FileExplorer 34 au! 35 au BufEnter * call s:LocalBrowse(expand("<amatch>")) 36augroup END 37 38" Network Browsing Reading Writing: {{{2 39augroup Network 40 au! 41 if has("win32") || has("win95") || has("win64") || has("win16") 42 au BufReadCmd file://* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e '.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>") 43 else 44 au BufReadCmd file:///* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e /'.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>") 45 au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".expand("<amatch>")|exe 'e /'.substitute(expand("<amatch>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<amatch>") 46 endif 47 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<amatch>")|exe "Nread 0r ".expand("<amatch>")|exe "silent doau BufReadPost ".expand("<amatch>") 48 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<amatch>")|exe "Nread " .expand("<amatch>")|exe "silent doau FileReadPost ".expand("<amatch>") 49 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe "Nwrite " .expand("<amatch>")|exe "silent doau BufWritePost ".expand("<amatch>") 50 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe "'[,']Nwrite " .expand("<amatch>")|exe "silent doau FileWritePost ".expand("<amatch>") 51augroup END 52 53" Commands: :Nread, :Nwrite, :NetUserPass {{{2 54com! -nargs=* Nread call netrw#NetSavePosn()<bar>call netrw#NetRead(<f-args>)<bar>call netrw#NetRestorePosn() 55com! -range=% -nargs=* Nwrite call netrw#NetSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetRestorePosn() 56com! -nargs=* NetUserPass call NetUserPass(<f-args>) 57 58" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2 59com! -nargs=? -bar -bang -count=0 Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>) 60com! -nargs=? -bar -bang -count=0 Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>) 61com! -nargs=? -bar -bang -count=0 Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>) 62com! -nargs=? -bar -bang -count=0 Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>) 63com! -nargs=? -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>) 64com! -nargs=? -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>) 65 66" Commands: NetrwSettings {{{2 67com! -nargs=0 NetrwSettings :call netrwSettings#NetrwSettings() 68 69" --------------------------------------------------------------------- 70" LocalBrowse: {{{2 71fun! s:LocalBrowse(dirname) 72 " unfortunate interaction -- debugging calls can't be used here; 73 " the BufEnter event causes triggering when attempts to write to 74 " the DBG buffer are made. 75 if isdirectory(a:dirname) 76 call netrw#DirBrowse(a:dirname) 77 endif 78 " not a directory, ignore it 79endfun 80 81" --------------------------------------------------------------------- 82" NetrwStatusLine: {{{1 83fun! NetrwStatusLine() 84" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr(".")." Xline#".w:netrw_explore_line." line#".line(".") 85 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr(".") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list") 86 let &stl= s:netrw_explore_stl 87 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif 88 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif 89 return "" 90 else 91 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen 92 endif 93endfun 94 95" ------------------------------------------------------------------------ 96" NetUserPass: set username and password for subsequent ftp transfer {{{1 97" Usage: :call NetUserPass() -- will prompt for userid and password 98" :call NetUserPass("uid") -- will prompt for password 99" :call NetUserPass("uid","password") -- sets global userid and password 100fun! NetUserPass(...) 101 102 " get/set userid 103 if a:0 == 0 104" call Dfunc("NetUserPass(a:0<".a:0.">)") 105 if !exists("g:netrw_uid") || g:netrw_uid == "" 106 " via prompt 107 let g:netrw_uid= input('Enter username: ') 108 endif 109 else " from command line 110" call Dfunc("NetUserPass(a:1<".a:1.">) {") 111 let g:netrw_uid= a:1 112 endif 113 114 " get password 115 if a:0 <= 1 " via prompt 116" call Decho("a:0=".a:0." case <=1:") 117 let g:netrw_passwd= inputsecret("Enter Password: ") 118 else " from command line 119" call Decho("a:0=".a:0." case >1: a:2<".a:2.">") 120 let g:netrw_passwd=a:2 121 endif 122" call Dret("NetUserPass") 123endfun 124 125" ------------------------------------------------------------------------ 126" NetReadFixup: this sort of function is typically written by the user {{{1 127" to handle extra junk that their system's ftp dumps 128" into the transfer. This function is provided as an 129" example and as a fix for a Windows 95 problem: in my 130" experience, win95's ftp always dumped four blank lines 131" at the end of the transfer. 132if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp 133 fun! NetReadFixup(method, line1, line2) 134" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") 135 if method == 3 " ftp (no <.netrc>) 136 let fourblanklines= line2 - 3 137 silent fourblanklines.",".line2."g/^\s*/d" 138 endif 139" call Dret("NetReadFixup") 140 endfun 141endif 142 143" ------------------------------------------------------------------------ 144" Modelines And Restoration: {{{1 145let &cpo= s:keepcpo 146unlet s:keepcpo 147" vim:ts=8 fdm=marker 148