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