blob: 13798b03f28242365ad238eeb89ce0c359b176ce [file] [log] [blame]
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00001" netrwPlugin.vim: Handles file transfer and remote directory listing across a network
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +00002" PLUGIN SECTION
Bram Moolenaar5c736222010-01-06 20:54:52 +01003" Date: Aug 10, 2008
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +00004" Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00005" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006" Copyright: Copyright (C) 1999-2008 Charles E. Campbell, Jr. {{{1
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00007" 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" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000019" Load Once: {{{1
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000020if &cp || exists("g:loaded_netrwPlugin")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000021 finish
22endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010023let g:loaded_netrwPlugin = "v136"
24if v:version < 702
25 echohl WarningMsg | echo "***netrw*** you need vim version 7.2 for this version of netrw" | echohl None
Bram Moolenaar8349fd72005-10-12 20:52:20 +000026 finish
27endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010028let s:keepcpo = &cpo
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000029set cpo&vim
30
31" ---------------------------------------------------------------------
32" Public Interface: {{{1
33
34" Local Browsing: {{{2
35augroup FileExplorer
36 au!
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000037 au BufEnter * silent! call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000038 if has("win32") || has("win95") || has("win64") || has("win16")
39 au BufEnter .* silent! call s:LocalBrowse(expand("<amatch>"))
40 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000041augroup END
42
43" Network Browsing Reading Writing: {{{2
44augroup Network
45 au!
46 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaare37d50a2008-08-06 17:06:04 +000047 au BufReadCmd file://* exe "silent doau BufReadPre ".fnameescape(netrw#RFC2396(expand("<amatch>")))|exe 'e '.fnameescape(substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',""))|exe "bwipe ".fnameescape(expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(netrw#RFC2396(expand("<amatch>")))
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000048 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +000049 au BufReadCmd file://* exe "silent doau BufReadPre ".fnameescape(netrw#RFC2396(expand("<amatch>")))|exe 'e '.fnameescape(substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',""))|exe "bwipe ".fnameescape(expand("<amatch>"))|exe "silent doau BufReadPost ".fnameescape(netrw#RFC2396(expand("<amatch>")))
50 au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".fnameescape(netrw#RFC2396(expand("<amatch>")))|exe 'e '.fnameescape(substitute(netrw#RFC2396(expand("<amatch>")),'file://localhost/\(.*\)','\1',""))|exe "bwipe ".fnameescape(substitute(expand("<amatch>"),'file://\(\k\+@\)\=','',''))|exe "silent doau BufReadPost ".fnameescape(netrw#RFC2396(expand("<amatch>")))
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000051 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010052 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>"))
53 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>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +000054 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>"))
55 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>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000056 try
Bram Moolenaare37d50a2008-08-06 17:06:04 +000057 au SourceCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000058 catch /^Vim\%((\a\+)\)\=:E216/
Bram Moolenaare37d50a2008-08-06 17:06:04 +000059 au SourcePre ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000060 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000061augroup END
62
63" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000064com! -count=1 -nargs=* Nread call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn()
65com! -range=% -nargs=* Nwrite call netrw#NetrwSavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000066com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaarf2330482008-06-24 20:19:36 +000067com! -nargs=* Nsource call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000068
69" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000070com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
71com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
72com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
73com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
74com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
75com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
76com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000077
78" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000079com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
80com! -bang NetrwClean call netrw#NetrwClean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000081
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000082" Maps:
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000083if !exists("g:netrw_nogx") && maparg('g','n') == ""
84 if !hasmapto('<Plug>NetrwBrowseX')
85 nmap <unique> gx <Plug>NetrwBrowseX
86 endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000087 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<cr>
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000088endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000089
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000090" ---------------------------------------------------------------------
91" LocalBrowse: {{{2
92fun! s:LocalBrowse(dirname)
93 " unfortunate interaction -- debugging calls can't be used here;
94 " the BufEnter event causes triggering when attempts to write to
95 " the DBG buffer are made.
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000096" echomsg "dirname<".a:dirname.">"
97 if has("amiga")
98 " The check against '' is made for the Amiga, where the empty
99 " string is the current directory and not checking would break
100 " things such as the help command.
101 if a:dirname != '' && isdirectory(a:dirname)
102 silent! call netrw#LocalBrowseCheck(a:dirname)
103 endif
104 elseif isdirectory(a:dirname)
105" echomsg "dirname<".dirname."> isdir"
106 silent! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000107 endif
108 " not a directory, ignore it
109endfun
110
111" ---------------------------------------------------------------------
112" NetrwStatusLine: {{{1
113fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000114" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
115 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")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000116 let &stl= s:netrw_explore_stl
117 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
118 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
119 return ""
120 else
121 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
122 endif
123endfun
124
125" ------------------------------------------------------------------------
126" NetUserPass: set username and password for subsequent ftp transfer {{{1
127" Usage: :call NetUserPass() -- will prompt for userid and password
128" :call NetUserPass("uid") -- will prompt for password
129" :call NetUserPass("uid","password") -- sets global userid and password
130fun! NetUserPass(...)
131
132 " get/set userid
133 if a:0 == 0
134" call Dfunc("NetUserPass(a:0<".a:0.">)")
135 if !exists("g:netrw_uid") || g:netrw_uid == ""
136 " via prompt
137 let g:netrw_uid= input('Enter username: ')
138 endif
139 else " from command line
140" call Dfunc("NetUserPass(a:1<".a:1.">) {")
141 let g:netrw_uid= a:1
142 endif
143
144 " get password
145 if a:0 <= 1 " via prompt
146" call Decho("a:0=".a:0." case <=1:")
147 let g:netrw_passwd= inputsecret("Enter Password: ")
148 else " from command line
149" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
150 let g:netrw_passwd=a:2
151 endif
152" call Dret("NetUserPass")
153endfun
154
155" ------------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000156" Modelines And Restoration: {{{1
157let &cpo= s:keepcpo
158unlet s:keepcpo
159" vim:ts=8 fdm=marker