blob: b0a29ad786c815cd07f4c9a460802daaa5080bd2 [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 Moolenaarf2330482008-06-24 20:19:36 +00003" Date: Apr 07, 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
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
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000022if &cp || exists("g:loaded_netrwPlugin")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000023 finish
24endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000025let g:loaded_netrwPlugin = "v125"
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000026let s:keepcpo = &cpo
Bram Moolenaar8349fd72005-10-12 20:52:20 +000027if v:version < 700
28 echohl WarningMsg | echo "***netrw*** you need vim version 7.0 for this version of netrw" | echohl None
29 finish
30endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000031let s:keepcpo= &cpo
32set cpo&vim
33
34" ---------------------------------------------------------------------
35" Public Interface: {{{1
36
37" Local Browsing: {{{2
38augroup FileExplorer
39 au!
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000040 au BufEnter * silent! call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000041 if has("win32") || has("win95") || has("win64") || has("win16")
42 au BufEnter .* silent! call s:LocalBrowse(expand("<amatch>"))
43 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000044augroup END
45
46" Network Browsing Reading Writing: {{{2
47augroup Network
48 au!
49 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarf2330482008-06-24 20:19:36 +000050 au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',"")|exe "bwipe ".expand("<amatch>")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>"))
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000051 else
Bram Moolenaarf2330482008-06-24 20:19:36 +000052 au BufReadCmd file://* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://\(.*\)','\1',"")|exe "bwipe ".expand("<amatch>")|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>"))
53 au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".netrw#RFC2396(expand("<amatch>"))|exe 'e '.substitute(netrw#RFC2396(expand("<amatch>")),'file://localhost/\(.*\)','\1',"")|exe "bwipe ".substitute(expand("<amatch>"),'file://\(\k\+@\)\=','','')|exe "silent doau BufReadPost ".netrw#RFC2396(expand("<amatch>"))
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000054 endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000055 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<amatch>")|exe '2Nread "'.expand("<amatch>").'"'|exe "silent doau BufReadPost ".expand("<amatch>")
56 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau FileReadPre ".expand("<amatch>")|exe 'Nread "' .expand("<amatch>").'"'|exe "silent doau FileReadPost ".expand("<amatch>")
57 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau BufWritePre ".expand("<amatch>")|exe 'Nwrite "' .expand("<amatch>").'"'|exe "silent doau BufWritePost ".expand("<amatch>")
58 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "silent doau FileWritePre ".expand("<amatch>")|exe "'[,']".'Nwrite "' .expand("<amatch>").'"'|exe "silent doau FileWritePost ".expand("<amatch>")
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000059 try
Bram Moolenaarf2330482008-06-24 20:19:36 +000060 au SourceCmd ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource "'.expand("<amatch>").'"'
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000061 catch /^Vim\%((\a\+)\)\=:E216/
Bram Moolenaarf2330482008-06-24 20:19:36 +000062 au SourcePre ftp://*,rcp://*,scp://*,http://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource "'.expand("<amatch>").'"'
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000063 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000064augroup END
65
66" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000067com! -count=1 -nargs=* Nread call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn()
68com! -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 +000069com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaarf2330482008-06-24 20:19:36 +000070com! -nargs=* Nsource call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000071
72" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000073com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
74com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
75com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
76com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
77com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
78com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
79com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000080
81" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000082com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
83com! -bang NetrwClean call netrw#NetrwClean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000084
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000085" Maps:
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000086if !exists("g:netrw_nogx") && maparg('g','n') == ""
87 if !hasmapto('<Plug>NetrwBrowseX')
88 nmap <unique> gx <Plug>NetrwBrowseX
89 endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000090 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<cr>
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000091endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000092
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000093" ---------------------------------------------------------------------
94" LocalBrowse: {{{2
95fun! s:LocalBrowse(dirname)
96 " unfortunate interaction -- debugging calls can't be used here;
97 " the BufEnter event causes triggering when attempts to write to
98 " the DBG buffer are made.
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000099" echomsg "dirname<".a:dirname.">"
100 if has("amiga")
101 " The check against '' is made for the Amiga, where the empty
102 " string is the current directory and not checking would break
103 " things such as the help command.
104 if a:dirname != '' && isdirectory(a:dirname)
105 silent! call netrw#LocalBrowseCheck(a:dirname)
106 endif
107 elseif isdirectory(a:dirname)
108" echomsg "dirname<".dirname."> isdir"
109 silent! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000110 endif
111 " not a directory, ignore it
112endfun
113
114" ---------------------------------------------------------------------
115" NetrwStatusLine: {{{1
116fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000117" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
118 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 +0000119 let &stl= s:netrw_explore_stl
120 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
121 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
122 return ""
123 else
124 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
125 endif
126endfun
127
128" ------------------------------------------------------------------------
129" NetUserPass: set username and password for subsequent ftp transfer {{{1
130" Usage: :call NetUserPass() -- will prompt for userid and password
131" :call NetUserPass("uid") -- will prompt for password
132" :call NetUserPass("uid","password") -- sets global userid and password
133fun! NetUserPass(...)
134
135 " get/set userid
136 if a:0 == 0
137" call Dfunc("NetUserPass(a:0<".a:0.">)")
138 if !exists("g:netrw_uid") || g:netrw_uid == ""
139 " via prompt
140 let g:netrw_uid= input('Enter username: ')
141 endif
142 else " from command line
143" call Dfunc("NetUserPass(a:1<".a:1.">) {")
144 let g:netrw_uid= a:1
145 endif
146
147 " get password
148 if a:0 <= 1 " via prompt
149" call Decho("a:0=".a:0." case <=1:")
150 let g:netrw_passwd= inputsecret("Enter Password: ")
151 else " from command line
152" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
153 let g:netrw_passwd=a:2
154 endif
155" call Dret("NetUserPass")
156endfun
157
158" ------------------------------------------------------------------------
159" NetReadFixup: this sort of function is typically written by the user {{{1
160" to handle extra junk that their system's ftp dumps
161" into the transfer. This function is provided as an
162" example and as a fix for a Windows 95 problem: in my
163" experience, win95's ftp always dumped four blank lines
164" at the end of the transfer.
165if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
166 fun! NetReadFixup(method, line1, line2)
167" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
168 if method == 3 " ftp (no <.netrc>)
169 let fourblanklines= line2 - 3
170 silent fourblanklines.",".line2."g/^\s*/d"
171 endif
172" call Dret("NetReadFixup")
173 endfun
174endif
175
176" ------------------------------------------------------------------------
177" Modelines And Restoration: {{{1
178let &cpo= s:keepcpo
179unlet s:keepcpo
180" vim:ts=8 fdm=marker