blob: cad4d31a04ad7eb3544713196a5277aed6cd08bc [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 Moolenaar8feef4f2015-01-07 16:57:10 +01003" Date: Nov 07, 2014
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 Moolenaar8d043172014-01-23 14:24:41 +01006" Copyright: Copyright (C) 1999-2013 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 Moolenaar8feef4f2015-01-07 16:57:10 +010023let g:loaded_netrwPlugin = "v153"
Bram Moolenaar5c736222010-01-06 20:54:52 +010024if v:version < 702
Bram Moolenaar8d043172014-01-23 14:24:41 +010025 echohl WarningMsg
26 echo "***warning*** you need vim version 7.2 for this version of netrw"
27 echohl None
28 finish
29endif
30if v:version < 703 || (v:version == 703 && !has("patch465"))
31 echohl WarningMsg
32 echo "***warning*** this version of netrw needs vim 7.3.465 or later"
33 echohl Normal
Bram Moolenaar8349fd72005-10-12 20:52:20 +000034 finish
35endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010036let s:keepcpo = &cpo
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000037set cpo&vim
Bram Moolenaar8d043172014-01-23 14:24:41 +010038"DechoRemOn
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000039
40" ---------------------------------------------------------------------
41" Public Interface: {{{1
42
Bram Moolenaar8d043172014-01-23 14:24:41 +010043" Local Browsing Autocmds: {{{2
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000044augroup FileExplorer
45 au!
Bram Moolenaara6878372014-03-22 21:02:50 +010046 au BufLeave * if &ft != "netrw"|let w:netrw_prvfile= expand("%:p")|endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010047 au BufEnter * sil call s:LocalBrowse(expand("<amatch>"))
48 au VimEnter * sil call s:VimEnter(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000049 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8d043172014-01-23 14:24:41 +010050 au BufEnter .* sil call s:LocalBrowse(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000051 endif
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000052augroup END
53
54" Network Browsing Reading Writing: {{{2
55augroup Network
56 au!
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010057 au BufReadCmd file://* call netrw#FileUrlRead(expand("<amatch>"))
58 au BufReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,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>"))
59 au FileReadCmd ftp://*,rcp://*,scp://*,http://*,file://*,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>"))
60 au BufWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau BufWritePre ".fnameescape(expand("<amatch>"))|exe 'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau BufWritePost ".fnameescape(expand("<amatch>"))
61 au FileWriteCmd ftp://*,rcp://*,scp://*,http://*,file://*,dav://*,davs://*,rsync://*,sftp://* exe "sil doau FileWritePre ".fnameescape(expand("<amatch>"))|exe "'[,']".'Nwrite '.fnameescape(expand("<amatch>"))|exe "sil doau FileWritePost ".fnameescape(expand("<amatch>"))
62 try
63 au SourceCmd ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
64 catch /^Vim\%((\a\+)\)\=:E216/
65 au SourcePre ftp://*,rcp://*,scp://*,http://*,file://*,https://*,dav://*,davs://*,rsync://*,sftp://* exe 'Nsource '.fnameescape(expand("<amatch>"))
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000066 endtry
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000067augroup END
68
69" Commands: :Nread, :Nwrite, :NetUserPass {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +010070com! -count=1 -nargs=* Nread call netrw#SavePosn()<bar>call netrw#NetRead(<count>,<f-args>)<bar>call netrw#RestorePosn()
71com! -range=% -nargs=* Nwrite call netrw#SavePosn()<bar><line1>,<line2>call netrw#NetWrite(<f-args>)<bar>call netrw#RestorePosn()
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000072com! -nargs=* NetUserPass call NetUserPass(<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +010073com! -nargs=* Nsource call netrw#SavePosn()<bar>call netrw#NetSource(<f-args>)<bar>call netrw#RestorePosn()
74com! -nargs=? Ntree call netrw#SetTreetop(<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000075
Bram Moolenaar8d043172014-01-23 14:24:41 +010076" Commands: :Explore, :Sexplore, Hexplore, Vexplore, Lexplore {{{2
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000077com! -nargs=* -bar -bang -count=0 -complete=dir Explore call netrw#Explore(<count>,0,0+<bang>0,<q-args>)
78com! -nargs=* -bar -bang -count=0 -complete=dir Sexplore call netrw#Explore(<count>,1,0+<bang>0,<q-args>)
79com! -nargs=* -bar -bang -count=0 -complete=dir Hexplore call netrw#Explore(<count>,1,2+<bang>0,<q-args>)
80com! -nargs=* -bar -bang -count=0 -complete=dir Vexplore call netrw#Explore(<count>,1,4+<bang>0,<q-args>)
81com! -nargs=* -bar -count=0 -complete=dir Texplore call netrw#Explore(<count>,0,6 ,<q-args>)
82com! -nargs=* -bar -bang Nexplore call netrw#Explore(-1,0,0,<q-args>)
83com! -nargs=* -bar -bang Pexplore call netrw#Explore(-2,0,0,<q-args>)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010084com! -nargs=* -bar -bang -count=0 -complete=dir Lexplore call netrw#Lexplore(<count>,<bang>0,<q-args>)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000085
86" Commands: NetrwSettings {{{2
Bram Moolenaarf2330482008-06-24 20:19:36 +000087com! -nargs=0 NetrwSettings call netrwSettings#NetrwSettings()
Bram Moolenaara6878372014-03-22 21:02:50 +010088com! -bang NetrwClean call netrw#Clean(<bang>0)
Bram Moolenaar482aaeb2005-09-29 18:26:07 +000089
Bram Moolenaarb8a7b562006-02-01 21:47:16 +000090" Maps:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010091if !exists("g:netrw_nogx")
92 if maparg('gx','n') == ""
93 if !hasmapto('<Plug>NetrwBrowseX')
94 nmap <unique> gx <Plug>NetrwBrowseX
95 endif
96 nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())<cr>
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +000097 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010098 if maparg('gx','v') == ""
99 if !hasmapto('<Plug>NetrwBrowseXVis')
100 vmap <unique> gx <Plug>NetrwBrowseXVis
101 endif
102 vno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr>
103 endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +0000104endif
Bram Moolenaarb8a7b562006-02-01 21:47:16 +0000105
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000106" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +0100107" LocalBrowse: invokes netrw#LocalBrowseCheck() on directory buffers {{{2
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000108fun! s:LocalBrowse(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100109 " Unfortunate interaction -- only DechoMsg debugging calls can be safely used here.
110 " Otherwise, the BufEnter event gets triggered when attempts to write to
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000111 " the DBG buffer are made.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100112
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200113 if !exists("s:vimentered")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100114 " If s:vimentered doesn't exist, then the VimEnter event hasn't fired. It will,
115 " and so s:VimEnter() will then be calling this routine, but this time with s:vimentered defined.
116" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered doesn't exist)")
117" call Dret("s:LocalBrowse")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200118 return
119 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100120
121" call Dfunc("s:LocalBrowse(dirname<".a:dirname.">) (s:vimentered=".s:vimentered.")")
122
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000123 if has("amiga")
124 " The check against '' is made for the Amiga, where the empty
125 " string is the current directory and not checking would break
126 " things such as the help command.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100127" call Decho("(LocalBrowse) dirname<".a:dirname."> (isdirectory, amiga)")
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000128 if a:dirname != '' && isdirectory(a:dirname)
Bram Moolenaaradc21822011-04-01 18:03:16 +0200129 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100130 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +0100131 exe w:netrw_bannercnt
132 endif
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000133 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100134
Bram Moolenaardd2a3cd2007-05-05 17:10:09 +0000135 elseif isdirectory(a:dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +0100136" call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)")
137" call Dredir("LocalBrowse ft last set: ","verbose set ft")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200138 sil! call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100139 if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +0100140 exe w:netrw_bannercnt
141 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100142
143 else
144 " not a directory, ignore it
145" call Decho("(LocalBrowse) dirname<".a:dirname."> not a directory, ignoring...")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000146 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100147
148" call Dret("s:LocalBrowse")
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000149endfun
150
151" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +0100152" s:VimEnter: after all vim startup stuff is done, this function is called. {{{2
153" Its purpose: to look over all windows and run s:LocalBrowse() on
154" them, which checks if they're directories and will create a directory
155" listing when appropriate.
156" It also sets s:vimentered, letting s:LocalBrowse() know that s:VimEnter()
157" has already been called.
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200158fun! s:VimEnter(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100159" call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200160 let curwin = winnr()
161 let s:vimentered = 1
Bram Moolenaar8d043172014-01-23 14:24:41 +0100162 windo call s:LocalBrowse(expand("%:p"))
Bram Moolenaar477db062010-07-28 18:17:41 +0200163 exe curwin."wincmd w"
Bram Moolenaar8d043172014-01-23 14:24:41 +0100164" call Dret("s:VimEnter")
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200165endfun
166
167" ---------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000168" NetrwStatusLine: {{{1
169fun! NetrwStatusLine()
Bram Moolenaaraf48b092006-03-14 22:51:38 +0000170" let g:stlmsg= "Xbufnr=".w:netrw_explore_bufnr." bufnr=".bufnr("%")." Xline#".w:netrw_explore_line." line#".line(".")
171 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 +0000172 let &stl= s:netrw_explore_stl
173 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
174 if exists("w:netrw_explore_line")|unlet w:netrw_explore_line|endif
175 return ""
176 else
177 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
178 endif
179endfun
180
181" ------------------------------------------------------------------------
182" NetUserPass: set username and password for subsequent ftp transfer {{{1
183" Usage: :call NetUserPass() -- will prompt for userid and password
184" :call NetUserPass("uid") -- will prompt for password
185" :call NetUserPass("uid","password") -- sets global userid and password
186fun! NetUserPass(...)
187
188 " get/set userid
189 if a:0 == 0
190" call Dfunc("NetUserPass(a:0<".a:0.">)")
191 if !exists("g:netrw_uid") || g:netrw_uid == ""
192 " via prompt
193 let g:netrw_uid= input('Enter username: ')
194 endif
195 else " from command line
196" call Dfunc("NetUserPass(a:1<".a:1.">) {")
197 let g:netrw_uid= a:1
198 endif
199
200 " get password
201 if a:0 <= 1 " via prompt
202" call Decho("a:0=".a:0." case <=1:")
203 let g:netrw_passwd= inputsecret("Enter Password: ")
204 else " from command line
205" call Decho("a:0=".a:0." case >1: a:2<".a:2.">")
206 let g:netrw_passwd=a:2
207 endif
208" call Dret("NetUserPass")
209endfun
210
211" ------------------------------------------------------------------------
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000212" Modelines And Restoration: {{{1
213let &cpo= s:keepcpo
214unlet s:keepcpo
215" vim:ts=8 fdm=marker