blob: 718bb663e7e64d17644d0a3a13364ded3c5bcc52 [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 Moolenaare6ae6222013-05-21 21:01:10 +02003" Date: Apr 30, 2013
Bram Moolenaarff034192013-04-24 18:51:19 +02004" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00005" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaarff034192013-04-24 18:51:19 +02006" Copyright: Copyright (C) 1999-2012 Charles E. Campbell {{{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 Moolenaare6ae6222013-05-21 21:01:10 +020023"DechoTabOn
24let g:loaded_netrwPlugin = "v149"
Bram Moolenaar5c736222010-01-06 20:54:52 +010025if v:version < 702
26 echohl WarningMsg | echo "***netrw*** you need vim version 7.2 for this version of netrw" | echohl None
Bram Moolenaar8349fd72005-10-12 20:52:20 +000027 finish
28endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010029let s:keepcpo = &cpo
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000030set cpo&vim
Bram Moolenaare6ae6222013-05-21 21:01:10 +020031"DechoTabOn
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000032
33" ---------------------------------------------------------------------
34" Public Interface: {{{1
35
36" Local Browsing: {{{2
37augroup FileExplorer
38 au!
Bram Moolenaare6ae6222013-05-21 21:01:10 +020039 " SEE Benzinger problem...
Bram Moolenaaradc21822011-04-01 18:03:16 +020040 au BufEnter * sil! call s:LocalBrowse(expand("<amatch>"))
41 au VimEnter * sil! call s:VimEnter(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000042 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaaradc21822011-04-01 18:03:16 +020043 au BufEnter .* sil! call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000044 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000045augroup END
46
47" Network Browsing Reading Writing: {{{2
48augroup Network
49 au!
Bram Moolenaare6ae6222013-05-21 21:01:10 +020050 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>"))
Bram Moolenaarff034192013-04-24 18:51:19 +020051 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(2,expand("<amatch>"))|exe "sil doau BufReadPost ".fnameescape(expand("<amatch>"))
52 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileReadPre ".fnameescape(expand("<amatch>"))|call netrw#Nread(1,expand("<amatch>"))|exe "sil doau FileReadPost ".fnameescape(expand("<amatch>"))
53 au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau BufWritePost ".fnameescape(expand("<amatch>"))
54 au FileWriteCmd ftp://*,rcp://*,scp://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau FileWritePost ".fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000055 try
Bram Moolenaar15146672011-10-20 22:22:38 +020056 au SourceCmd ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000057 catch /^Vim\%((\a\+)\)\=:E216/
Bram Moolenaar15146672011-10-20 22:22:38 +020058 au SourcePre ftp://*,rcp://*,scp://*,http://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000059 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000060augroup END
61
62" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000063com! -count=1 -nargs=* Nread call netrw#NetrwSavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#NetrwRestorePosn()
64com! -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 +000065com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaarf2330482008-06-24 20:19:36 +000066com! -nargs=* Nsource call netrw#NetrwSavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#NetrwRestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000067
68" Commands: :Explore, :Sexplore, Hexplore, Vexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000069com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
70com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
71com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
72com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
73com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
74com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
75com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000076
77" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000078com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
79com! -bang NetrwClean call netrw#NetrwClean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000080
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000081" Maps:
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020082if !exists("g:netrw_nogx") && maparg('gx','n') == ""
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000083 if !hasmapto('<Plug>NetrwBrowseX')
84 nmap <unique> gx <Plug>NetrwBrowseX
85 endif
Bram Moolenaarf2330482008-06-24 20:19:36 +000086 nno <silent> <Plug>NetrwBrowseX :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<cr>
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000087endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000088
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000089" ---------------------------------------------------------------------
90" LocalBrowse: {{{2
91fun! s:LocalBrowse(dirname)
92 " unfortunate interaction -- debugging calls can't be used here;
93 " the BufEnter event causes triggering when attempts to write to
94 " the DBG buffer are made.
Bram Moolenaare6ae6222013-05-21 21:01:10 +020095 if !exists("s:vimentered")
96 return
97 endif
98" call Decho("s:LocalBrowse(dirname<".a:dirname.">){")
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.
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200104" call Decho("(LocalBrowse) dirname<".a:dirname."> (amiga)")
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000105 if a:dirname != '' && isdirectory(a:dirname)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200106 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000107 endif
108 elseif isdirectory(a:dirname)
109" echomsg "dirname<".dirname."> isdir"
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200110" call Decho("(LocalBrowse) dirname<".a:dirname."> (not amiga)")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200111 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000112 endif
113 " not a directory, ignore it
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200114" call Decho("|return s:LocalBrowse }")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000115endfun
116
117" ---------------------------------------------------------------------
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200118" s:VimEnter: {{{2
119fun! s:VimEnter(dirname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200120" call Decho("VimEnter(dirname<".a:dirname.">){")
121 let curwin = winnr()
122 let s:vimentered = 1
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200123 windo if a:dirname != expand("%")|call s:LocalBrowse(expand("%:p"))|endif
Bram Moolenaar477db062010-07-28 18:17:41 +0200124 exe curwin."wincmd w"
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200125" call Decho("|return VimEnter }")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200126endfun
127
128" ---------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000129" NetrwStatusLine: {{{1
130fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000131" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
132 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 +0000133 let &stl= s:netrw_explore_stl
134 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
135 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
136 return ""
137 else
138 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
139 endif
140endfun
141
142" ------------------------------------------------------------------------
143" NetUserPass: set username and password for subsequent ftp transfer {{{1
144" Usage: :call NetUserPass() -- will prompt for userid and password
145" :call NetUserPass("uid") -- will prompt for password
146" :call NetUserPass("uid","password") -- sets global userid and password
147fun! NetUserPass(...)
148
149 " get/set userid
150 if a:0 == 0
151" call Dfunc("NetUserPass(a:0<".a:0.">)")
152 if !exists("g:netrw_uid") || g:netrw_uid == ""
153 " via prompt
154 let g:netrw_uid= input('Enter username: ')
155 endif
156 else " from command line
157" call Dfunc("NetUserPass(a:1<".a:1.">) {")
158 let g:netrw_uid= a:1
159 endif
160
161 " get password
162 if a:0 <= 1 " via prompt
163" call Decho("a:0=".a:0." case <=1:")
164 let g:netrw_passwd= inputsecret("Enter Password: ")
165 else " from command line
166" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
167 let g:netrw_passwd=a:2
168 endif
169" call Dret("NetUserPass")
170endfun
171
172" ------------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000173" Modelines And Restoration: {{{1
174let &cpo= s:keepcpo
175unlet s:keepcpo
176" vim:ts=8 fdm=marker