1" netrwPlugin.vim: Handles file transfer and remote directory listing across a network
2"            PLUGIN SECTION
3" Date:		Feb 10, 2011
4" Maintainer:	Charles E Campbell, Jr <[email protected]>
5" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
6" Copyright:    Copyright (C) 1999-2008 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" Load Once: {{{1
20if &cp || exists("g:loaded_netrwPlugin")
21 finish
22endif
23let g:loaded_netrwPlugin = "v141"
24if v:version < 702
25 echohl WarningMsg | echo "***netrw*** you need vim version 7.2 for this version of netrw" | echohl None
26 finish
27endif
28let s:keepcpo = &cpo
29set cpo&vim
30
31" ---------------------------------------------------------------------
32" Public Interface: {{{1
33
34" Local Browsing: {{{2
35augroup FileExplorer
36 au!
37" au BufReadCmd *[/\\]	sil! call s:LocalBrowse(expand("<amatch>"))
38" au BufEnter *[^/\\]	sil! call s:LocalBrowse(expand("<amatch>"))
39" au VimEnter *[^/\\]	sil! call s:VimEnter(expand("<amatch>"))
40 au BufEnter *	sil! call s:LocalBrowse(expand("<amatch>"))
41 au VimEnter *	sil! call s:VimEnter(expand("<amatch>"))
42 if has("win32") || has("win95") || has("win64") || has("win16")
43  au BufEnter .* sil! call s:LocalBrowse(expand("<amatch>"))
44 endif
45augroup END
46
47" Network Browsing Reading Writing: {{{2
48augroup Network
49 au!
50 if has("win32") || has("win95") || has("win64") || has("win16")
51  au BufReadCmd  file://*		call netrw#FileUrlRead(expand("<amatch>"))
52 else
53  au BufReadCmd  file://*		call netrw#FileUrlRead(expand("<amatch>"))
54  au BufReadCmd  file://localhost/*	call netrw#FileUrlRead(substitute(expand("<amatch>")),'file://localhost/','file:///','')
55 endif
56 au BufReadCmd   ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://*	exe "silent doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(expand("<amatch>"))
57 au FileReadCmd  ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://*	exe "silent doau FileReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(1,expand("<amatch>"))|exe "silent doau FileReadPost ".fnameescape(expand("<amatch>"))
58 au BufWriteCmd  ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://*		exe "silent doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "silent doau BufWritePost ".fnameescape(expand("<amatch>"))
59 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://*		exe "silent doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "silent doau FileWritePost ".fnameescape(expand("<amatch>"))
60 try
61  au SourceCmd   ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://*	exe 'Nsource '.fnameescape(expand("<amatch>"))
62 catch /^Vim\%((\a\+)\)\=:E216/
63  au SourcePre   ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://*	exe 'Nsource '.fnameescape(expand("<amatch>"))
64 endtry
65augroup END
66
67" Commands: :Nread, :Nwrite, :NetUserPass {{{2
68com! -count=1 -nargs=*	Nread		call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn()
69com! -range=% -nargs=*	Nwrite		call netrw#NetrwSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetrwRestorePosn()
70com! -nargs=*		NetUserPass	call NetUserPass(<f-args>)
71com! -nargs=*	        Nsource		call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn()
72
73" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
74com! -nargs=* -bar -bang -count=0 -complete=dir	Explore		call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
75com! -nargs=* -bar -bang -count=0 -complete=dir	Sexplore	call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
76com! -nargs=* -bar -bang -count=0 -complete=dir	Hexplore	call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
77com! -nargs=* -bar -bang -count=0 -complete=dir	Vexplore	call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
78com! -nargs=* -bar       -count=0 -complete=dir	Texplore	call netrw#Explore(<count>,0,6        ,<q-args>)
79com! -nargs=* -bar -bang			Nexplore	call netrw#Explore(-1,0,0,<q-args>)
80com! -nargs=* -bar -bang			Pexplore	call netrw#Explore(-2,0,0,<q-args>)
81
82" Commands: NetrwSettings {{{2
83com! -nargs=0	NetrwSettings	call netrwSettings#NetrwSettings()
84com! -bang	NetrwClean	call netrw#NetrwClean(<bang>0)
85
86" Maps:
87if !exists("g:netrw_nogx") && maparg('gx','n') == ""
88 if !hasmapto('<Plug>NetrwBrowseX')
89  nmap <unique> gx <Plug>NetrwBrowseX
90 endif
91 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<cr>
92endif
93
94" ---------------------------------------------------------------------
95" LocalBrowse: {{{2
96fun! s:LocalBrowse(dirname)
97  " unfortunate interaction -- debugging calls can't be used here;
98  " the BufEnter event causes triggering when attempts to write to
99  " the DBG buffer are made.
100"  echomsg "dirname<".a:dirname.">"
101  if has("amiga")
102   " The check against '' is made for the Amiga, where the empty
103   " string is the current directory and not checking would break
104   " things such as the help command.
105   if a:dirname != '' && isdirectory(a:dirname)
106    sil! call netrw#LocalBrowseCheck(a:dirname)
107   endif
108  elseif isdirectory(a:dirname)
109"   echomsg "dirname<".dirname."> isdir"
110   sil! call netrw#LocalBrowseCheck(a:dirname)
111  endif
112  " not a directory, ignore it
113endfun
114
115" ---------------------------------------------------------------------
116" s:VimEnter: {{{2
117fun! s:VimEnter(dirname)
118  let curwin= winnr()
119  windo if a:dirname != expand("%")|call s:LocalBrowse(expand("%:p"))|endif
120  exe curwin."wincmd w"
121endfun
122
123" ---------------------------------------------------------------------
124" NetrwStatusLine: {{{1
125fun! NetrwStatusLine()
126"  let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
127  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")
128   let &stl= s:netrw_explore_stl
129   if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
130   if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
131   return ""
132  else
133   return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
134  endif
135endfun
136
137" ------------------------------------------------------------------------
138" NetUserPass: set username and password for subsequent ftp transfer {{{1
139"   Usage:  :call NetUserPass()			-- will prompt for userid and password
140"	    :call NetUserPass("uid")		-- will prompt for password
141"	    :call NetUserPass("uid","password") -- sets global userid and password
142fun! NetUserPass(...)
143
144 " get/set userid
145 if a:0 == 0
146"  call Dfunc("NetUserPass(a:0<".a:0.">)")
147  if !exists("g:netrw_uid") || g:netrw_uid == ""
148   " via prompt
149   let g:netrw_uid= input('Enter username: ')
150  endif
151 else	" from command line
152"  call Dfunc("NetUserPass(a:1<".a:1.">) {")
153  let g:netrw_uid= a:1
154 endif
155
156 " get password
157 if a:0 <= 1 " via prompt
158"  call Decho("a:0=".a:0." case <=1:")
159  let g:netrw_passwd= inputsecret("Enter Password: ")
160 else " from command line
161"  call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
162  let g:netrw_passwd=a:2
163 endif
164"  call Dret("NetUserPass")
165endfun
166
167" ------------------------------------------------------------------------
168" Modelines And Restoration: {{{1
169let &cpo= s:keepcpo
170unlet s:keepcpo
171" vim:ts=8 fdm=marker
172